Commit 6d208695ce45b2dc34bec1e3f1c3b0308edf7663
1 parent
999ebc8a
Exists in
master
and in
5 other branches
Ajustes no template e no campo de senha de de criar usuario
Showing
4 changed files
with
55 additions
and
57 deletions
Show diff stats
amadeus/settings.py
| ... | ... | @@ -78,8 +78,8 @@ TEMPLATES = [ |
| 78 | 78 | 'django.contrib.auth.context_processors.auth', |
| 79 | 79 | 'django.contrib.messages.context_processors.messages', |
| 80 | 80 | |
| 81 | - # 'core.context_processors.notifications', | |
| 82 | - # 'courses.context_processors.courses', | |
| 81 | + 'core.context_processors.notifications', | |
| 82 | + 'courses.context_processors.courses', | |
| 83 | 83 | ], |
| 84 | 84 | }, |
| 85 | 85 | }, | ... | ... |
core/context_processors.py
| ... | ... | @@ -3,9 +3,8 @@ from .models import Notification |
| 3 | 3 | def notifications(request): |
| 4 | 4 | context = {} |
| 5 | 5 | context['notifications'] = None |
| 6 | - if not request.user is None: | |
| 7 | - if request.user.is_authenticated: | |
| 8 | - return { | |
| 9 | - 'notifications': Notification.objects.filter(user= request.user, read=False).order_by('-datetime') | |
| 10 | - } | |
| 6 | + if request.user.is_authenticated: | |
| 7 | + return { | |
| 8 | + 'notifications': Notification.objects.filter(user= request.user, read=False).order_by('-datetime') | |
| 9 | + } | |
| 11 | 10 | return context | ... | ... |
users/forms.py
| ... | ... | @@ -4,6 +4,7 @@ from django.conf import settings |
| 4 | 4 | from django import forms |
| 5 | 5 | from django.utils.translation import ugettext_lazy as _ |
| 6 | 6 | from rolepermissions.shortcuts import assign_role |
| 7 | +from django.contrib.auth.forms import UserCreationForm | |
| 7 | 8 | from .models import User |
| 8 | 9 | |
| 9 | 10 | |
| ... | ... | @@ -22,35 +23,32 @@ class ProfileForm(forms.ModelForm): |
| 22 | 23 | fields = ['username', 'name', 'email', 'password', 'birth_date', 'city', 'state', 'gender', 'cpf', 'phone', 'image'] |
| 23 | 24 | widgets = { |
| 24 | 25 | 'password':forms.PasswordInput |
| 25 | - } | |
| 26 | - | |
| 27 | -class UserForm(forms.ModelForm): | |
| 28 | - def save(self, commit=True): | |
| 29 | - super(UserForm, self).save(commit=False) | |
| 30 | - | |
| 31 | - #if not self.instance.image: | |
| 32 | - # self.instance.image = os.path.join(os.path.dirname(settings.BASE_DIR), 'uploads', 'no_image.jpg') | |
| 33 | - | |
| 34 | - self.instance.set_password(self.cleaned_data['password']) | |
| 35 | - self.instance.save() | |
| 36 | - | |
| 37 | - if self.instance.is_staff: | |
| 38 | - assign_role(self.instance, 'system_admin') | |
| 39 | - elif self.instance.type_profile == 2: | |
| 40 | - assign_role(self.instance, 'student') | |
| 41 | - elif self.instance.type_profile == 1: | |
| 42 | - assign_role(self.instance, 'professor') | |
| 43 | - | |
| 44 | - self.instance.save() | |
| 26 | + } | |
| 45 | 27 | |
| 46 | - return self.instance | |
| 28 | +class UserForm(UserCreationForm): | |
| 29 | + # def save(self, commit=True): | |
| 30 | + # super(UserForm, self).save() | |
| 31 | + # | |
| 32 | + # #if not self.instance.image: | |
| 33 | + # # self.instance.image = os.path.join(os.path.dirname(settings.BASE_DIR), 'uploads', 'no_image.jpg') | |
| 34 | + # | |
| 35 | + # # self.instance.set_password(self.cleaned_data['password']) | |
| 36 | + # # self.instance.save() | |
| 37 | + # | |
| 38 | + # if self.instance.is_staff: | |
| 39 | + # assign_role(self.instance, 'system_admin') | |
| 40 | + # elif self.instance.type_profile == 2: | |
| 41 | + # assign_role(self.instance, 'student') | |
| 42 | + # elif self.instance.type_profile == 1: | |
| 43 | + # assign_role(self.instance, 'professor') | |
| 44 | + # | |
| 45 | + # self.instance.save() | |
| 46 | + # | |
| 47 | + # return self.instance | |
| 47 | 48 | |
| 48 | 49 | class Meta: |
| 49 | 50 | model = User |
| 50 | - fields = ['username', 'name', 'email', 'password', 'birth_date', 'city', 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] | |
| 51 | - widgets = { | |
| 52 | - 'password':forms.PasswordInput | |
| 53 | - } | |
| 51 | + fields = ['username', 'name', 'email', 'birth_date', 'city', 'state', 'gender', 'type_profile', 'cpf', 'phone', 'image', 'is_staff', 'is_active'] | |
| 54 | 52 | |
| 55 | 53 | class EditUserForm(forms.ModelForm): |
| 56 | 54 | ... | ... |
users/templates/users/create.html
| ... | ... | @@ -32,30 +32,31 @@ |
| 32 | 32 | {% csrf_token %} |
| 33 | 33 | {% for field in form %} |
| 34 | 34 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> |
| 35 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
| 36 | 35 | {% if field.auto_id == 'id_birth_date' %} |
| 37 | - {% render_field field class='form-control input-sm' type='date' %} | |
| 38 | - <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
| 36 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
| 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 %}"> | |
| 39 | 38 | {% elif field.auto_id == 'id_image' %} |
| 40 | - {% render_field field class='form-control input-sm' %} | |
| 39 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
| 40 | + {% render_field field class='form-control' %} | |
| 41 | 41 | <div class="input-group"> |
| 42 | - <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your photo...' %}"> | |
| 43 | - <span class="input-group-btn input-group-sm"> | |
| 44 | - <button type="button" class="btn btn-fab btn-fab-mini"> | |
| 45 | - <i class="material-icons">attach_file</i> | |
| 46 | - </button> | |
| 47 | - </span> | |
| 48 | - </div> | |
| 49 | - {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} | |
| 50 | - <div class="checkbox"> | |
| 51 | - <label> | |
| 52 | - {% render_field field type='checkbox' %} | |
| 53 | - </label> | |
| 54 | - </div> | |
| 42 | + <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your photo...' %}"> | |
| 43 | + <span class="input-group-btn input-group-sm"> | |
| 44 | + <button type="button" class="btn btn-fab btn-fab-mini"> | |
| 45 | + <i class="material-icons">attach_file</i> | |
| 46 | + </button> | |
| 47 | + </span> | |
| 48 | + </div> | |
| 49 | + {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} | |
| 50 | + <div class="checkbox"> | |
| 51 | + <label> | |
| 52 | + <input type="checkbox" name="checkbox"><span class="checkbox-material"><span class="check"></span></span> {{field.label}} | |
| 53 | + </label> | |
| 54 | + </div> | |
| 55 | 55 | {% else %} |
| 56 | - {% render_field field class='form-control input-sm' %} | |
| 57 | - <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
| 56 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | |
| 57 | + {% render_field field class='form-control' %} | |
| 58 | 58 | {% endif %} |
| 59 | + <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | |
| 59 | 60 | {% if field.errors.length > 0 %} |
| 60 | 61 | <div class="alert alert-danger alert-dismissible" role="alert"> |
| 61 | 62 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"> |
| ... | ... | @@ -67,20 +68,20 @@ |
| 67 | 68 | {% endfor %} |
| 68 | 69 | </ul> |
| 69 | 70 | </div> |
| 70 | - </div> | |
| 71 | 71 | {% endif %} |
| 72 | 72 | </div> |
| 73 | 73 | {% endfor %} |
| 74 | 74 | <div class="col-md-offset-2 col-md-2 col-sm-2 col-xs-2"> |
| 75 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | |
| 75 | + <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | |
| 76 | 76 | </div> |
| 77 | 77 | <div class="col-md-offset-3 col-md-2 col-sm-2 col-xs-2"> |
| 78 | - <a href="{% url 'users:manage' %}" class="btn btn-sm btn-success" >{% trans 'Cancel' %}</a> | |
| 78 | + <a href="{% url 'users:manage' %}" class="btn btn-sm btn-default" >{% trans 'Cancel' %}</a> | |
| 79 | 79 | </div> |
| 80 | 80 | </form> |
| 81 | 81 | </div> |
| 82 | 82 | </div> |
| 83 | - </div> | |
| 84 | - | |
| 85 | - <br clear="all" /> | |
| 83 | + </div> | |
| 84 | +</br> | |
| 85 | +</br> | |
| 86 | +</br> | |
| 86 | 87 | {% endblock %} | ... | ... |