Commit e874a320b66ba12242da88d1cad270c058fb09b8

Authored by ailsoncgt
1 parent beabbf7f

Fixing commented errors #188

app/templates/home.html
... ... @@ -5,8 +5,14 @@
5 5 {% block javascript %}
6 6 {% if page_obj %}
7 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 16 var baseUrl = '{% url "app:index" %}';
11 17  
12 18 // loadOnScroll handler
... ...
core/static/css/base/amadeus.css
... ... @@ -2,6 +2,10 @@
2 2 clear: both;
3 3 }
4 4  
  5 +.mg-b-5m{
  6 + margin-bottom: 5em;
  7 +}
  8 +
5 9 .navbar .logo {position: absolute; top: 6px; text-align: center; height: 48px; width: 48px;}
6 10  
7 11 /* Modal */
... ...
core/static/js/base/amadeus.js
... ... @@ -14,6 +14,7 @@ function campoNumerico(campo, evento){
14 14 return true;
15 15 } else {
16 16 evento.returnValue = false;
  17 + evento.preventDefault();
17 18 return false;
18 19 }
19 20 };
... ... @@ -28,7 +29,7 @@ function formatarCpf(campo, evento){
28 29 }
29 30 else if( evento ) { // Firefox
30 31 codTecla = evento.which;
31   - }
  32 + }
32 33 tamanho = campo.value.length;
33 34 if( (codTecla > 47 && codTecla < 58) || codTecla== 8 || codTecla == 0){
34 35 if(tamanho < 14 ){
... ... @@ -41,8 +42,8 @@ function formatarCpf(campo, evento){
41 42 }
42 43 }else{
43 44 evento.returnValue = false;
  45 + return false;
44 46 }
45   - return true;
46 47 } else {
47 48 return false;
48 49 }
... ... @@ -61,30 +62,28 @@ function formatarTelefone(campo, evento){
61 62 }
62 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 67 if(tamanho == 0){
67 68 campo.value = "(" + campo.value;
68 69 }else if( tamanho == 3 ){
69 70 campo.value = campo.value + ") ";
70   - }else if(tamanho == 9){
  71 + }else if(tamanho == 10){
71 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 74 return true;
78 75  
  76 +
79 77 } else if(codTecla == 0 || codTecla == 8){
80 78 return true;
81 79 } else {
82 80 evento.returnValue = false;
  81 + evento.preventDefault()
83 82 return false;
84 83 }
  84 + evento.preventDefault()
85 85 return false;
86   -}
87   -
  86 +};
88 87 /*
89 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 63 def clean_birth_date(self):
64 64 birth_date = self.cleaned_data['birth_date']
65 65 if birth_date >= date.today():
66   - print('===============' + date.today() + '================')
67 66 raise forms.ValidationError(_('Please enter a valid date'))
68 67 return birth_date
69 68  
... ... @@ -73,10 +72,18 @@ class UpdateUserForm(forms.ModelForm):
73 72 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration',
74 73 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active']
75 74  
76   -class UpdateProfileForm(UpdateUserForm):
  75 +class UpdateProfileFormAdmin(UpdateUserForm):
77 76  
78 77 class Meta:
79 78 model = User
80 79 fields = ['username', 'name', 'email', 'birth_date', 'city',
81 80 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration',
82 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 3 {% load static i18n permission_tags %}
4 4 {% load widget_tweaks %}
... ... @@ -6,9 +6,13 @@
6 6 {% load django_bootstrap_breadcrumbs %}
7 7  
8 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 17 {% endblock %}
14 18  
... ... @@ -25,7 +29,7 @@
25 29 {% endfor %}
26 30 {% endif %}
27 31  
28   - <div class="card">
  32 + <div class="card mg-b-5m">
29 33 <div class="card-content">
30 34 <div class="card-body">
31 35 <form method="post" action="" enctype="multipart/form-data">
... ... @@ -53,6 +57,9 @@
53 57  
54 58 {% elif field.auto_id == 'id_phone' %}
55 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 64 {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %}
58 65 {% if user|has_role:'system_admin' %}
... ...
users/templates/users/update.html
... ... @@ -6,10 +6,10 @@
6 6 {% load django_bootstrap_breadcrumbs %}
7 7  
8 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 13 {% endblock %}
14 14  
15 15  
... ... @@ -25,7 +25,7 @@
25 25 {% endfor %}
26 26 {% endif %}
27 27  
28   - <div class="card">
  28 + <div class="card mg-b-5m">
29 29 <div class="card-content">
30 30 <div class="card-body">
31 31 <form method="post" action="" enctype="multipart/form-data">
... ...
users/views.py
... ... @@ -7,8 +7,9 @@ from django.contrib.auth.mixins import LoginRequiredMixin
7 7 from django.core.urlresolvers import reverse_lazy
8 8 from django.utils.translation import ugettext_lazy as _
9 9 from rolepermissions.shortcuts import assign_role
  10 +from rolepermissions.verifications import has_role
10 11 from .models import User
11   -from .forms import UserForm, UpdateProfileForm, UpdateUserForm
  12 +from .forms import UserForm, UpdateProfileForm, UpdateUserForm, UpdateProfileFormAdmin
12 13  
13 14 # ================ ADMIN =======================
14 15 class UsersListView(HasRoleMixin, LoginRequiredMixin, generic.ListView):
... ... @@ -110,8 +111,6 @@ class Remove_account(generic.TemplateView):
110 111  
111 112  
112 113 class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView):
113   -
114   - allowed_roles = ['student']
115 114 login_url = reverse_lazy("core:home")
116 115 template_name = 'users/edit_profile.html'
117 116 form_class = UpdateProfileForm
... ... @@ -121,6 +120,14 @@ class UpdateProfile(LoginRequiredMixin, generic.edit.UpdateView):
121 120 user = get_object_or_404(User, username = self.request.user.username)
122 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 131 def form_valid(self, form):
125 132 form.save()
126 133 messages.success(self.request, _('Profile edited successfully!'))
... ...