From 8617ef0d2d339ba5a472f5bf104d4bd801f4977d Mon Sep 17 00:00:00 2001 From: ailsoncgt Date: Wed, 26 Oct 2016 18:40:42 -0300 Subject: [PATCH] Permissions to edit staff user and field to update #185 --- users/forms.py | 8 ++++++-- users/templates/users/edit_profile.html | 58 +++++++++++++++++++++++++++++++++++++--------------------- users/templates/users/update.html | 4 ++-- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/users/forms.py b/users/forms.py index 57fb346..c3a70bc 100644 --- a/users/forms.py +++ b/users/forms.py @@ -69,10 +69,14 @@ class UpdateUserForm(forms.ModelForm): class Meta: model = User - fields = ['username', 'name', 'email', 'city', 'state', 'birth_date', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] + fields = ['username', 'name', 'email', 'birth_date', 'city', + 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration', + 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active'] class UpdateProfileForm(UpdateUserForm): class Meta: model = User - fields = ['username', 'name', 'email', 'birth_date', 'city', 'state', 'gender', 'cpf', 'phone', 'image', 'curriculum'] + fields = ['username', 'name', 'email', 'birth_date', 'city', + 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration', + 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active'] diff --git a/users/templates/users/edit_profile.html b/users/templates/users/edit_profile.html index 79ec3f2..f7e6732 100644 --- a/users/templates/users/edit_profile.html +++ b/users/templates/users/edit_profile.html @@ -1,16 +1,18 @@ -{% extends 'users/profile.html' %} +{% extends 'list_users.html' %} -{% load static i18n %} +{% load static i18n permission_tags %} {% load widget_tweaks %} + {% load django_bootstrap_breadcrumbs %} {% block breadcrumbs %} {{ block.super }} - {% breadcrumb 'Edit' 'users:update_profile' %} + {% breadcrumb 'Update User' 'users:update' %} {% endblock %} + {% block content %} {% if messages %} {% for message in messages %} @@ -22,6 +24,7 @@ {% endfor %} {% endif %} +
@@ -29,37 +32,51 @@ {% csrf_token %} {% for field in form %}
- + {% if not field.auto_id == 'id_is_staff' and not field.auto_id == 'id_is_active' and not field.auto_id == 'id_type_profile' %} + + {% endif %} {% if field.auto_id == 'id_birth_date' %} - + {{ field.help_text }} - {% elif field.auto_id == 'id_image' %} + {% elif field.auto_id == 'id_image' or field.auto_id == 'id_curriculum'%} {% render_field field class='form-control input-sm' %}
- +
- {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} -
- -
{% elif field.auto_id == 'id_cpf' %} {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %} {% elif field.auto_id == 'id_phone' %} {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarTelefone(this,event);' %} + + {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} + {% if user|has_role:'system_admin' %} + +
+ +
+ {% endif %} + {% elif field.auto_id == 'id_type_profile' %} + {% if user|has_role:'system_admin' %} + + {% render_field field class='form-control' %} + {{ field.help_text }} + {% endif %} {% else %} - {% render_field field class='form-control' %} - {{ field.help_text }} + {% if not field.auto_id == 'id_is_staff' and not field.auto_id == 'id_is_active' and not field.auto_id == 'id_type_profile' %} + {% render_field field class='form-control' %} + {{ field.help_text }} + {% endif %} {% endif %} {% if field.errors %} - -
{% endblock %} diff --git a/users/templates/users/update.html b/users/templates/users/update.html index 37ccef8..ccb9d1c 100644 --- a/users/templates/users/update.html +++ b/users/templates/users/update.html @@ -36,10 +36,10 @@ {% if field.auto_id == 'id_birth_date' %} {{ field.help_text }} - {% elif field.auto_id == 'id_image' %} + {% elif field.auto_id == 'id_image' or field.auto_id == 'id_curriculum'%} {% render_field field class='form-control input-sm' %}
- +