Skip to content

Commit

Permalink
HA-148 - Improved create_preregister_users command to choose no inter…
Browse files Browse the repository at this point in the history
…coop, only intercoop or all users

HA-166 - Improved admin email sending to do it only if there is an admin email already set up
  • Loading branch information
jbc25 committed May 31, 2024
1 parent 708aa58 commit 1657ad9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
19 changes: 10 additions & 9 deletions authentication/models/preregister.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ def send_email(self):
self.email_sent = True
self.save()

# Admin confirmation email
send_template_email(
title=_('Nueva usuaria creada en la app'),
destination=self.account.node.admin_email,
template_name='admin_preregister_confirm_msg',
template_params={
'user': self.user,
'account': self.account }
)
if self.account.node.admin_email:
send_template_email(
title=_('Nueva usuaria creada en la app'),
destination=self.account.node.admin_email,
template_name='admin_preregister_confirm_msg',
template_params={
'user': self.user,
'account': self.account }
)

except Exception as e:
print(e)

Expand Down
24 changes: 15 additions & 9 deletions market/management/commands/create_preregister_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
from market.models import Account, Consumer


def create_preregister(account):
PreRegisteredUser.create_user_and_preregister(account)
time.sleep(2) # to void possible errors due to very quick email sending


class Command(BaseCommand):
help = 'Create preregister user for all accounts of node'

def add_arguments(self, parser):
parser.add_argument('--node', type=int, help='Node Id')
parser.add_argument('--intercoop', action=argparse.BooleanOptionalAction)
parser.set_defaults(intercoop=True)

def handle(self, *args, **options):

node_id = options['node']
include_intercoop = options['intercoop']
intercoop = options['intercoop']

node = Node.objects.get(pk=node_id)

Expand All @@ -42,13 +46,15 @@ def handle(self, *args, **options):
existing_emails.append(account.email)
continue

if not include_intercoop and isinstance(account, Consumer) and account.is_intercoop:
print(f"Skiping intercoop: {account.email}")
continue

print(f"Creating user and preregister: {account.email}")
PreRegisteredUser.create_user_and_preregister(account)
time.sleep(2) # to void possible errors due to very quick email sending
if intercoop is None:
print(f"Creating user and preregister: {account.email}")
create_preregister(account)
elif intercoop is True and account.is_intercoop:
print(f"Creating Intercoop user and preregister: {account.email}")
create_preregister(account)
elif intercoop is False and not account.is_intercoop:
print(f"Creating not Intercoop user and preregister: {account.email}")
create_preregister(account)

print("\nExisting emails:")
print("\n".join(existing_emails))

0 comments on commit 1657ad9

Please sign in to comment.