Commit c7f0223c83e0469422da5c3a3d01885ec27537e3
Exists in
master
and in
5 other branches
Merge branch 'dev' of https://github.com/amadeusproject/amadeuslms into dev
Showing
14 changed files
with
161 additions
and
111 deletions
Show diff stats
core/static/js/base/amadeus.js
@@ -16,7 +16,7 @@ function campoNumerico(campo, evento){ | @@ -16,7 +16,7 @@ function campoNumerico(campo, evento){ | ||
16 | evento.returnValue = false; | 16 | evento.returnValue = false; |
17 | return false; | 17 | return false; |
18 | } | 18 | } |
19 | -} | 19 | +}; |
20 | 20 | ||
21 | function formatarCpf(campo, evento){ | 21 | function formatarCpf(campo, evento){ |
22 | var codTecla; | 22 | var codTecla; |
@@ -47,85 +47,37 @@ function formatarCpf(campo, evento){ | @@ -47,85 +47,37 @@ function formatarCpf(campo, evento){ | ||
47 | return false; | 47 | return false; |
48 | } | 48 | } |
49 | return false; | 49 | return false; |
50 | -} | 50 | +}; |
51 | 51 | ||
52 | -function validarCpfSemAlert(campo,nome,idElementoMensagemErro){ | ||
53 | - //alert("teste"); | ||
54 | - cpf = campo.value; | ||
55 | - | ||
56 | - cpf = cpf.replace(".",""); | ||
57 | - cpf = cpf.replace("-",""); | ||
58 | - cpf = cpf.replace(".",""); | ||
59 | - retorno = true; | 52 | +function formatarTelefone(campo, evento){ |
53 | + var codTecla; | ||
54 | + var tamanho; | ||
55 | + if( document.all ) { // Internet Explorer | ||
56 | + codTecla = evento.keyCode; | ||
57 | + } else if( document.layers ) { // Nestcape | ||
58 | + codTecla = evento.which; | ||
59 | + } else if( evento ) { // Firefox | ||
60 | + codTecla = evento.which; | ||
61 | + } | ||
62 | + tamanho = campo.value.length; | ||
60 | 63 | ||
61 | - if(trim(cpf).length > 0){ | ||
62 | - //alert("teste2"); | ||
63 | - cpfstr= ''; | ||
64 | - temp = cpf + ''; | ||
65 | - | ||
66 | - cpfstr = temp.substring(0,3); | ||
67 | - cpfstr = cpfstr + temp.substring(3,6); | ||
68 | - cpfstr = cpfstr + temp.substring(6,9); | ||
69 | - cpfstr = cpfstr + temp.substring(9,11); | ||
70 | - | ||
71 | - | ||
72 | - | ||
73 | - retorno = false; | ||
74 | - if(cpf != null){ | ||
75 | - //alert("teste3"); | ||
76 | - soma = 0; | ||
77 | - digito1 = 0; | ||
78 | - digito2 = 0; | ||
79 | - for(i = 0; i < 9; i = i + 1) { | ||
80 | - soma = soma + ((parseInt(cpf.substring(i,i+1)))*(11-(i+1))); | ||
81 | - } | ||
82 | - soma = soma % 11; | ||
83 | - if (soma == 0 || soma == 1) { | ||
84 | - digito1 = 0; | ||
85 | - } else { | ||
86 | - digito1 = 11 - soma; | ||
87 | - } | ||
88 | - soma = 0; | ||
89 | - | ||
90 | - for(i = 0; i < 9; i = i + 1) { | ||
91 | - soma = soma + ((parseInt(cpf.substring(i,i+1)))*(12-(i+1))); | ||
92 | - } | ||
93 | - soma = soma + (digito1*2); | ||
94 | - soma = soma % 11; | ||
95 | - if (soma == 0 || soma == 1) { | ||
96 | - digito2 = 0; | ||
97 | - } | ||
98 | - else{ | ||
99 | - digito2 = 11 - soma; | ||
100 | - } | ||
101 | - digito = digito1 +''+ digito2; | ||
102 | - | ||
103 | - | ||
104 | - //alert(cpfstr.substring(9,11)); | ||
105 | - if(digito == (cpfstr.substring(9,11))){ | ||
106 | - retorno = true; | ||
107 | - } else{ | ||
108 | - //alert("teste4"); | ||
109 | - retorno = false; | ||
110 | - | ||
111 | - } | ||
112 | - } else { | ||
113 | - retorno = false; | 64 | + if((codTecla > 47 && codTecla < 58) && tamanho < 14){ |
65 | + | ||
66 | + if(tamanho == 0){ | ||
67 | + campo.value = "(" + campo.value; | ||
68 | + }else if( tamanho == 3 ){ | ||
69 | + campo.value = campo.value + ")"; | ||
70 | + }else if(tamanho == 9){ | ||
71 | + campo.value = campo.value + "-"; | ||
114 | } | 72 | } |
115 | - }else{ | ||
116 | - retorno = false; | ||
117 | - } | ||
118 | - //alert(retorno); | ||
119 | - if(retorno == false){ | ||
120 | - //alert('E-mail informado invalido! Por favor, especifique um E-mail válido para o campo \"' + nome + '\".'); | ||
121 | - document.getElementById(idElementoMensagemErro).style.display = ''; | ||
122 | - campo.focus(); | ||
123 | - return false; | ||
124 | - }else{ | ||
125 | - document.getElementById(idElementoMensagemErro).style.display = 'none'; | ||
126 | return true; | 73 | return true; |
74 | + } else if(codTecla == 0 || codTecla == 8){ | ||
75 | + return true; | ||
76 | + } else { | ||
77 | + evento.returnValue = false; | ||
78 | + return false; | ||
127 | } | 79 | } |
128 | - return retorno; | 80 | + return false; |
129 | } | 81 | } |
130 | 82 | ||
131 | /* | 83 | /* |
core/tests.py
@@ -165,21 +165,21 @@ class UpdateUserTestCase(TestCase): | @@ -165,21 +165,21 @@ class UpdateUserTestCase(TestCase): | ||
165 | data = {'username': 'test', 'password': 'testing1'} | 165 | data = {'username': 'test', 'password': 'testing1'} |
166 | response = self.client.post(reverse('core:home'), data) | 166 | response = self.client.post(reverse('core:home'), data) |
167 | self.assertRedirects(response, reverse('app:index')) | 167 | self.assertRedirects(response, reverse('app:index')) |
168 | - | ||
169 | 168 | ||
170 | data={ | 169 | data={ |
171 | - 'username': 'testeamadeus', | ||
172 | - 'email': 'teste@amadeus.com', | 170 | + 'username': 'test', |
171 | + 'birth_date': '12/12/2000', | ||
172 | + 'email': 'testing@amadeus.com', | ||
173 | + 'cpf': '705.089.884-89', | ||
173 | 'name': 'Teste Amadeus', | 174 | 'name': 'Teste Amadeus', |
174 | 'city': 'Praia', | 175 | 'city': 'Praia', |
175 | 'state': 'PE', | 176 | 'state': 'PE', |
176 | 'gender': 'F', | 177 | 'gender': 'F', |
177 | } | 178 | } |
178 | - # self.assertRedirects(response1, reverse('app:index')) | ||
179 | response = self.client.get(self.url) | 179 | response = self.client.get(self.url) |
180 | self.assertEqual(response.status_code, 200) | 180 | self.assertEqual(response.status_code, 200) |
181 | response = self.client.post(self.url, data) | 181 | response = self.client.post(self.url, data) |
182 | - self.assertEqual(response.status_code, 302) | 182 | + self.assertRedirects(response, reverse('users:profile')) |
183 | 183 | ||
184 | def test_update_error(self): | 184 | def test_update_error(self): |
185 | 185 | ||
@@ -195,12 +195,13 @@ class UpdateUserTestCase(TestCase): | @@ -195,12 +195,13 @@ class UpdateUserTestCase(TestCase): | ||
195 | 'username': '', | 195 | 'username': '', |
196 | 'email': 'teste@amadeus.com', | 196 | 'email': 'teste@amadeus.com', |
197 | 'name': 'Teste Amadeus', | 197 | 'name': 'Teste Amadeus', |
198 | + 'birth_date': '12/12/2000', | ||
198 | 'city': 'Praia', | 199 | 'city': 'Praia', |
199 | 'state': 'PE', | 200 | 'state': 'PE', |
200 | 'gender': 'F', | 201 | 'gender': 'F', |
201 | } | 202 | } |
202 | response = self.client.post(self.url, data) | 203 | response = self.client.post(self.url, data) |
203 | - self.assertFormError(response, 'form', 'username', 'This field is required.') | 204 | + self.assertFormError(response, 'form', 'username', _('This field is required.')) |
204 | 205 | ||
205 | 206 | ||
206 | class DeleteUserTestCase(TestCase): | 207 | class DeleteUserTestCase(TestCase): |
courses/templates/subject/form_view_student.html
forum/static/js/forum.js
@@ -57,7 +57,9 @@ function createForum(url, topic) { | @@ -57,7 +57,9 @@ function createForum(url, topic) { | ||
57 | $(".forum_form").html(data); | 57 | $(".forum_form").html(data); |
58 | $("#id_topic").val(topic); | 58 | $("#id_topic").val(topic); |
59 | 59 | ||
60 | - $('.date-picker').datepicker(); | 60 | + $('.date-picker').datepicker({ |
61 | + format: 'dd/mm/yyyy', | ||
62 | + }); | ||
61 | 63 | ||
62 | var frm = $('#forum_create'); | 64 | var frm = $('#forum_create'); |
63 | frm.submit(function () { | 65 | frm.submit(function () { |
@@ -92,15 +94,16 @@ function createForum(url, topic) { | @@ -92,15 +94,16 @@ function createForum(url, topic) { | ||
92 | * Function to load edit forum's form and set the submit function | 94 | * Function to load edit forum's form and set the submit function |
93 | * | 95 | * |
94 | */ | 96 | */ |
95 | -function editForum(url, forum) { | 97 | +function editForum(url, forum, success_message) { |
96 | $.ajax({ | 98 | $.ajax({ |
97 | url: url, | 99 | url: url, |
98 | data: {'pk': forum}, | 100 | data: {'pk': forum}, |
99 | success: function(data) { | 101 | success: function(data) { |
100 | $(".forum_form").html(data); | 102 | $(".forum_form").html(data); |
101 | - //$("#id_topic").val(topic); | ||
102 | 103 | ||
103 | - $('.date-picker').datepicker(); | 104 | + $('.date-picker').datepicker({ |
105 | + format: 'dd/mm/yyyy', | ||
106 | + }); | ||
104 | 107 | ||
105 | var frm = $('#forum_create'); | 108 | var frm = $('#forum_create'); |
106 | frm.submit(function () { | 109 | frm.submit(function () { |
@@ -111,6 +114,8 @@ function editForum(url, forum) { | @@ -111,6 +114,8 @@ function editForum(url, forum) { | ||
111 | success: function (data) { | 114 | success: function (data) { |
112 | $('.forum_view').html(data); | 115 | $('.forum_view').html(data); |
113 | 116 | ||
117 | + alertify.success(success_message); | ||
118 | + | ||
114 | $("#editForum").modal('hide'); | 119 | $("#editForum").modal('hide'); |
115 | }, | 120 | }, |
116 | error: function(data) { | 121 | error: function(data) { |
forum/templates/forum/forum_view.html
@@ -41,7 +41,7 @@ | @@ -41,7 +41,7 @@ | ||
41 | </div> | 41 | </div> |
42 | <div class="panel-body"> | 42 | <div class="panel-body"> |
43 | <ul class="nav nav-pills nav-stacked"> | 43 | <ul class="nav nav-pills nav-stacked"> |
44 | - <li><a href="javascript:editForum('{% url 'course:forum:update' forum.id %}', '{{ forum.id }}')">{% trans 'Edit' %}</a></li> | 44 | + <li><a href="javascript:editForum('{% url 'course:forum:update' forum.id %}', '{{ forum.id }}', '{% trans 'Forum edited successfully!' %}')">{% trans 'Edit' %}</a></li> |
45 | <li><a href="javascript:delete_forum('{% url 'course:forum:delete' forum.id %}', '{{ forum.id }}', '{% trans "Are you sure you want to delete this forum?" %}', '{% url 'course:view_subject' forum.topic.subject.slug %}')">{% trans 'Delete' %}</a></li> | 45 | <li><a href="javascript:delete_forum('{% url 'course:forum:delete' forum.id %}', '{{ forum.id }}', '{% trans "Are you sure you want to delete this forum?" %}', '{% url 'course:view_subject' forum.topic.subject.slug %}')">{% trans 'Delete' %}</a></li> |
46 | </ul> | 46 | </ul> |
47 | </div> | 47 | </div> |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +from django import forms | ||
2 | +from .models import Link | ||
3 | + | ||
4 | +class CreateLinkForm(forms.ModelForm): | ||
5 | + class Meta: | ||
6 | + model = Link | ||
7 | + fields = ['name','link','description'] | ||
8 | + | ||
9 | +class UpdateLinkForm(forms.ModelForm): | ||
10 | + class Meta: | ||
11 | + model = Link | ||
12 | + fields = ['name','link','description'] |
links/views.py
1 | from django.shortcuts import render | 1 | from django.shortcuts import render |
2 | +from django.views import generic | ||
3 | +from django.core.urlresolvers import reverse_lazy | ||
4 | +from django.contrib import messages | ||
5 | +from django.utils.translation import ugettext_lazy as _ | ||
6 | + | ||
7 | + | ||
8 | +from .models import Link | ||
9 | +from .forms import * | ||
2 | 10 | ||
3 | # Create your views here. | 11 | # Create your views here. |
12 | +class CreateLink(generic.CreateView): | ||
13 | + template_name = 'links/' | ||
14 | + form_class = CreateLinkForm | ||
15 | + success_url = reverse_lazy() | ||
16 | + def form_valid(self, form): | ||
17 | + form.save() | ||
18 | + messages.success(self.request, _('Link created successfully!')) | ||
19 | + return super(CreateLink, self).form_valid(form) | ||
20 | + | ||
21 | + | ||
22 | +class DeleteLink(generic.DeleteView): | ||
23 | + | ||
24 | +class UpdateLink(generic.UpdateView): | ||
25 | + template_name = 'links/' | ||
26 | + form_class = UpdateLinkForm | ||
27 | + success_url = reverse_lazy() | ||
28 | + def form_valid(self, form): | ||
29 | + form.save() | ||
30 | + messages.success(self.request, _('Link updated successfully!')) | ||
31 | + | ||
32 | + return super(UpdateLink, self).form_valid(form) |
users/admin.py
1 | from django.contrib import admin | 1 | from django.contrib import admin |
2 | from .models import User | 2 | from .models import User |
3 | -from .forms import UserForm | 3 | +from .forms import AdminUserForm |
4 | 4 | ||
5 | class UserAdmin(admin.ModelAdmin): | 5 | class UserAdmin(admin.ModelAdmin): |
6 | list_display = ['username', 'name', 'email', 'is_staff', 'is_active'] | 6 | list_display = ['username', 'name', 'email', 'is_staff', 'is_active'] |
7 | search_fields = ['username', 'name', 'email'] | 7 | search_fields = ['username', 'name', 'email'] |
8 | - # form = UserForm | 8 | + form = AdminUserForm |
9 | 9 | ||
10 | admin.site.register(User, UserAdmin) | 10 | admin.site.register(User, UserAdmin) |
11 | \ No newline at end of file | 11 | \ No newline at end of file |
users/forms.py
1 | # coding=utf-8 | 1 | # coding=utf-8 |
2 | -import os | 2 | +import os, re |
3 | +from datetime import date | ||
4 | +from pycpfcnpj import cpfcnpj | ||
3 | from django.conf import settings | 5 | from django.conf import settings |
4 | from django import forms | 6 | from django import forms |
5 | from django.utils.translation import ugettext_lazy as _ | 7 | from django.utils.translation import ugettext_lazy as _ |
@@ -8,20 +10,27 @@ from django.contrib.auth.forms import UserCreationForm | @@ -8,20 +10,27 @@ from django.contrib.auth.forms import UserCreationForm | ||
8 | from core.forms import RegisterUserForm | 10 | from core.forms import RegisterUserForm |
9 | from .models import User | 11 | from .models import User |
10 | 12 | ||
11 | - | ||
12 | -class ProfileForm(forms.ModelForm): | ||
13 | - | 13 | +class AdminUserForm(forms.ModelForm): |
14 | def save(self, commit=True): | 14 | def save(self, commit=True): |
15 | - super(ProfileForm, self).save(commit=False) | 15 | + super(AdminUserForm, self).save(commit=False) |
16 | 16 | ||
17 | self.instance.set_password(self.cleaned_data['password']) | 17 | self.instance.set_password(self.cleaned_data['password']) |
18 | self.instance.save() | 18 | self.instance.save() |
19 | 19 | ||
20 | + if self.instance.is_staff: | ||
21 | + assign_role(self.instance, 'system_admin') | ||
22 | + elif self.instance.type_profile == 2: | ||
23 | + assign_role(self.instance, 'student') | ||
24 | + elif self.instance.type_profile == 1: | ||
25 | + assign_role(self.instance, 'professor') | ||
26 | + | ||
27 | + self.instance.save() | ||
28 | + | ||
20 | return self.instance | 29 | return self.instance |
21 | 30 | ||
22 | class Meta: | 31 | class Meta: |
23 | model = User | 32 | model = User |
24 | - fields = ['username', 'name', 'email', 'password', 'birth_date', 'city', 'state', 'gender', 'cpf', 'phone', 'image'] | 33 | + fields = ['username', 'name', 'email', 'password', 'birth_date', 'city', 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] |
25 | widgets = { | 34 | widgets = { |
26 | 'password':forms.PasswordInput | 35 | 'password':forms.PasswordInput |
27 | } | 36 | } |
@@ -32,16 +41,33 @@ class UserForm(RegisterUserForm): | @@ -32,16 +41,33 @@ class UserForm(RegisterUserForm): | ||
32 | model = User | 41 | model = User |
33 | fields = ['username', 'name', 'email', 'birth_date', 'city', 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] | 42 | fields = ['username', 'name', 'email', 'birth_date', 'city', 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] |
34 | 43 | ||
35 | -class EditUserForm(forms.ModelForm): | 44 | +class UpdateUserForm(forms.ModelForm): |
45 | + | ||
46 | + def validate_cpf(self, cpf): | ||
47 | + cpf = ''.join(re.findall('\d', str(cpf))) | ||
48 | + | ||
49 | + if cpfcnpj.validate(cpf): | ||
50 | + return True | ||
51 | + return False | ||
52 | + | ||
53 | + def clean_cpf(self): | ||
54 | + cpf = self.cleaned_data['cpf'] | ||
55 | + if not self.validate_cpf(cpf): | ||
56 | + raise forms.ValidationError(_('Please enter a valid CPF')) | ||
57 | + return cpf | ||
58 | + | ||
59 | + def clean_birth_date(self): | ||
60 | + birth_date = self.cleaned_data['birth_date'] | ||
61 | + if birth_date >= date.today(): | ||
62 | + raise forms.ValidationError(_('Please enter a valid date')) | ||
63 | + return birth_date | ||
36 | 64 | ||
37 | class Meta: | 65 | class Meta: |
38 | model = User | 66 | model = User |
39 | - fields = ['username', 'name', 'email', 'birth_date', 'city', 'state', 'gender', 'cpf', 'phone', 'image'] | 67 | + fields = ['username', 'name', 'email', 'city', 'state', 'birth_date', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] |
40 | 68 | ||
41 | -# Ailson | ||
42 | -class UpdateUserForm(forms.ModelForm): | ||
43 | - company_logo = forms.ImageField(label=_('Company Logo'),required=False, error_messages = {'invalid':_("Image files only")}) | 69 | +class UpdateProfileForm(UpdateUserForm): |
44 | 70 | ||
45 | class Meta: | 71 | class Meta: |
46 | model = User | 72 | model = User |
47 | - fields = ['username', 'name', 'email', 'city', 'state', 'birth_date', 'gender', 'cpf', 'phone', 'image'] | ||
48 | \ No newline at end of file | 73 | \ No newline at end of file |
74 | + fields = ['username', 'name', 'email', 'birth_date', 'city', 'state', 'gender', 'cpf', 'phone', 'image'] |
users/templates/users/edit_profile.html
@@ -31,7 +31,7 @@ | @@ -31,7 +31,7 @@ | ||
31 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | 31 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> |
32 | <label for="{{ field.auto_id }}">{{ field.label }}</label> | 32 | <label for="{{ field.auto_id }}">{{ field.label }}</label> |
33 | {% if field.auto_id == 'id_birth_date' %} | 33 | {% if field.auto_id == 'id_birth_date' %} |
34 | - <input type="date" class="form-control"name="{{field.name}}" value="{% if field.value.year %}{{field.value|date:'Y-m-d'}}{% else %}{{field.value}}{% endif %}" min="{{now|date:'Y-m-d'}}" id="{{ field.auto_id }}"> | 34 | + <input type="text" class="form-control date-picker"name="{{field.name}}" value="{% if field.value.year %}{{field.value|date:'Y-m-d'}}{% else %}{{field.value}}{% endif %}" min="{{now|date:'Y-m-d'}}" id="{{ field.auto_id }}"> |
35 | <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | 35 | <span id="helpBlock" class="help-block">{{ field.help_text }}</span> |
36 | {% elif field.auto_id == 'id_image' %} | 36 | {% elif field.auto_id == 'id_image' %} |
37 | {% render_field field class='form-control input-sm' %} | 37 | {% render_field field class='form-control input-sm' %} |
@@ -49,11 +49,16 @@ | @@ -49,11 +49,16 @@ | ||
49 | {% render_field field type='checkbox' %} | 49 | {% render_field field type='checkbox' %} |
50 | </label> | 50 | </label> |
51 | </div> | 51 | </div> |
52 | + {% elif field.auto_id == 'id_cpf' %} | ||
53 | + {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %} | ||
54 | + | ||
55 | + {% elif field.auto_id == 'id_phone' %} | ||
56 | + {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarTelefone(this,event);' %} | ||
52 | {% else %} | 57 | {% else %} |
53 | {% render_field field class='form-control' %} | 58 | {% render_field field class='form-control' %} |
54 | <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | 59 | <span id="helpBlock" class="help-block">{{ field.help_text }}</span> |
55 | {% endif %} | 60 | {% endif %} |
56 | - {% if field.errors.length > 0 %} | 61 | + {% if field.errors %} |
57 | <div class="alert alert-danger alert-dismissible" role="alert"> | 62 | <div class="alert alert-danger alert-dismissible" role="alert"> |
58 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | 63 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"> |
59 | <span aria-hidden="true">×</span> | 64 | <span aria-hidden="true">×</span> |
@@ -64,7 +69,6 @@ | @@ -64,7 +69,6 @@ | ||
64 | {% endfor %} | 69 | {% endfor %} |
65 | </ul> | 70 | </ul> |
66 | </div> | 71 | </div> |
67 | - </div> | ||
68 | {% endif %} | 72 | {% endif %} |
69 | </div> | 73 | </div> |
70 | {% endfor %} | 74 | {% endfor %} |
users/templates/users/profile.html
@@ -27,6 +27,17 @@ | @@ -27,6 +27,17 @@ | ||
27 | {% endblock %} | 27 | {% endblock %} |
28 | 28 | ||
29 | {% block content %} | 29 | {% block content %} |
30 | + {% if messages %} | ||
31 | + {% for message in messages %} | ||
32 | + <div class="alert alert-success alert-dismissible" role="alert"> | ||
33 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
34 | + <span aria-hidden="true">×</span> | ||
35 | + </button> | ||
36 | + <p>{{ message }}</p> | ||
37 | + </div> | ||
38 | + {% endfor %} | ||
39 | + {% endif %} | ||
40 | + | ||
30 | <div class="row"> | 41 | <div class="row"> |
31 | <div class="col-lg-offset-4 col-lg-2"> | 42 | <div class="col-lg-offset-4 col-lg-2"> |
32 | <img src="" class="img-responsive center-block " alt="logo amadeus"> | 43 | <img src="" class="img-responsive center-block " alt="logo amadeus"> |
users/templates/users/update.html
@@ -34,7 +34,7 @@ | @@ -34,7 +34,7 @@ | ||
34 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | 34 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> |
35 | <label for="{{ field.auto_id }}">{{ field.label }}</label> | 35 | <label for="{{ field.auto_id }}">{{ field.label }}</label> |
36 | {% if field.auto_id == 'id_birth_date' %} | 36 | {% if field.auto_id == 'id_birth_date' %} |
37 | - <input type="date" class="form-control"name="{{field.name}}" value="{% if field.value.year %}{{field.value|date:'Y-m-d'}}{% else %}{{field.value}}{% endif %}" min="{{now|date:'Y-m-d'}}" id="{{ field.auto_id }}"> | 37 | + <input type="text" class="form-control date-picker"name="{{field.name}}" value="{% if field.value.year %}{{field.value|date:'Y-m-d'}}{% else %}{{field.value}}{% endif %}" min="{{now|date:'Y-m-d'}}" id="{{ field.auto_id }}"> |
38 | <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | 38 | <span id="helpBlock" class="help-block">{{ field.help_text }}</span> |
39 | {% elif field.auto_id == 'id_image' %} | 39 | {% elif field.auto_id == 'id_image' %} |
40 | {% render_field field class='form-control input-sm' %} | 40 | {% render_field field class='form-control input-sm' %} |
@@ -48,6 +48,16 @@ | @@ -48,6 +48,16 @@ | ||
48 | </div> | 48 | </div> |
49 | {% elif field.auto_id == 'id_cpf' %} | 49 | {% elif field.auto_id == 'id_cpf' %} |
50 | {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %} | 50 | {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %} |
51 | + | ||
52 | + {% elif field.auto_id == 'id_phone' %} | ||
53 | + {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarTelefone(this,event);' %} | ||
54 | + | ||
55 | + {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} | ||
56 | + <div class="checkbox"> | ||
57 | + <label for="{{ field.auto_id }}"> | ||
58 | + {% render_field field %}<span class="checkbox-material"><span class="check"></span></span> {{field.label}} | ||
59 | + </label> | ||
60 | + </div> | ||
51 | {% else %} | 61 | {% else %} |
52 | {% render_field field class='form-control' %} | 62 | {% render_field field class='form-control' %} |
53 | <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | 63 | <span id="helpBlock" class="help-block">{{ field.help_text }}</span> |
users/urls.py
@@ -11,6 +11,6 @@ urlpatterns = [ | @@ -11,6 +11,6 @@ urlpatterns = [ | ||
11 | url(r'^profile/$', views.Profile.as_view(), name='profile'), | 11 | url(r'^profile/$', views.Profile.as_view(), name='profile'), |
12 | url(r'^profile/editar/(?P<username>[\w_-]+)/$', views.EditProfile.as_view(), name='edit_profile'), | 12 | url(r'^profile/editar/(?P<username>[\w_-]+)/$', views.EditProfile.as_view(), name='edit_profile'), |
13 | # | 13 | # |
14 | - url(r'^profile/update/$', views.UpdateUser.as_view(), name='update_profile'), | 14 | + url(r'^profile/update/$', views.UpdateProfile.as_view(), name='update_profile'), |
15 | url(r'^profile/delete/$', views.DeleteUser.as_view(), name='delete_profile'), | 15 | url(r'^profile/delete/$', views.DeleteUser.as_view(), name='delete_profile'), |
16 | ] | 16 | ] |
users/views.py
@@ -8,7 +8,7 @@ from django.core.urlresolvers import reverse_lazy | @@ -8,7 +8,7 @@ from django.core.urlresolvers import reverse_lazy | ||
8 | from django.utils.translation import ugettext_lazy as _ | 8 | from django.utils.translation import ugettext_lazy as _ |
9 | from rolepermissions.shortcuts import assign_role | 9 | from rolepermissions.shortcuts import assign_role |
10 | from .models import User | 10 | from .models import User |
11 | -from .forms import UserForm, ProfileForm, UpdateUserForm | 11 | +from .forms import UserForm, UpdateProfileForm, UpdateUserForm |
12 | 12 | ||
13 | # ================ ADMIN ======================= | 13 | # ================ ADMIN ======================= |
14 | class UsersListView(HasRoleMixin, LoginRequiredMixin, generic.ListView): | 14 | class UsersListView(HasRoleMixin, LoginRequiredMixin, generic.ListView): |
@@ -103,13 +103,13 @@ def delete(request,username): | @@ -103,13 +103,13 @@ def delete(request,username): | ||
103 | 103 | ||
104 | 104 | ||
105 | 105 | ||
106 | -class UpdateUser(LoginRequiredMixin, generic.edit.UpdateView): | 106 | +class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView): |
107 | 107 | ||
108 | allowed_roles = ['student'] | 108 | allowed_roles = ['student'] |
109 | login_url = reverse_lazy("core:home") | 109 | login_url = reverse_lazy("core:home") |
110 | template_name = 'users/edit_profile.html' | 110 | template_name = 'users/edit_profile.html' |
111 | - form_class = UpdateUserForm | ||
112 | - success_url = reverse_lazy('users:update_profile') | 111 | + form_class = UpdateProfileForm |
112 | + success_url = reverse_lazy('users:profile') | ||
113 | 113 | ||
114 | def get_object(self): | 114 | def get_object(self): |
115 | user = get_object_or_404(User, username = self.request.user.username) | 115 | user = get_object_or_404(User, username = self.request.user.username) |
@@ -119,7 +119,7 @@ class UpdateUser(LoginRequiredMixin, generic.edit.UpdateView): | @@ -119,7 +119,7 @@ class UpdateUser(LoginRequiredMixin, generic.edit.UpdateView): | ||
119 | form.save() | 119 | form.save() |
120 | messages.success(self.request, _('Profile edited successfully!')) | 120 | messages.success(self.request, _('Profile edited successfully!')) |
121 | 121 | ||
122 | - return super(UpdateUser, self).form_valid(form) | 122 | + return super(UpdateProfile, self).form_valid(form) |
123 | 123 | ||
124 | class DeleteUser(LoginRequiredMixin, generic.edit.DeleteView): | 124 | class DeleteUser(LoginRequiredMixin, generic.edit.DeleteView): |
125 | allowed_roles = ['student'] | 125 | allowed_roles = ['student'] |