Browse Source

Cria logica para esconder os botoes quando o usuario nao tem a permissao

pull/506/head
Eduardo Calil 9 years ago
parent
commit
eaa5ff8da4
  1. 44
      sapl/base/templatetags/common_tags.py
  2. 10
      sapl/templates/crud/detail.html
  3. 15
      sapl/templates/crud/list.html
  4. 20
      sapl/templates/materia/proposicao_detail.html
  5. 6
      sapl/templates/norma/list_pesquisa.html
  6. 5
      sapl/templates/norma/pesquisa.html
  7. 11
      sapl/templates/sessao/materia_ordemdia_list.html

44
sapl/base/templatetags/common_tags.py

@ -36,3 +36,47 @@ def lookup(d, key):
def isinst(value, class_str):
classe = value.__class__.__name__
return classe == class_str
@register.filter
def to_class_name(value):
return value.__class__.__name__.lower()
@register.filter
def get_add_perm(value, arg):
perm = value
view = arg
nome_app = view.__class__.model._meta.app_label
nome_model = view.__class__.model.__name__.lower()
can_add = '.add_' + nome_model
return perm.__contains__(nome_app + can_add)
@register.filter
def get_change_perm(value, arg):
perm = value
view = arg
nome_app = view.__class__.model._meta.app_label
nome_model = view.__class__.model.__name__.lower()
can_change = '.change_' + nome_model
return perm.__contains__(nome_app + can_change)
@register.filter
def get_delete_perm(value, arg):
perm = value
view = arg
nome_app = view.__class__.model._meta.app_label
nome_model = view.__class__.model.__name__.lower()
can_delete = '.delete_' + nome_model
return perm.__contains__(nome_app + can_delete)
# view.__class__.model._meta.app_label -> nome do app
# context.getcontext.get('view').__class__.model.__name__.lower() -> nome do model

10
sapl/templates/crud/detail.html

@ -1,13 +1,19 @@
{% extends "base.html" %}
{% load i18n %}
{% load common_tags %}
{% block base_content %}
<div class="clearfix">
{% block actions %}
<div class="actions btn-group pull-right" role="group">
<a href="{{ view.update_url }}" class="btn btn-default">{% trans 'Editar' %}</a>
<a href="{{ view.delete_url }}" class="btn btn-default">{% trans 'Excluir' %}</a>
{% if perms|get_change_perm:view %}
<a href="{{ view.update_url }}" class="btn btn-default">{% trans 'Editar' %}</a>
{% endif %}
{% if perms|get_delete_perm:view %}
<a href="{{ view.delete_url }}" class="btn btn-default">{% trans 'Excluir' %}</a>
{% endif %}
</div>
{% endblock actions %}
</div>

15
sapl/templates/crud/list.html

@ -1,14 +1,17 @@
{% extends "base.html" %}
{% load i18n %}
{% load common_tags %}
{% block base_content %}
<div class="actions btn-group pull-right" role="group">
<a href="{{ view.create_url }}" class="btn btn-default">
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %}
</a>
{% block more_buttons %}{% endblock more_buttons %}
</div>
<div class="actions btn-group pull-right" role="group">
{% if perms|get_add_perm:view %}
<a href="{{ view.create_url }}" class="btn btn-default">
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %}
</a>
{% endif %}
{% block more_buttons %}{% endblock more_buttons %}
</div>
<br/><br/>
{% block extra_content %} {% endblock %}

20
sapl/templates/materia/proposicao_detail.html

@ -1,14 +1,26 @@
{% extends "crud/detail.html" %}
{% load i18n %}
{% load common_tags %}
{% block actions %}
<div class="actions btn-group pull-right" role="group">
{% if proposicao.data_envio %}
<a href="{{ view.update_url }}" class="btn btn-default">{% trans 'Editar Proposição' %}</a>
<a href="{{ view.delete_url }}" class="btn btn-default">{% trans 'Retornar Proposição Enviada' %}</a>
{% if perms|get_change_perm:view %}
<a href="{{ view.update_url }}" class="btn btn-default">{% trans 'Editar Proposição' %}</a>
{% endif %}
{% if perms|get_delete_perm:view %}
<a href="{{ view.delete_url }}" class="btn btn-default">{% trans 'Retornar Proposição Enviada' %}</a>
{% endif %}
{% else %}
<a href="{{ view.update_url }}" class="btn btn-default">{% trans 'Enviar/Editar Proposição' %}</a>
<a href="{{ view.delete_url }}" class="btn btn-default">{% trans 'Excluir Proposição' %}</a>
{% if perms|get_change_perm:view %}
<a href="{{ view.update_url }}" class="btn btn-default">{% trans 'Enviar/Editar Proposição' %}</a>
{% endif %}
{% if perms|get_delete_perm:view %}
<a href="{{ view.delete_url }}" class="btn btn-default">{% trans 'Excluir Proposição' %}</a>
{% endif %}
{% endif %}
</div>
{% endblock actions %}

6
sapl/templates/norma/list_pesquisa.html

@ -1,10 +1,14 @@
{% extends "crud/detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load common_tags %}
{% block actions %}{% endblock %}
{% block detail_content %}
<div class="actions btn-group pull-right" role="group">
<a href="{% url 'sapl.norma:normajuridica_create' %}" class="btn btn-default">Adicionar Norma Jurídica</a>
{% if perms.norma.add_normajuridica %}
<a href="{% url 'sapl.norma:normajuridica_create' %}" class="btn btn-default">Adicionar Norma Jurídica</a>
{% endif %}
</div>
<br /><br /><br />
{% if object_list %}

5
sapl/templates/norma/pesquisa.html

@ -1,12 +1,15 @@
{% extends "crud/detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load common_tags %}
{% block base_content %}
{% block actions %}
<div class="actions btn-group pull-right" role="group">
<a href="{% url 'sapl.norma:normajuridica_create' %}" class="btn btn-default">{% trans 'Adicionar Norma Juridica' %}</a>
{% if perms.norma.add_normajuridica %}
<a href="{% url 'sapl.norma:normajuridica_create' %}" class="btn btn-default">{% trans 'Adicionar Norma Juridica' %}</a>
{% endif %}
</div>
<br /><br />
{% endblock %}

11
sapl/templates/sessao/materia_ordemdia_list.html

@ -1,5 +1,6 @@
{% extends "crud/detail.html" %}
{% load i18n %}
{% load common_tags %}
{% block detail_content %}
@ -74,11 +75,15 @@ Matérias da Ordem do Dia
<form method="POST" action="{% url 'sapl.sessao:materiaordemdia_list' object.pk %}">
{% csrf_token %}
<input type="hidden" name="error_message" id="error_message" />
<a href="{% url 'sapl.sessao:materiaordemdia_create' object.pk %}" class="btn btn-primary">{% trans 'Adicionar Matérias' %}</a>
&nbsp;&nbsp;&nbsp;
{% if perms|get_add_perm:view %}
<a href="{% url 'sapl.sessao:materiaordemdia_create' object.pk %}" class="btn btn-primary">{% trans 'Adicionar Matérias' %}</a>
&nbsp;&nbsp;&nbsp;
{% endif %}
<input type="submit" id="materia_reorder" name="materia_reorder" value="Reordenar Matérias da Ordem do Dia" class="btn btn-primary" />
&nbsp;&nbsp;&nbsp;
<input type="submit" id="incluir_varias" name="incluir_varias" value="Incluir Várias Matérias" class="btn btn-primary" />
{% if perms|get_add_perm:view %}
<input type="submit" id="incluir_varias" name="incluir_varias" value="Incluir Várias Matérias" class="btn btn-primary" />
{% endif %}
</form>
{% endblock detail_content %}

Loading…
Cancel
Save