From b79df7333f8d89a3f80473c116e0c3ad2babd133 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sun, 21 Jan 2024 20:33:57 +0100 Subject: [PATCH] add generate user automaticaly from excel --- idhub/admin/forms.py | 11 +++++------ idhub/admin/views.py | 9 ++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index b1300fc..268ce95 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -66,6 +66,7 @@ class ImportForm(forms.Form): self._eidas1 = None self.rows = {} self.properties = {} + self.users = [] self.user = kwargs.pop('user', None) super().__init__(*args, **kwargs) dids = DID.objects.filter(user=self.user) @@ -178,13 +179,11 @@ class ImportForm(forms.Form): msg = "line {}: {}".format(line+1, e) self.exception(msg) - user = User.objects.filter(email=row.get('email')) - if not user: - txt = _('The user does not exist!') - msg = "line {}: {}".format(line+1, txt) - self.exception(msg) + user, new = User.objects.get_or_create(email=row.get('email')) + if new: + self.users.append(user) - return user.first() + return user def create_credential(self, user, row): return VerificableCredential( diff --git a/idhub/admin/views.py b/idhub/admin/views.py index 51abf91..37d6076 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -936,7 +936,7 @@ class ImportStep2View(ImportExport, TemplateView): return context -class ImportAddView(ImportExport, FormView): +class ImportAddView(NotifyActivateUserByEmail, ImportExport, FormView): template_name = "idhub/admin/import_add.html" subtitle = _('Import') icon = '' @@ -957,5 +957,12 @@ class ImportAddView(ImportExport, FormView): Event.set_EV_CREDENTIAL_CAN_BE_REQUESTED(cred) else: messages.error(self.request, _("Error importing the file!")) + + for user in form.users: + try: + self.send_email(user) + except SMTPException as e: + messages.error(self.request, e) + return super().form_valid(form)