diff --git a/amadeus/templates/base.html b/amadeus/templates/base.html index bc61476..4b9c7df 100644 --- a/amadeus/templates/base.html +++ b/amadeus/templates/base.html @@ -169,6 +169,11 @@ + \ No newline at end of file diff --git a/users/forms.py b/users/forms.py index 3bc1720..7af2fc7 100644 --- a/users/forms.py +++ b/users/forms.py @@ -86,4 +86,26 @@ class ProfileForm(Validation): fields = ['social_name', 'description', 'show_email', 'image'] widgets = { 'description': forms.Textarea, - } \ No newline at end of file + } + +class UserForm(Validation): + password = forms.CharField(label=_('Password'), widget = forms.PasswordInput, required = False) + password2 = forms.CharField(label = _('Confirm Password'), widget = forms.PasswordInput, required = False) + + is_edit = False + + def save(self, commit=True): + super(UserForm, self).save(commit=False) + + self.instance.set_password(self.cleaned_data['password']) + + self.instance.save() + + return self.instance + + class Meta: + model = User + fields = ['email', 'username', 'last_name', 'social_name', 'description', 'show_email', 'image', 'is_staff', 'is_active'] + widgets = { + 'description': forms.Textarea, + } \ No newline at end of file diff --git a/users/migrations/0003_auto_20161222_1505.py b/users/migrations/0003_auto_20161222_1505.py new file mode 100644 index 0000000..56c7a51 --- /dev/null +++ b/users/migrations/0003_auto_20161222_1505.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2016-12-22 18:05 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models +import re +import users.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0002_auto_20161220_1700'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='email', + field=models.EmailField(help_text='Your email address that will be used to access the platform', max_length=254, unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[\\w.@+-]+$', 32), 'Type a valid email. This fields should only contain letters, numbers and the characteres: @/./+/-/_ .', 'invalid')], verbose_name='Mail'), + ), + migrations.AlterField( + model_name='user', + name='image', + field=models.ImageField(blank=True, null=True, upload_to='users/', validators=[users.models.validate_img_extension], verbose_name='Photo'), + ), + migrations.AlterField( + model_name='user', + name='show_email', + field=models.IntegerField(blank=True, choices=[(1, 'Allow everyone to see my address'), (2, 'Only classmates can see my address'), (3, 'Nobody can see my address')], default=1, null=True, verbose_name='Show email?'), + ), + ] diff --git a/users/models.py b/users/models.py index 320f91c..d6355da 100644 --- a/users/models.py +++ b/users/models.py @@ -29,7 +29,7 @@ class User(AbstractBaseUser, PermissionsMixin): image = models.ImageField(verbose_name = _('Photo'), null=True, blank = True, upload_to = 'users/', validators = [validate_img_extension]) date_created = models.DateTimeField(_('Create Date'), auto_now_add = True) last_update = models.DateTimeField(_('Last Update'), auto_now = True) - show_email = models.IntegerField(_('Show email?'), null = True, blank = True, choices = ((1, _('Allow everyone to see my address')), (2, _('Only classmates can see my address')), (3, _('Nobody can see my address')))) + show_email = models.IntegerField(_('Show email?'), null = True, blank = True, choices = ((1, _('Allow everyone to see my address')), (2, _('Only classmates can see my address')), (3, _('Nobody can see my address'))), default = 1) is_staff = models.BooleanField(_('Administrator'), default = False) is_active = models.BooleanField(_('Active'), default = True) @@ -46,7 +46,7 @@ class User(AbstractBaseUser, PermissionsMixin): return self.social_name or self.username def get_short_name(self): - return self.username + return str(self) @property def image_url(self): diff --git a/users/templates/users/create.html b/users/templates/users/create.html index 356e100..5c9dec7 100644 --- a/users/templates/users/create.html +++ b/users/templates/users/create.html @@ -1,4 +1,4 @@ -{% extends 'list_users.html' %} +{% extends 'users/list.html' %} {% load static i18n %} {% load widget_tweaks %} @@ -6,25 +6,11 @@ {% load django_bootstrap_breadcrumbs %} {% block breadcrumbs %} - - {{ block.super }} + {{ block.super }} {% breadcrumb 'Add User' 'users:create' %} - {% endblock %} - {% block content %} - {% if messages %} - {% for message in messages %} - - {% endfor %} - {% endif %} -
@@ -32,15 +18,7 @@ {% csrf_token %} {% for field in form %}
- {% if field.auto_id == 'id_birth_date' %} - {% if field.field.required %} - - {% else %} - - {% endif %} - - {% render_field field class='form-control date-picker' %} - {% elif field.auto_id == 'id_image' %} + {% if field.auto_id == 'id_image' %} {% if field.field.required %} {% else %} @@ -55,51 +33,19 @@
- - {% elif field.auto_id == 'id_curriculum' %} - {% if field.field.required %} + {% elif field.auto_id == 'id_description' %} + {% if field.field.required %} {% else %} {% endif %} - {% render_field field class='form-control' %} -
- - - - -
+ {% render_field field class='form-control text_wysiwyg' %} {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %}
- {% elif field.auto_id == 'id_cpf' %} - {% if field.field.required %} - - {% else %} - - {% endif %} - {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %} - - {% elif field.auto_id == 'id_year_titration' %} - {% if field.field.required %} - - {% else %} - - {% endif %} - {% render_field field class='form-control' onkeypress='campoNumerico(this,event);' %} - - {% elif field.auto_id == 'id_phone' %} - {% if field.field.required %} - - {% else %} - - {% endif %} - {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarTelefone(this,event);' %} {% else %} {% if field.field.required %} @@ -123,24 +69,11 @@ {% endif %}
{% endfor %} -
- -
-
-
-
-
-
- + {% endblock %} diff --git a/users/templates/users/edit_profile.html b/users/templates/users/edit_profile.html index 98259c2..9a58bee 100644 --- a/users/templates/users/edit_profile.html +++ b/users/templates/users/edit_profile.html @@ -69,11 +69,5 @@ - -
- + {% endblock %} diff --git a/users/templates/users/list.html b/users/templates/users/list.html index 2cc93d2..df8d3e3 100644 --- a/users/templates/users/list.html +++ b/users/templates/users/list.html @@ -38,7 +38,7 @@
- {% trans 'Create User' %} + {% trans 'Create User' %}
@@ -54,7 +54,11 @@

{% trans 'Name' %}: {{ acc }}

{% trans 'Email' %}: {{ acc.email }}

-

{% trans 'Description' %}: {{ acc.description|truncatechars:100|default:_("Not Informed") }}

+

{% trans 'Description' %}: + {% autoescape off %} + {{ acc.description|default:_("Not Informed")|striptags|truncatechars:300 }} + {% endautoescape %} +

diff --git a/users/urls.py b/users/urls.py index 7dc5f84..e0f5a5f 100644 --- a/users/urls.py +++ b/users/urls.py @@ -8,6 +8,7 @@ urlpatterns = [ url(r'^logout/$', auth_views.logout, {'next_page': 'users:login'}, name='logout'), url(r'^signup/$', views.RegisterUser.as_view(), name = 'signup'), url(r'^$', views.UsersListView.as_view(), name = 'manage'), + url(r'^create/$', views.CreateView.as_view(), name = 'create'), url(r'^profile/$', views.Profile.as_view(), name = 'profile'), url(r'^edit_profile/$', views.UpdateProfile.as_view(), name = 'edit_profile'), ] diff --git a/users/views.py b/users/views.py index 6266a02..8f4f36c 100644 --- a/users/views.py +++ b/users/views.py @@ -14,7 +14,7 @@ from itertools import chain from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from .models import User -from .forms import RegisterUserForm, ProfileForm +from .forms import RegisterUserForm, ProfileForm, UserForm #API IMPORTS from rest_framework import viewsets @@ -24,35 +24,7 @@ from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnl # ================ ADMIN ======================= -# class Create(HasRoleMixin, LoginRequiredMixin, generic.edit.CreateView): -# allowed_roles = ['system_admin'] -# #login_url = reverse_lazy("core:home") -# redirect_field_name = 'next' -# template_name = 'users/create.html' -# form_class = UserForm -# context_object_name = 'acc' -# success_url = reverse_lazy('users:manage') - -# def form_valid(self, form): -# self.object = form.save() - -# if self.object.type_profile == 2: -# assign_role(self.object, 'student') -# elif self.object.type_profile == 1: -# assign_role(self.object, 'professor') -# elif self.object.is_staff: -# assign_role(self.object, 'system_admin') - -# self.object.save() - -# messages.success(self.request, ('User ')+self.object.name+(' created successfully!')) - -# return super(Create, self).form_valid(form) -# def get_context_data (self, **kwargs): -# context = super(Create, self).get_context_data(**kwargs) -# context['title'] = "Add User" -# return context # class Update(HasRoleMixin, LoginRequiredMixin, generic.UpdateView): @@ -181,6 +153,31 @@ class UsersListView(HasRoleMixin, LoginRequiredMixin, generic.ListView): return context +class CreateView(HasRoleMixin, LoginRequiredMixin, generic.edit.CreateView): + login_url = reverse_lazy("users:login") + redirect_field_name = 'next' + + allowed_roles = ['system_admin'] + template_name = 'users/create.html' + form_class = UserForm + context_object_name = 'acc' + success_url = reverse_lazy('users:manage') + + def form_valid(self, form): + self.object = form.save() + + msg = _("User %s created successfully" % self.object.get_short_name()) + + messages.success(self.request, msg) + + return super(CreateView, self).form_valid(form) + + def get_context_data (self, **kwargs): + context = super(CreateView, self).get_context_data(**kwargs) + context['title'] = _("Add User") + + return context + class Profile(LoginRequiredMixin, generic.DetailView): login_url = reverse_lazy("users:login") redirect_field_name = 'next' -- libgit2 0.21.2