Commit 8617ef0d2d339ba5a472f5bf104d4bd801f4977d

Authored by ailsoncgt
1 parent 791b7e58

Permissions to edit staff user and field to update #185

users/forms.py
... ... @@ -69,10 +69,14 @@ class UpdateUserForm(forms.ModelForm):
69 69  
70 70 class Meta:
71 71 model = User
72   - fields = ['username', 'name', 'email', 'city', 'state', 'birth_date', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active']
  72 + fields = ['username', 'name', 'email', 'birth_date', 'city',
  73 + 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration',
  74 + 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active']
73 75  
74 76 class UpdateProfileForm(UpdateUserForm):
75 77  
76 78 class Meta:
77 79 model = User
78   - fields = ['username', 'name', 'email', 'birth_date', 'city', 'state', 'gender', 'cpf', 'phone', 'image', 'curriculum']
  80 + fields = ['username', 'name', 'email', 'birth_date', 'city',
  81 + 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'titration',
  82 + 'year_titration', 'institution', 'curriculum', 'is_staff', 'is_active']
... ...
users/templates/users/edit_profile.html
1   -{% extends 'users/profile.html' %}
  1 +{% extends 'list_users.html' %}
2 2  
3   -{% load static i18n %}
  3 +{% load static i18n permission_tags %}
4 4 {% load widget_tweaks %}
  5 +
5 6 {% load django_bootstrap_breadcrumbs %}
6 7  
7 8 {% block breadcrumbs %}
8 9  
9 10 {{ block.super }}
10   - {% breadcrumb 'Edit' 'users:update_profile' %}
  11 + {% breadcrumb 'Update User' 'users:update' %}
11 12  
12 13 {% endblock %}
13 14  
  15 +
14 16 {% block content %}
15 17 {% if messages %}
16 18 {% for message in messages %}
... ... @@ -22,6 +24,7 @@
22 24 </div>
23 25 {% endfor %}
24 26 {% endif %}
  27 +
25 28 <div class="card">
26 29 <div class="card-content">
27 30 <div class="card-body">
... ... @@ -29,37 +32,51 @@
29 32 {% csrf_token %}
30 33 {% for field in form %}
31 34 <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput">
32   - <label for="{{ field.auto_id }}">{{ field.label }}</label>
  35 + {% if not field.auto_id == 'id_is_staff' and not field.auto_id == 'id_is_active' and not field.auto_id == 'id_type_profile' %}
  36 + <label for="{{ field.auto_id }}">{{ field.label }}</label>
  37 + {% endif %}
33 38 {% if field.auto_id == 'id_birth_date' %}
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 }}">
  39 + <input type="text" class="form-control date-picker"name="{{field.name}}" value="{% if field.value.year %}{{field.value|date:'m/d/Y'}}{% else %}{{field.value}}{% endif %}" min="{{now|date:'m/d/Y'}}" id="{{ field.auto_id }}">
35 40 <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
36   - {% elif field.auto_id == 'id_image' %}
  41 + {% elif field.auto_id == 'id_image' or field.auto_id == 'id_curriculum'%}
37 42 {% render_field field class='form-control input-sm' %}
38 43 <div class="input-group">
39   - <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your photo...' %}">
  44 + <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}">
40 45 <span class="input-group-btn input-group-sm">
41 46 <button type="button" class="btn btn-fab btn-fab-mini">
42 47 <i class="material-icons">attach_file</i>
43 48 </button>
44 49 </span>
45 50 </div>
46   - {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %}
47   - <div class="checkbox">
48   - <label>
49   - {% render_field field type='checkbox' %}
50   - </label>
51   - </div>
52 51 {% elif field.auto_id == 'id_cpf' %}
53 52 {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %}
54 53  
55 54 {% elif field.auto_id == 'id_phone' %}
56 55 {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarTelefone(this,event);' %}
  56 +
  57 + {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %}
  58 + {% if user|has_role:'system_admin' %}
  59 + <label for="{{ field.auto_id }}">{{ field.label }}</label>
  60 + <div class="checkbox">
  61 + <label for="{{ field.auto_id }}">
  62 + {% render_field field %}<span class="checkbox-material"><span class="check"></span></span> {{field.label}}
  63 + </label>
  64 + </div>
  65 + {% endif %}
  66 + {% elif field.auto_id == 'id_type_profile' %}
  67 + {% if user|has_role:'system_admin' %}
  68 + <label for="{{ field.auto_id }}">{{ field.label }}</label>
  69 + {% render_field field class='form-control' %}
  70 + <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
  71 + {% endif %}
57 72 {% else %}
58   - {% render_field field class='form-control' %}
59   - <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
  73 + {% if not field.auto_id == 'id_is_staff' and not field.auto_id == 'id_is_active' and not field.auto_id == 'id_type_profile' %}
  74 + {% render_field field class='form-control' %}
  75 + <span id="helpBlock" class="help-block">{{ field.help_text }}</span>
  76 + {% endif %}
60 77 {% endif %}
61 78 {% if field.errors %}
62   - <div class="alert alert-danger alert-dismissible" role="alert">
  79 + <div class="alert alert-danger alert-dismissible col-md-offset-4 col-md-8" role="alert">
63 80 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
64 81 <span aria-hidden="true">&times;</span>
65 82 </button>
... ... @@ -72,16 +89,15 @@
72 89 {% endif %}
73 90 </div>
74 91 {% endfor %}
75   - <div class="col-md-3 col-sm-2 col-xs-2">
76   - <input type="submit" value="{% trans 'Save' %}" class="btn btn-raised btn-block btn-success" />
  92 + <div class="col-md-offset-2 col-md-2 col-sm-2 col-xs-2">
  93 + <input type="submit" value="{% trans 'Save' %}" class="btn btn-raised btn-success" />
77 94 </div>
78   - <div class="col-md-3 col-sm-2 col-xs-2">
79   - <a href="{% url 'users:profile' %}" class="btn btn-raised btn-block btn-danger" >{% trans 'Cancel' %}</a>
  95 + <div class="col-md-offset-3 col-md-2 col-sm-2 col-xs-2">
  96 + <a href="{% url 'users:profile' %}" class="btn btn-raised btn-danger" >{% trans 'Cancel' %}</a>
80 97 </div>
81 98 </form>
82 99 </div>
83 100 </div>
84 101 </div>
85   -
86 102 <br clear="all" />
87 103 {% endblock %}
... ...
users/templates/users/update.html
... ... @@ -36,10 +36,10 @@
36 36 {% if field.auto_id == 'id_birth_date' %}
37 37 <input type="text" class="form-control date-picker"name="{{field.name}}" value="{% if field.value.year %}{{field.value|date:'m/d/Y'}}{% else %}{{field.value}}{% endif %}" min="{{now|date:'m/d/Y'}}" id="{{ field.auto_id }}">
38 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' or field.auto_id == 'id_curriculum'%}
40 40 {% render_field field class='form-control input-sm' %}
41 41 <div class="input-group">
42   - <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your photo...' %}">
  42 + <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your file...' %}">
43 43 <span class="input-group-btn input-group-sm">
44 44 <button type="button" class="btn btn-fab btn-fab-mini">
45 45 <i class="material-icons">attach_file</i>
... ...