users creation form(#7065)
|
@ -2,5 +2,5 @@ include MANIFEST.in
|
|||
include README
|
||||
include COPYING
|
||||
recursive-include uauth/templates *.html
|
||||
recursive-include uauth/static *.css *.js
|
||||
recursive-include uauth/static *.css *.js *.png
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
{% extends "organization/base.html" %}
|
||||
{% load i18n static %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" type="text/css" media="all" href="{% static "css/jquery-ui.min.css" %}" />
|
||||
{% endblock %}
|
||||
|
||||
{% block extrascripts %}
|
||||
<script src="{% static "js/jquery-ui.min.js" %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block title %}
|
||||
{% trans "User creation" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{% trans "Create a user" %}<h1>
|
||||
<h3>{% trans "or more" %}<em> login-N</em></h2>
|
||||
|
||||
<form method="post" autocomplete="off">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<div class="form-actions">
|
||||
<input type="submit" value="{% trans "Create" %}" class="btn btn-primary" />
|
||||
</div>
|
||||
<script>
|
||||
$('input.datepicker').datepicker({ dateFormat: "yy-mm-dd", weekStart: 1 });
|
||||
</script>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
{% block appbar %}
|
||||
<h2>{% trans "Local users" %}</h2>
|
||||
<a href="{% url "create-users" organization.slug %}" rel="popup">{% trans "Create users" %}</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
|
|
@ -5,4 +5,5 @@ from .views import *
|
|||
urlpatterns = patterns('',
|
||||
url(r'^$', manage, name='manage'),
|
||||
url(r'^users/?$', users, name='manage-users'),
|
||||
url(r'^users/create$', create_users, name='create-users'),
|
||||
)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import random
|
||||
|
||||
from django.contrib.auth.hashers import make_password
|
||||
|
||||
from .models import LocalAccount
|
||||
|
||||
|
||||
def create_password():
|
||||
return ''.join([random.choice('23456789ABCDEFGHJLMNPQRSTUVWXZabcdefghjkmnpqrstuvwxyz')
|
||||
for x in range(random.randint(6,9))])
|
||||
|
||||
|
||||
def create_user(data):
|
||||
if not data['password']:
|
||||
data['password'] = create_password()
|
||||
try:
|
||||
user = LocalAccount.objects.create(**data)
|
||||
return user
|
||||
except:
|
||||
return False
|
|
@ -3,10 +3,14 @@ from django.core.urlresolvers import reverse_lazy
|
|||
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.list import ListView
|
||||
from django.views.generic.edit import FormView
|
||||
from django.contrib import messages
|
||||
|
||||
from django_tables2 import RequestConfig
|
||||
|
||||
from .utils import create_user
|
||||
from .models import LocalAccount, Organization
|
||||
from .forms import LocalAccountCreateForm
|
||||
from .tables import AccountTable
|
||||
|
||||
|
||||
|
@ -41,3 +45,33 @@ class UsersPageView(OrganizationMixin, ListView):
|
|||
return context
|
||||
|
||||
users = UsersPageView.as_view()
|
||||
|
||||
|
||||
class UsersCreateView(OrganizationMixin, FormView):
|
||||
template_name = 'organization/create-users.html'
|
||||
form_class = LocalAccountCreateForm
|
||||
|
||||
def form_valid(self, form):
|
||||
data = form.cleaned_data
|
||||
data['organization'] = Organization.objects.get(slug=self.kwargs['organization_slug'])
|
||||
accounts_number = data.pop('accounts_number')
|
||||
accounts_number_start = data.pop('accounts_number_start')
|
||||
if accounts_number_start < 1:
|
||||
accounts_number_start = 0
|
||||
|
||||
username = data['username']
|
||||
if accounts_number > 1:
|
||||
for index in xrange(accounts_number_start, accounts_number + accounts_number_start):
|
||||
data['username'] = '%s-%s' % (username, index)
|
||||
if not create_user(data):
|
||||
messages.error(self, request, _('Error while creating user %s' % data['username']))
|
||||
break
|
||||
messages.info(self.request, _('%s users added successfully' % accounts_number))
|
||||
else:
|
||||
if create_user(data):
|
||||
messages.info(self.request, _('User "%s" successfully created' % data['username']))
|
||||
else:
|
||||
messages.error(self.request, _('Error occured while creating user "%s"' % data['username']))
|
||||
return super(UsersCreateView, self).form_valid(form)
|
||||
|
||||
create_users = UsersCreateView.as_view()
|
||||
|
|
After Width: | Height: | Size: 418 B |
After Width: | Height: | Size: 312 B |
After Width: | Height: | Size: 205 B |
After Width: | Height: | Size: 262 B |
After Width: | Height: | Size: 348 B |
After Width: | Height: | Size: 207 B |
After Width: | Height: | Size: 5.7 KiB |
After Width: | Height: | Size: 278 B |
After Width: | Height: | Size: 328 B |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 6.2 KiB |