From f9addcc96465d8eed404d265ace7752bd932a65f Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 16 Aug 2016 14:41:43 -0300 Subject: [PATCH] =?UTF-8?q?Restringe=20informa=C3=A7=C3=B5es=20do=20detail?= =?UTF-8?q?=20de=20parlamentar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/templatetags/common_tags.py | 12 +++ sapl/parlamentares/views.py | 25 +++++- .../parlamentar_perfil_publico.html | 84 +++++++++++++++++++ sapl/utils.py | 1 - 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 sapl/templates/parlamentares/parlamentar_perfil_publico.html diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py index ed1da8633..f89d6375e 100644 --- a/sapl/base/templatetags/common_tags.py +++ b/sapl/base/templatetags/common_tags.py @@ -1,6 +1,8 @@ from compressor.utils import get_class from django import template +from sapl.parlamentares.models import Filiacao + register = template.Library() @@ -81,3 +83,13 @@ def ver_menu_sistema_perm(value): return True else: return False + + +@register.filter +def ultima_filiacao(value): + parlamentar = value + + ultima_filiacao = Filiacao.objects.filter( + parlamentar=parlamentar).order_by('-data').first() + + return ultima_filiacao.partido diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 227bb1d38..4f9bd3d0e 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -2,6 +2,7 @@ from django.contrib import messages from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType +from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse_lazy from django.shortcuts import redirect from django.utils.datastructures import MultiValueDictKeyError @@ -9,7 +10,8 @@ from django.utils.translation import ugettext_lazy as _ from django.views.generic import FormView from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, - CrudDeleteView, CrudListView, CrudUpdateView) + CrudDeleteView, CrudDetailView, + CrudListView, CrudUpdateView) from sapl.crud.masterdetail import MasterDetailCrud from sapl.utils import permissao_tb_aux, permissoes_parlamentares @@ -191,10 +193,31 @@ class FiliacaoCrud(MasterDetailCrud): ordering = '-data' +def get_parlamentar_permissions(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='parlamentares') + perms_parlamentares = list(Permission.objects.filter( + content_type__in=cts)) + for p in perms_parlamentares: + lista_permissoes.append('parlamentares.' + p.codename) + return set(lista_permissoes) + + class ParlamentarCrud(Crud): model = Parlamentar help_path = '' + class DetailView(CrudDetailView): + def get_template_names(self): + usuario = self.request.user + lista_permissoes = get_parlamentar_permissions() + + if usuario.has_perms(lista_permissoes): + return ['crud/detail.html'] + + else: + return ['parlamentares/parlamentar_perfil_publico.html'] + class UpdateView(PermissionRequiredMixin, CrudUpdateView): form_class = ParlamentarForm permission_required = permissoes_parlamentares() diff --git a/sapl/templates/parlamentares/parlamentar_perfil_publico.html b/sapl/templates/parlamentares/parlamentar_perfil_publico.html new file mode 100644 index 000000000..b60c3e0d5 --- /dev/null +++ b/sapl/templates/parlamentares/parlamentar_perfil_publico.html @@ -0,0 +1,84 @@ +{% extends "base.html" %} +{% load i18n %} +{% load common_tags %} + +{% block base_content %} + +
+ {% block actions %} + {% endblock actions %} +
+ + {% block detail_content %} +

+ +
+
+
+
+ +
+
+
+ +
+
+

Nome Completo:   {{object.nome_completo}}

+
+
+ +
+
+

Partido:   {{object|ultima_filiacao|default_if_none:"Não informado"}}

+
+
+ +
+
+

Data de Nascimento:   {{object.data_nascimento|default_if_none:"Não informado"}}

+
+
+ +
+
+

Telefone:   {{object.telefone|default_if_none:"Não informado"}}

+
+
+ +
+
+

E-mail:   {{object.email|default_if_none:"Não informado"}}

+
+
+ +
+
+

Número do Gabinete:   {{object.numero_gab_parlamentar|default_if_none:"Não informado"}}

+
+
+ +
+
+

Fax:   {{object.numero_gab_parlamentar|default_if_none:"Não informado"}}

+
+
+ + +
+ + + + {% endblock detail_content %} + +{% endblock base_content %} diff --git a/sapl/utils.py b/sapl/utils.py index 5b1bee282..31de52e62 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -203,7 +203,6 @@ def fabrica_validador_de_tipos_de_arquivo(lista, nome): def restringe_tipos_de_arquivo(value): mime = magic.from_buffer(value.read(), mime=True) - mime = mime.decode() if mime not in lista: raise ValidationError(_('Tipo de arquivo não suportado')) # o nome é importante para as migrations