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 %} + +
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"}}
+