Commit e874a320b66ba12242da88d1cad270c058fb09b8
1 parent
beabbf7f
Exists in
master
and in
5 other branches
Fixing commented errors #188
Showing
7 changed files
with
57 additions
and
27 deletions
Show diff stats
app/templates/home.html
@@ -5,8 +5,14 @@ | @@ -5,8 +5,14 @@ | ||
5 | {% block javascript %} | 5 | {% block javascript %} |
6 | {% if page_obj %} | 6 | {% if page_obj %} |
7 | <script type="text/javascript"> | 7 | <script type="text/javascript"> |
8 | - var pageNum = {{ page_obj.number }}; // The latest page loaded | ||
9 | - var numberPages = {{ paginator.num_pages }}; // Indicates the number of pages | 8 | + {% if page_obj and paginator %} |
9 | + var pageNum = {{ page_obj.number }}; // The latest page loaded | ||
10 | + var numberPages = {{ paginator.num_pages }}; // Indicates the number of pages | ||
11 | + {% else %} | ||
12 | + var pageNum = 0 ; // The latest page loaded | ||
13 | + var numberPages = 0 ; // Indicates the number of pages | ||
14 | + {% endif %} | ||
15 | + | ||
10 | var baseUrl = '{% url "app:index" %}'; | 16 | var baseUrl = '{% url "app:index" %}'; |
11 | 17 | ||
12 | // loadOnScroll handler | 18 | // loadOnScroll handler |
core/static/css/base/amadeus.css
@@ -2,6 +2,10 @@ | @@ -2,6 +2,10 @@ | ||
2 | clear: both; | 2 | clear: both; |
3 | } | 3 | } |
4 | 4 | ||
5 | +.mg-b-5m{ | ||
6 | + margin-bottom: 5em; | ||
7 | +} | ||
8 | + | ||
5 | .navbar .logo {position: absolute; top: 6px; text-align: center; height: 48px; width: 48px;} | 9 | .navbar .logo {position: absolute; top: 6px; text-align: center; height: 48px; width: 48px;} |
6 | 10 | ||
7 | /* Modal */ | 11 | /* Modal */ |
core/static/js/base/amadeus.js
@@ -14,6 +14,7 @@ function campoNumerico(campo, evento){ | @@ -14,6 +14,7 @@ function campoNumerico(campo, evento){ | ||
14 | return true; | 14 | return true; |
15 | } else { | 15 | } else { |
16 | evento.returnValue = false; | 16 | evento.returnValue = false; |
17 | + evento.preventDefault(); | ||
17 | return false; | 18 | return false; |
18 | } | 19 | } |
19 | }; | 20 | }; |
@@ -28,7 +29,7 @@ function formatarCpf(campo, evento){ | @@ -28,7 +29,7 @@ function formatarCpf(campo, evento){ | ||
28 | } | 29 | } |
29 | else if( evento ) { // Firefox | 30 | else if( evento ) { // Firefox |
30 | codTecla = evento.which; | 31 | codTecla = evento.which; |
31 | - } | 32 | + } |
32 | tamanho = campo.value.length; | 33 | tamanho = campo.value.length; |
33 | if( (codTecla > 47 && codTecla < 58) || codTecla== 8 || codTecla == 0){ | 34 | if( (codTecla > 47 && codTecla < 58) || codTecla== 8 || codTecla == 0){ |
34 | if(tamanho < 14 ){ | 35 | if(tamanho < 14 ){ |
@@ -41,8 +42,8 @@ function formatarCpf(campo, evento){ | @@ -41,8 +42,8 @@ function formatarCpf(campo, evento){ | ||
41 | } | 42 | } |
42 | }else{ | 43 | }else{ |
43 | evento.returnValue = false; | 44 | evento.returnValue = false; |
45 | + return false; | ||
44 | } | 46 | } |
45 | - return true; | ||
46 | } else { | 47 | } else { |
47 | return false; | 48 | return false; |
48 | } | 49 | } |
@@ -61,30 +62,28 @@ function formatarTelefone(campo, evento){ | @@ -61,30 +62,28 @@ function formatarTelefone(campo, evento){ | ||
61 | } | 62 | } |
62 | tamanho = campo.value.length; | 63 | tamanho = campo.value.length; |
63 | 64 | ||
64 | - if(((codTecla > 47 && codTecla < 58) || (codTecla == 8)) && tamanho < 15){ | 65 | + if(((codTecla > 47 && codTecla < 58) && tamanho < 15)){ |
65 | 66 | ||
66 | if(tamanho == 0){ | 67 | if(tamanho == 0){ |
67 | campo.value = "(" + campo.value; | 68 | campo.value = "(" + campo.value; |
68 | }else if( tamanho == 3 ){ | 69 | }else if( tamanho == 3 ){ |
69 | campo.value = campo.value + ") "; | 70 | campo.value = campo.value + ") "; |
70 | - }else if(tamanho == 9){ | 71 | + }else if(tamanho == 10){ |
71 | campo.value = campo.value + "-"; | 72 | campo.value = campo.value + "-"; |
72 | - }else if(tamanho == 14){ | ||
73 | - // alert('oi'); | ||
74 | - campo.value = campo.value.slice(0, 4) + campo.value.slice(5, 14); | ||
75 | - campo.value = campo.value.slice(0, 8) + campo.value.slice(9, 10) + campo.value.slice(8, 9) + campo.value.slice(10, 14) | ||
76 | } | 73 | } |
77 | return true; | 74 | return true; |
78 | 75 | ||
76 | + | ||
79 | } else if(codTecla == 0 || codTecla == 8){ | 77 | } else if(codTecla == 0 || codTecla == 8){ |
80 | return true; | 78 | return true; |
81 | } else { | 79 | } else { |
82 | evento.returnValue = false; | 80 | evento.returnValue = false; |
81 | + evento.preventDefault() | ||
83 | return false; | 82 | return false; |
84 | } | 83 | } |
84 | + evento.preventDefault() | ||
85 | return false; | 85 | return false; |
86 | -} | ||
87 | - | 86 | +}; |
88 | /* | 87 | /* |
89 | This functions get the next 5 notifications from the user given a "step"(an amount) of previous notifications | 88 | This functions get the next 5 notifications from the user given a "step"(an amount) of previous notifications |
90 | */ | 89 | */ |
users/forms.py
@@ -63,7 +63,6 @@ class UpdateUserForm(forms.ModelForm): | @@ -63,7 +63,6 @@ class UpdateUserForm(forms.ModelForm): | ||
63 | def clean_birth_date(self): | 63 | def clean_birth_date(self): |
64 | birth_date = self.cleaned_data['birth_date'] | 64 | birth_date = self.cleaned_data['birth_date'] |
65 | if birth_date >= date.today(): | 65 | if birth_date >= date.today(): |
66 | - print('===============' + date.today() + '================') | ||
67 | raise forms.ValidationError(_('Please enter a valid date')) | 66 | raise forms.ValidationError(_('Please enter a valid date')) |
68 | return birth_date | 67 | return birth_date |
69 | 68 | ||
@@ -73,10 +72,18 @@ class UpdateUserForm(forms.ModelForm): | @@ -73,10 +72,18 @@ class UpdateUserForm(forms.ModelForm): | ||
73 | 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration', | 72 | 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration', |
74 | 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active'] | 73 | 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active'] |
75 | 74 | ||
76 | -class UpdateProfileForm(UpdateUserForm): | 75 | +class UpdateProfileFormAdmin(UpdateUserForm): |
77 | 76 | ||
78 | class Meta: | 77 | class Meta: |
79 | model = User | 78 | model = User |
80 | fields = ['username', 'name', 'email', 'birth_date', 'city', | 79 | fields = ['username', 'name', 'email', 'birth_date', 'city', |
81 | 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration', | 80 | 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration', |
82 | 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active'] | 81 | 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active'] |
82 | + | ||
83 | +class UpdateProfileForm(UpdateUserForm): | ||
84 | + | ||
85 | + class Meta: | ||
86 | + model = User | ||
87 | + fields = ['username', 'name', 'email', 'birth_date', 'city', | ||
88 | + 'state', 'gender', 'cpf', 'phone', 'image', 'titration', | ||
89 | + 'year_titration', 'institution', 'curriculum'] |
users/templates/users/edit_profile.html
1 | -{% extends 'list_users.html' %} | 1 | +{% extends 'users/profile.html' %} |
2 | 2 | ||
3 | {% load static i18n permission_tags %} | 3 | {% load static i18n permission_tags %} |
4 | {% load widget_tweaks %} | 4 | {% load widget_tweaks %} |
@@ -6,9 +6,13 @@ | @@ -6,9 +6,13 @@ | ||
6 | {% load django_bootstrap_breadcrumbs %} | 6 | {% load django_bootstrap_breadcrumbs %} |
7 | 7 | ||
8 | {% block breadcrumbs %} | 8 | {% block breadcrumbs %} |
9 | - | ||
10 | - {{ block.super }} | ||
11 | - {% breadcrumb 'Update User' 'users:update' %} | 9 | + {% if user|has_role:'system_admin' %} |
10 | + {{ block.super }} | ||
11 | + {% breadcrumb 'Update User' 'users:update' %} | ||
12 | + {% else %} | ||
13 | + {{ block.super }} | ||
14 | + {% breadcrumb 'Update Profile' 'users:update' %} | ||
15 | + {% endif %} | ||
12 | 16 | ||
13 | {% endblock %} | 17 | {% endblock %} |
14 | 18 | ||
@@ -25,7 +29,7 @@ | @@ -25,7 +29,7 @@ | ||
25 | {% endfor %} | 29 | {% endfor %} |
26 | {% endif %} | 30 | {% endif %} |
27 | 31 | ||
28 | - <div class="card"> | 32 | + <div class="card mg-b-5m"> |
29 | <div class="card-content"> | 33 | <div class="card-content"> |
30 | <div class="card-body"> | 34 | <div class="card-body"> |
31 | <form method="post" action="" enctype="multipart/form-data"> | 35 | <form method="post" action="" enctype="multipart/form-data"> |
@@ -53,6 +57,9 @@ | @@ -53,6 +57,9 @@ | ||
53 | 57 | ||
54 | {% elif field.auto_id == 'id_phone' %} | 58 | {% elif field.auto_id == 'id_phone' %} |
55 | {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarTelefone(this,event);' %} | 59 | {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarTelefone(this,event);' %} |
60 | + | ||
61 | + {% elif field.auto_id == 'id_year_titration' %} | ||
62 | + {% render_field field class='form-control' onkeypress='campoNumerico(this,event);' %} | ||
56 | 63 | ||
57 | {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} | 64 | {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} |
58 | {% if user|has_role:'system_admin' %} | 65 | {% if user|has_role:'system_admin' %} |
users/templates/users/update.html
@@ -6,10 +6,10 @@ | @@ -6,10 +6,10 @@ | ||
6 | {% load django_bootstrap_breadcrumbs %} | 6 | {% load django_bootstrap_breadcrumbs %} |
7 | 7 | ||
8 | {% block breadcrumbs %} | 8 | {% block breadcrumbs %} |
9 | - | ||
10 | - {{ block.super }} | ||
11 | - {% breadcrumb 'Update User' 'users:update' %} | ||
12 | - | 9 | + |
10 | + {{ block.super }} | ||
11 | + {% breadcrumb 'Update User' 'users:update' %} | ||
12 | + | ||
13 | {% endblock %} | 13 | {% endblock %} |
14 | 14 | ||
15 | 15 | ||
@@ -25,7 +25,7 @@ | @@ -25,7 +25,7 @@ | ||
25 | {% endfor %} | 25 | {% endfor %} |
26 | {% endif %} | 26 | {% endif %} |
27 | 27 | ||
28 | - <div class="card"> | 28 | + <div class="card mg-b-5m"> |
29 | <div class="card-content"> | 29 | <div class="card-content"> |
30 | <div class="card-body"> | 30 | <div class="card-body"> |
31 | <form method="post" action="" enctype="multipart/form-data"> | 31 | <form method="post" action="" enctype="multipart/form-data"> |
users/views.py
@@ -7,8 +7,9 @@ from django.contrib.auth.mixins import LoginRequiredMixin | @@ -7,8 +7,9 @@ from django.contrib.auth.mixins import LoginRequiredMixin | ||
7 | from django.core.urlresolvers import reverse_lazy | 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 rolepermissions.verifications import has_role | ||
10 | from .models import User | 11 | from .models import User |
11 | -from .forms import UserForm, UpdateProfileForm, UpdateUserForm | 12 | +from .forms import UserForm, UpdateProfileForm, UpdateUserForm, UpdateProfileFormAdmin |
12 | 13 | ||
13 | # ================ ADMIN ======================= | 14 | # ================ ADMIN ======================= |
14 | class UsersListView(HasRoleMixin, LoginRequiredMixin, generic.ListView): | 15 | class UsersListView(HasRoleMixin, LoginRequiredMixin, generic.ListView): |
@@ -110,8 +111,6 @@ class Remove_account(generic.TemplateView): | @@ -110,8 +111,6 @@ class Remove_account(generic.TemplateView): | ||
110 | 111 | ||
111 | 112 | ||
112 | class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView): | 113 | class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView): |
113 | - | ||
114 | - allowed_roles = ['student'] | ||
115 | login_url = reverse_lazy("core:home") | 114 | login_url = reverse_lazy("core:home") |
116 | template_name = 'users/edit_profile.html' | 115 | template_name = 'users/edit_profile.html' |
117 | form_class = UpdateProfileForm | 116 | form_class = UpdateProfileForm |
@@ -121,6 +120,14 @@ class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView): | @@ -121,6 +120,14 @@ class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView): | ||
121 | user = get_object_or_404(User, username = self.request.user.username) | 120 | user = get_object_or_404(User, username = self.request.user.username) |
122 | return user | 121 | return user |
123 | 122 | ||
123 | + def get_context_data(self, **kwargs): | ||
124 | + context = super(UpdateProfile, self).get_context_data(**kwargs) | ||
125 | + if has_role(self.request.user, 'system_admin'): | ||
126 | + context['form'] = UpdateProfileFormAdmin(instance = self.object) | ||
127 | + else: | ||
128 | + context['form'] = UpdateProfileForm(instance = self.object) | ||
129 | + return context | ||
130 | + | ||
124 | def form_valid(self, form): | 131 | def form_valid(self, form): |
125 | form.save() | 132 | form.save() |
126 | messages.success(self.request, _('Profile edited successfully!')) | 133 | messages.success(self.request, _('Profile edited successfully!')) |