Skip to content

Commit

Permalink
Merge pull request #279 from fga-gpp-mds/devel
Browse files Browse the repository at this point in the history
TS37-EditProfile
  • Loading branch information
Bumbleblo authored Dec 7, 2017
2 parents cf48abe + abf414b commit c214bf8
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
</li>

<li><a href="{% url 'dashboard_hp' %}"><i class="fa fa-dashboard"></i> <span>Dashboard</span></a></li>
<li><a href="#"><i class="fa fa-cog"></i> <span>Configurações</span></a></li>
<li><a href="{% url 'edit_profile' %}"><i class="fa fa-cog"></i> <span>Configurações</span></a></li>
</ul>

<!-- /.sidebar-menu -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<li><a href="{% url 'list_patient_prescription' %}"><i class="fa fa-files-o"></i> <span>Prescrições</span></a></li>
<li><a href="{% url 'list_patient_files' %}"><i class="glyphicon glyphicon-open"></i><span>Arquivo(s) enviado(s)</span></a></li>
<li><a href="#"><i class="glyphicon glyphicon-file"></i><span>Exames</span></a></li>
<li><a href="{% url 'edit_patient_password' request.user.email %}"><i class="fa fa-cog"></i><span>Configurações</span></a></li>
<li><a href="{% url 'edit_profile' %}"><i class="fa fa-cog"></i><span>Configurações</span></a></li>
</ul>

<!-- /.sidebar-menu -->
Expand Down
2 changes: 1 addition & 1 deletion medical_prescription/user/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
# PHONE_NUMBER FIELDS.
PHONE_NUMBER = "Phone number"
PHONE_NUMBER_FIELD_LENGTH_MAX = 14
PHONE_NUMBER_FIELD_LENGTH_MIN = 13
PHONE_NUMBER_FIELD_LENGTH_MIN = 10

# PHONE_NUMBER VALIDATION MESSAGES.
PHONE_NUMBER_SIZE = 'Phone number must be between 13 and 14 characters'
Expand Down
24 changes: 15 additions & 9 deletions medical_prescription/user/forms/updateuserform.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@ class UpdateUserForm(forms.ModelForm):
Form to update the users.
"""

date_of_birth = FormattedDateField(initial=date.today)
password = forms.CharField(widget=forms.PasswordInput())
name = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control',
'type': 'text',
'placeholder': _('Nome')}))

phone = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control',
'type': 'text',
'placeholder': _('Telefone')}))

date_of_birth = FormattedDateField(initial=date.today, widget=forms.DateInput(format='%d/%m/%Y', attrs={'class': 'form-control'}))

image_profile = forms.FileField(required=False, widget=forms.FileInput, initial='')


class Meta:
# Define model to User.
model = User
fields = [
'name', 'date_of_birth', 'phone', 'sex'
'name', 'date_of_birth', 'phone', 'sex', 'image_profile'
]

def clean(self):
Expand All @@ -40,24 +50,20 @@ def clean(self):

name = self.cleaned_data.get('name')
phone = self.cleaned_data.get('phone')
password = self.cleaned_data.get('password')
date_of_birth = self.cleaned_data.get('date_of_birth')
self.validator_all(name, phone, password, date_of_birth)
self.validator_all(name, phone, date_of_birth)

logger.debug("Exit clean data in UpdateUserForm.")

def validator_all(self, name, phone, password, date_of_birth):
def validator_all(self, name, phone, date_of_birth):
"""
Checks validator in all fields.
"""

logger.debug("Start validations in UpdateUserForm.")

self.verify_password(password)

validator = UserValidator()
validator.validator_name(name)
validator.validator_password(password, password)
validator.validator_phone_number(phone)
validator.validator_date_of_birth(date_of_birth)

Expand Down
142 changes: 80 additions & 62 deletions medical_prescription/user/templates/edit_health_professional.html
Original file line number Diff line number Diff line change
@@ -1,74 +1,92 @@
{% extends "editHealthProfessionalLanding/template.html" %} {% block content %} {% load staticfiles %} {% load static %}{% load i18n %}
<!-- Register Form -->
<div class="g-position--relative g-bg-color--primary">
<div class="g-container--md g-padding-y-125--xs">
<div class="g-text-center--xs g-margin-t-50--xs g-margin-b-80--xs">
<p class="text-uppercase g-font-size-14--xs g-font-weight--700 g-color--white-opacity g-letter-spacing--2 g-margin-b-25--xs">Editar Profissional de Saúde</p>
<h2 class="g-font-size-32--xs g-font-size-36--sm g-color--white">Dados Cadastrais</h2>
</div>

<form class="center-block g-width-500--sm g-width-550--md" method='POST' action=''>
{% csrf_token %}

<div class="row g-row-col-5 g-margin-b-50--xs">
<div class="col-sm-10 g-margin-b-30--xs g-margin-b-0--md">
{% for error in form.name.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{% extends template %} {% block content %} {% load staticfiles %} {% load static %}{% load i18n %}

<h4 class="g-font-size-14--xs g-font-size-14--sm g-color--white">Nome</h4>
{{ form.name }}
</div>

<div class="col-sm-2">
{% for error in form.sex.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{% csrf_token %}
<form class="post-form" action='' method="POST" enctype="multipart/form-data">
<div class="form-group">
{% csrf_token %}
<div class="row">
<div class = "col-md-12">
<font size="5">
<span class="label label-primary">{% trans "Nome" %}</span>
</font>
</div>
<div class = "col-md-12">
{% for error in form.name.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.name }}
</div>
</div>
<br>

<h4 class="g-font-size-14--xs g-font-size-14--sm g-color--white">Sexo</h4>
{{ form.sex }}
</div>
</div>
<div class="row">
<div class = "col-md-12">
<font size="5">
<span class="label label-primary">{% trans "Data de Nascimento" %}</span>
</font>
</div>
<div class = "col-md-12">
{% for error in form.date_of_birth.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.date_of_birth }}
</div>
</div>

<br>

<div class="row g-row-col-5 g-margin-b-50--xs">
<div class="col-sm-6 g-margin-b-30--xs g-margin-b-0--md">
{% for error in form.date_of_birth.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
<div class="row">
<div class = "col-md-12">
<font size="5">
<span class="label label-primary">{% trans "Telefone" %}</span>
</font>
</div>
<div class = "col-md-12">
{% for error in form.phone.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.phone }}
</div>
</div>

<h4 class="g-font-size-14--xs g-font-size-14--sm g-color--white">Data de Nascimento</h4>
{{ form.date_of_birth }}
</div>
<br>

<div class="col-sm-6">
{% for error in form.phone.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
<div class="row">
<div class = "col-md-12">
<font size="5">
<span class="label label-primary">{% trans "Sexo" %}</span>
</font>
</div>
<div class = "col-md-12">
{% for error in form.sex.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{{ form.sex }}
</div>
</div>

<h4 class="g-font-size-14--xs g-font-size-14--sm g-color--white">Telefone:</h4>
{{ form.phone }}
</div>
</div>
<br>

<div class="row g-row-col-5 g-margin-b-50--xs">
<div class="col-sm-6 g-margin-b-30--xs g-margin-b-0--md">
{% for error in form.password.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
<font size="5">
<span class="label label-primary">{% trans "Imagem de Perfil" %}</span>
</font>
{% for error in form.image_profile.errors %}
<div class="alert alert-danger" role="alert">{{ error }}</div>
{% endfor %}
{% if user.image_profile.name %}
<br><br>
<img src="/public/{{user.image_profile}}" width="100px" height="100px"></img>
<br>
{% endif %}
<br>

<h4 class="g-font-size-14--xs g-font-size-14--sm g-color--white">Senha</h4>
{{ form.password }}
</div>
</div>
{{ form.image_profile }}

<div class="g-text-center--xs">
<button value='Update' type="submit" class="text-uppercase s-btn s-btn--md s-btn--white-bg g-radius--50 g-padding-x-70--xs g-margin-b-20--xs">Editar</button>
</div>

</form>
</div>
</div>
<!-- End Form -->

{% endblock %}
<div class="col-sm-2 col-sm-push-5">
<button type="submit" class="btn btn-success">{% trans "Salvar" %}</button>
</div>
</div>
</form>
{% endblock %}
22 changes: 1 addition & 21 deletions medical_prescription/user/test/test_form_update_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
self.date_of_birth_invalid_MIN = '10/12/2022'

self.phone_valid = '(61)1234-56789'
self.phone_invalid = 'a1234567890a'
self.phone_invalid = 'a12345678'
self.phone_invalid_MAX = '12345678912312310111212345612345678'
self.phone_invalid_MIN = '12345'
self.phone_invalid_TYPE = '1a!2#4*'
Expand Down Expand Up @@ -71,7 +71,6 @@ def test_user_update_user_form_name_is_not_valid_MAX(self):
'date_of_birth': self.date_of_birth_invalid,
'phone': self.phone_valid,
'sex': self.sex_valid,
'password': self.password_valid,
}
form = UpdateUserForm(data=form_data, instance=self.user)
self.assertFalse(form.is_valid())
Expand Down Expand Up @@ -111,7 +110,6 @@ def test_user_update_user_form_phone_is_not_valid(self):
'date_of_birth': self.date_of_birth_valid,
'phone': self.phone_invalid,
'sex': self.sex_valid,
'password': self.password_valid,
}
form = UpdateUserForm(data=form_data, instance=self.user)
self.assertFalse(form.is_valid())
Expand Down Expand Up @@ -156,21 +154,3 @@ def test_user_update_user_form_sex_is_not_valid(self):
form = UpdateUserForm(data=form_data, instance=self.user)
self.assertFalse(form.is_valid())

def test_user_update_user_form_password_is_not_valid_MAX(self):
form_data = {'name': self.name_valid,
'date_of_birth': self.date_of_birth_valid,
'phone': self.phone_valid,
'sex': self.sex_valid,
'password': self.password_invalid_MAX,
}
form = UpdateUserForm(data=form_data, instance=self.user)
self.assertFalse(form.is_valid())

def test_user_update_user_form_password_is_not_valid_MIN(self):
form_data = {'name': self.name_valid,
'date_of_birth': self.date_of_birth_valid,
'phone': self.phone_valid,
'sex': self.sex_valid,
'password': self.password_invalid_MIN}
form = UpdateUserForm(data=form_data, instance=self.user)
self.assertFalse(form.is_valid())
2 changes: 2 additions & 0 deletions medical_prescription/user/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Local Django
from user.views import (ConfirmPasswordView,
DeleteHealthProfessional,
EditProfileView,
LogoutView,
LoginView,
RegisterPatientView,
Expand Down Expand Up @@ -35,6 +36,7 @@
url(r'^delete_health_professional/(?P<pk>[0-9]+)/$', DeleteHealthProfessional.as_view(), name='delete'),
url(r'^register_patient/(?P<activation_key>\w+)/$', RegisterPatientView.as_view(), name='register_patient'),
url(r'^view_patient/$', permission_required('is_staff')(ShowPatientsView.as_view()), name='view_patient'),
url(r'^edit_profile/$', EditProfileView.as_view(), name='edit_profile'),
url(r'^edit_patient/(?P<pk>[0-9]+)/$', UpdatePatient.as_view(), name='edit_patient'),
url(r'^confirm/(?P<activation_key>\w+)/$', ConfirmAccountView.activate_register_user, name='confirm_account'),
url(r'^editpasswordpatient/(?P<email>[\w|\W]+)/$', UpdateUserPassword.edit_patient_password_view, name='edit_patient_password'),
Expand Down
1 change: 1 addition & 0 deletions medical_prescription/user/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
from .updatepatient import UpdatePatient
from .showhealthprofessionalview import ShowHealthProfessionalView
from .updatepasswordview import UpdateUserPassword
from .editprofile import EditProfileView
34 changes: 34 additions & 0 deletions medical_prescription/user/views/editprofile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from django.views.generic.edit import UpdateView
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required

from user.models import User
from user.forms import UpdateUserForm


class EditProfileView(UpdateView):
model = User
form_class = UpdateUserForm
template_name = 'edit_health_professional.html'

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(EditProfileView, self).dispatch(*args, **kwargs)

def get_object(self):
return self.request.user

def get_context_data(self, **kwargs):
context = super(EditProfileView, self).get_context_data(**kwargs)
is_health_professional = hasattr(self.request.user, 'healthprofessional')
if is_health_professional:
template = "dashboardHealthProfessional/template.html"
else:
template = "dashboardPatient/template.html"

context['template'] = template
return context

def get_success_url(self):
return reverse_lazy('edit_profile')

0 comments on commit c214bf8

Please sign in to comment.