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._eidas1 = None
self.rows = {} self.rows = {}
self.properties = {} self.properties = {}
self.users = []
self.user = kwargs.pop('user', None) self.user = kwargs.pop('user', None)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
dids = DID.objects.filter(user=self.user) dids = DID.objects.filter(user=self.user)
@ -178,13 +179,11 @@ class ImportForm(forms.Form):
msg = "line {}: {}".format(line+1, e) msg = "line {}: {}".format(line+1, e)
self.exception(msg) self.exception(msg)
user = User.objects.filter(email=row.get('email')) user, new = User.objects.get_or_create(email=row.get('email'))
if not user: if new:
txt = _('The user does not exist!') self.users.append(user)
msg = "line {}: {}".format(line+1, txt)
self.exception(msg)
return user.first() return user
def create_credential(self, user, row): def create_credential(self, user, row):
return VerificableCredential( return VerificableCredential(

View File

@ -936,7 +936,7 @@ class ImportStep2View(ImportExport, TemplateView):
return context return context
class ImportAddView(ImportExport, FormView): class ImportAddView(NotifyActivateUserByEmail, ImportExport, FormView):
template_name = "idhub/admin/import_add.html" template_name = "idhub/admin/import_add.html"
subtitle = _('Import') subtitle = _('Import')
icon = '' icon = ''
@ -957,5 +957,12 @@ class ImportAddView(ImportExport, FormView):
Event.set_EV_CREDENTIAL_CAN_BE_REQUESTED(cred) Event.set_EV_CREDENTIAL_CAN_BE_REQUESTED(cred)
else: else:
messages.error(self.request, _("Error importing the file!")) 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) return super().form_valid(form)