Révision d9dfbd19
Ajouté par Serghei Mihai (congés, retour 15/05) il y a environ 9 ans
uauth/organization/views.py | ||
---|---|---|
3 | 3 |
|
4 | 4 |
from django.views.generic.base import TemplateView |
5 | 5 |
from django.views.generic.list import ListView |
6 |
from django.views.generic.edit import FormView |
|
7 |
from django.contrib import messages |
|
6 | 8 |
|
7 | 9 |
from django_tables2 import RequestConfig |
8 | 10 |
|
11 |
from .utils import create_user |
|
9 | 12 |
from .models import LocalAccount, Organization |
13 |
from .forms import LocalAccountCreateForm |
|
10 | 14 |
from .tables import AccountTable |
11 | 15 |
|
12 | 16 |
|
... | ... | |
41 | 45 |
return context |
42 | 46 |
|
43 | 47 |
users = UsersPageView.as_view() |
48 |
|
|
49 |
|
|
50 |
class UsersCreateView(OrganizationMixin, FormView): |
|
51 |
template_name = 'organization/create-users.html' |
|
52 |
form_class = LocalAccountCreateForm |
|
53 |
|
|
54 |
def form_valid(self, form): |
|
55 |
data = form.cleaned_data |
|
56 |
data['organization'] = Organization.objects.get(slug=self.kwargs['organization_slug']) |
|
57 |
accounts_number = data.pop('accounts_number') |
|
58 |
accounts_number_start = data.pop('accounts_number_start') |
|
59 |
if accounts_number_start < 1: |
|
60 |
accounts_number_start = 0 |
|
61 |
|
|
62 |
username = data['username'] |
|
63 |
if accounts_number > 1: |
|
64 |
for index in xrange(accounts_number_start, accounts_number + accounts_number_start): |
|
65 |
data['username'] = '%s-%s' % (username, index) |
|
66 |
if not create_user(data): |
|
67 |
messages.error(self, request, _('Error while creating user %s' % data['username'])) |
|
68 |
break |
|
69 |
messages.info(self.request, _('%s users added successfully' % accounts_number)) |
|
70 |
else: |
|
71 |
if create_user(data): |
|
72 |
messages.info(self.request, _('User "%s" successfully created' % data['username'])) |
|
73 |
else: |
|
74 |
messages.error(self.request, _('Error occured while creating user "%s"' % data['username'])) |
|
75 |
return super(UsersCreateView, self).form_valid(form) |
|
76 |
|
|
77 |
create_users = UsersCreateView.as_view() |
Formats disponibles : Unified diff
users creation form(#7065)