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. 6
      sapl/templates/crud/detail.html
  3. 7
      sapl/templates/crud/list.html
  4. 12
      sapl/templates/materia/proposicao_detail.html
  5. 4
      sapl/templates/norma/list_pesquisa.html
  6. 3
      sapl/templates/norma/pesquisa.html
  7. 5
      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): def isinst(value, class_str):
classe = value.__class__.__name__ classe = value.__class__.__name__
return classe == class_str 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

6
sapl/templates/crud/detail.html

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

7
sapl/templates/crud/list.html

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

12
sapl/templates/materia/proposicao_detail.html

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

4
sapl/templates/norma/list_pesquisa.html

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

3
sapl/templates/norma/pesquisa.html

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

5
sapl/templates/sessao/materia_ordemdia_list.html

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

Loading…
Cancel
Save