add generate user automaticaly from excel

This commit is contained in:
Cayo Puigdefabregas 2024-01-21 20:33:57 +01:00
parent acbe778197
commit b79df7333f
2 changed files with 13 additions and 7 deletions

View File

@ -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(

View File

@ -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)