Browse Source

Fix #546

pull/788/head
LeandroRoberto 8 years ago
parent
commit
368de4c550
  1. 85
      sapl/compilacao/views.py
  2. 8
      sapl/templates/compilacao/dispositivo_form.html
  3. 2
      sapl/templates/compilacao/publicacao_list.html
  4. 2
      sapl/templates/compilacao/textoarticulado_list.html
  5. 5
      sapl/templates/compilacao/tipotextoarticulado_detail.html
  6. 2
      sapl/templates/compilacao/tipotextoarticulado_list.html
  7. 6
      sapl/urls.py

85
sapl/compilacao/views.py

@ -273,7 +273,14 @@ class IntegracaoTaView(TemplateView):
abstract = True abstract = True
class CompMixin: class CompMixin(PermissionRequiredMixin):
permission_required = []
def has_permission(self):
perms = self.get_permission_required()
# Torna a view pública se não possuir conteudo
# no atributo permission_required
return self.request.user.has_perms(perms) if len(perms) else True
@property @property
def ta(self): def ta(self):
@ -298,6 +305,7 @@ class TipoTaListView(CompMixin, ListView):
model = TipoTextoArticulado model = TipoTextoArticulado
paginate_by = 10 paginate_by = 10
verbose_name = model._meta.verbose_name verbose_name = model._meta.verbose_name
permission_required = 'compilacao.list_tipotextoarticulado'
@property @property
def title(self): def title(self):
@ -314,6 +322,7 @@ class TipoTaCreateView(CompMixin, FormMessagesMixin, CreateView):
template_name = "crud/form.html" template_name = "crud/form.html"
form_valid_message = _('Registro criado com sucesso!') form_valid_message = _('Registro criado com sucesso!')
form_invalid_message = _('O registro não foi criado.') form_invalid_message = _('O registro não foi criado.')
permission_required = 'compilacao.add_tipotextoarticulado'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = None self.object = None
@ -335,12 +344,14 @@ class TipoTaCreateView(CompMixin, FormMessagesMixin, CreateView):
class TipoTaDetailView(CompMixin, DetailView): class TipoTaDetailView(CompMixin, DetailView):
model = TipoTextoArticulado model = TipoTextoArticulado
permission_required = 'compilacao.detail_tipotextoarticulado'
class TipoTaUpdateView(CompMixin, UpdateView): class TipoTaUpdateView(CompMixin, UpdateView):
model = TipoTextoArticulado model = TipoTextoArticulado
form_class = TipoTaForm form_class = TipoTaForm
template_name = "crud/form.html" template_name = "crud/form.html"
permission_required = 'compilacao.change_tipotextoarticulado'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
@ -363,6 +374,7 @@ class TipoTaUpdateView(CompMixin, UpdateView):
class TipoTaDeleteView(CompMixin, DeleteView): class TipoTaDeleteView(CompMixin, DeleteView):
model = TipoTextoArticulado model = TipoTextoArticulado
template_name = "crud/confirm_delete.html" template_name = "crud/confirm_delete.html"
permission_required = 'compilacao.delete_tipotextoarticulado'
@property @property
def detail_url(self): def detail_url(self):
@ -377,6 +389,7 @@ class TaListView(CompMixin, ListView):
model = TextoArticulado model = TextoArticulado
paginate_by = 10 paginate_by = 10
verbose_name = model._meta.verbose_name verbose_name = model._meta.verbose_name
permission_required = 'compilacao.list_textoarticulado'
@property @property
def title(self): def title(self):
@ -416,6 +429,7 @@ class TaCreateView(CompMixin, FormMessagesMixin, CreateView):
template_name = "crud/form.html" template_name = "crud/form.html"
form_valid_message = _('Registro criado com sucesso!') form_valid_message = _('Registro criado com sucesso!')
form_invalid_message = _('O registro não foi criado.') form_invalid_message = _('O registro não foi criado.')
permission_required = 'compilacao.add_tipotextoarticulado'
def get_success_url(self): def get_success_url(self):
return reverse_lazy('sapl.compilacao:ta_detail', return reverse_lazy('sapl.compilacao:ta_detail',
@ -430,6 +444,7 @@ class TaUpdateView(CompMixin, UpdateView):
model = TextoArticulado model = TextoArticulado
form_class = TaForm form_class = TaForm
template_name = "crud/form.html" template_name = "crud/form.html"
permission_required = 'compilacao.change_textoarticulado'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
@ -452,6 +467,7 @@ class TaUpdateView(CompMixin, UpdateView):
class TaDeleteView(CompMixin, DeleteView): class TaDeleteView(CompMixin, DeleteView):
model = TextoArticulado model = TextoArticulado
template_name = "crud/confirm_delete.html" template_name = "crud/confirm_delete.html"
permission_required = 'compilacao.delete_textoarticulado'
@property @property
def detail_url(self): def detail_url(self):
@ -491,14 +507,11 @@ class NotaMixin(DispositivoSuccessUrlMixin):
return initial return initial
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(NotaMixin, self).dispatch(*args, **kwargs)
class NotasCreateView(NotaMixin, CreateView): class NotasCreateView(NotaMixin, CreateView):
template_name = 'compilacao/ajax_form.html' template_name = 'compilacao/ajax_form.html'
form_class = NotaForm form_class = NotaForm
permission_required = 'compilacao.add_nota'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
flag_action, modelo_nota = self.get_modelo_nota(request) flag_action, modelo_nota = self.get_modelo_nota(request)
@ -533,6 +546,7 @@ class NotasEditView(NotaMixin, UpdateView):
model = Nota model = Nota
template_name = 'compilacao/ajax_form.html' template_name = 'compilacao/ajax_form.html'
form_class = NotaForm form_class = NotaForm
permission_required = 'compilacao.change_nota'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
flag_action, modelo_nota = self.get_modelo_nota(request) flag_action, modelo_nota = self.get_modelo_nota(request)
@ -544,6 +558,8 @@ class NotasEditView(NotaMixin, UpdateView):
class NotasDeleteView(NotaMixin, TemplateView): class NotasDeleteView(NotaMixin, TemplateView):
permission_required = 'compilacao.delete_nota'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
nt = Nota.objects.get(pk=self.kwargs['pk']) nt = Nota.objects.get(pk=self.kwargs['pk'])
nt.delete() nt.delete()
@ -562,41 +578,28 @@ class VideMixin(DispositivoSuccessUrlMixin):
return initial return initial
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(VideMixin, self).dispatch(*args, **kwargs)
class VideCreateView(VideMixin, CreateView): class VideCreateView(VideMixin, CreateView):
model = Vide model = Vide
template_name = 'compilacao/ajax_form.html' template_name = 'compilacao/ajax_form.html'
form_class = VideForm form_class = VideForm
permission_required = 'compilacao.add_vide'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = None self.object = None
form = self.get_form() form = self.get_form()
return self.render_to_response(self.get_context_data(form=form)) return self.render_to_response(self.get_context_data(form=form))
"""
def get_form_kwargs(self):
kwargs = super(VideCreateView, self).get_form_kwargs()
if 'choice_model_type_foreignkey_in_extenal_views' not in kwargs:
kwargs.update({
'choice_model_type_foreignkey_in_extenal_views':
choice_model_type_foreignkey_in_extenal_views
})
return kwargs"""
class VideEditView(VideMixin, UpdateView): class VideEditView(VideMixin, UpdateView):
model = Vide model = Vide
template_name = 'compilacao/ajax_form.html' template_name = 'compilacao/ajax_form.html'
form_class = VideForm form_class = VideForm
permission_required = 'compilacao.change_vide'
class VideDeleteView(VideMixin, TemplateView): class VideDeleteView(VideMixin, TemplateView):
permission_required = 'compilacao.delete_vide'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
vd = Vide.objects.get(pk=self.kwargs['pk']) vd = Vide.objects.get(pk=self.kwargs['pk'])
@ -604,13 +607,7 @@ class VideDeleteView(VideMixin, TemplateView):
return HttpResponseRedirect(self.get_success_url()) return HttpResponseRedirect(self.get_success_url())
class PublicacaoMixin(PermissionRequiredMixin, CompMixin): class PublicacaoMixin(CompMixin):
def has_permission(self):
perms = self.get_permission_required()
# Torna a view pública se não possuir conteudo
# no atributo permission_required
return self.request.user.has_perms(perms) if len(perms) else True
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
ta = self.ta ta = self.ta
@ -659,7 +656,7 @@ class PublicacaoCreateView(PublicacaoMixin, FormMessagesMixin, CreateView):
template_name = "crud/form.html" template_name = "crud/form.html"
form_valid_message = _('Registro criado com sucesso!') form_valid_message = _('Registro criado com sucesso!')
form_invalid_message = _('O registro não foi criado.') form_invalid_message = _('O registro não foi criado.')
permission_required = 'add_publicacao', permission_required = 'compilacao.add_publicacao'
def get_success_url(self): def get_success_url(self):
return reverse_lazy( return reverse_lazy(
@ -680,14 +677,14 @@ class PublicacaoCreateView(PublicacaoMixin, FormMessagesMixin, CreateView):
class PublicacaoDetailView(PublicacaoMixin, DetailView): class PublicacaoDetailView(PublicacaoMixin, DetailView):
model = Publicacao model = Publicacao
permission_required = 'detail_publicacao' permission_required = 'compilacao.detail_publicacao'
class PublicacaoUpdateView(PublicacaoMixin, UpdateView): class PublicacaoUpdateView(PublicacaoMixin, UpdateView):
model = Publicacao model = Publicacao
form_class = PublicacaoForm form_class = PublicacaoForm
template_name = "crud/form.html" template_name = "crud/form.html"
permission_required = 'change_publicacao' permission_required = 'compilacao.change_publicacao'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
@ -711,7 +708,7 @@ class PublicacaoUpdateView(PublicacaoMixin, UpdateView):
class PublicacaoDeleteView(PublicacaoMixin, DeleteView): class PublicacaoDeleteView(PublicacaoMixin, DeleteView):
model = Publicacao model = Publicacao
template_name = "crud/confirm_delete.html" template_name = "crud/confirm_delete.html"
permission_required = 'delete_publicacao' permission_required = 'compilacao.delete_publicacao'
@property @property
def detail_url(self): def detail_url(self):
@ -740,9 +737,7 @@ class TextView(CompMixin, ListView):
ta_vigencia = None ta_vigencia = None
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
ta = TextoArticulado.objects.get(pk=self.kwargs['ta_id']) self.object = self.ta
self.object = ta
return super(TextView, self).get(request, *args, **kwargs) return super(TextView, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -934,8 +929,9 @@ class DispositivoView(TextView):
return itens return itens
class TextEditView(TemplateView): class TextEditView(CompMixin, TemplateView):
template_name = 'compilacao/text_edit.html' template_name = 'compilacao/text_edit.html'
permission_required = 'compilacao.change_dispositivo_edicao_dinamica'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
dispositivo_id = int(self.kwargs['dispositivo_id']) \ dispositivo_id = int(self.kwargs['dispositivo_id']) \
@ -944,7 +940,7 @@ class TextEditView(TemplateView):
if dispositivo_id: if dispositivo_id:
self.object = Dispositivo.objects.get(pk=dispositivo_id) self.object = Dispositivo.objects.get(pk=dispositivo_id)
context = super(TextEditView, self).get_context_data(**kwargs) context = super(TemplateView, self).get_context_data(**kwargs)
if not dispositivo_id: if not dispositivo_id:
ta = TextoArticulado.objects.get(pk=self.kwargs['ta_id']) ta = TextoArticulado.objects.get(pk=self.kwargs['ta_id'])
@ -2421,11 +2417,12 @@ class ActionsEditMixin(ActionDragAndMoveDispositivoAlteradoMixin,
class DispositivoDinamicEditView( class DispositivoDinamicEditView(
CompMixin, ActionsEditMixin, TextEditView, UpdateView): ActionsEditMixin, TextEditView, UpdateView):
template_name = 'compilacao/text_edit_bloco.html' template_name = 'compilacao/text_edit_bloco.html'
model = Dispositivo model = Dispositivo
form_class = DispositivoEdicaoBasicaForm form_class = DispositivoEdicaoBasicaForm
contador = -1 contador = -1
permission_required = 'compilacao.change_dispositivo_edicao_dinamica',
def get_initial(self): def get_initial(self):
initial = UpdateView.get_initial(self) initial = UpdateView.get_initial(self)
@ -2619,7 +2616,6 @@ class DispositivoSearchFragmentFormView(ListView):
def get_queryset(self): def get_queryset(self):
try: try:
n = 10 n = 10
if 'max_results' in self.request.GET: if 'max_results' in self.request.GET:
n = int(self.request.GET['max_results']) n = int(self.request.GET['max_results'])
@ -2803,6 +2799,8 @@ class DispositivoEdicaoBasicaView(CompMixin, FormMessagesMixin, UpdateView):
form_invalid_message = _('Houve erro em registrar ' form_invalid_message = _('Houve erro em registrar '
'as alterações no Dispositivo') 'as alterações no Dispositivo')
permission_required = 'compilacao.change_dispositivo_edicao_avancada'
@property @property
def cancel_url(self): def cancel_url(self):
return reverse_lazy( return reverse_lazy(
@ -2875,6 +2873,8 @@ class DispositivoEdicaoVigenciaView(CompMixin, FormMessagesMixin, UpdateView):
form_invalid_message = _('Houve erro em registrar ' form_invalid_message = _('Houve erro em registrar '
'as alterações no Dispositivo') 'as alterações no Dispositivo')
permission_required = 'compilacao.change_dispositivo_edicao_avancada'
@property @property
def cancel_url(self): def cancel_url(self):
return reverse_lazy( return reverse_lazy(
@ -2898,6 +2898,9 @@ class DispositivoDefinidorVigenciaView(CompMixin, FormMessagesMixin, FormView):
form_invalid_message = _('Houve erro em registrar ' form_invalid_message = _('Houve erro em registrar '
'as alterações no Dispositivo') 'as alterações no Dispositivo')
permission_required = ('compilacao.change_dispositivo_edicao_avancada',
'compilacao.change_dispositivo_de_vigencia_global')
def get_form_kwargs(self): def get_form_kwargs(self):
kwargs = FormView.get_form_kwargs(self) kwargs = FormView.get_form_kwargs(self)
kwargs.update({ kwargs.update({
@ -2955,6 +2958,8 @@ class DispositivoEdicaoAlteracaoView(CompMixin, FormMessagesMixin, UpdateView):
form_invalid_message = _('Houve erro em registrar ' form_invalid_message = _('Houve erro em registrar '
'as alterações no Dispositivo') 'as alterações no Dispositivo')
permission_required = 'compilacao.change_dispositivo_registros_compilacao'
@property @property
def cancel_url(self): def cancel_url(self):
return reverse_lazy( return reverse_lazy(
@ -2987,6 +2992,8 @@ class TextNotificacoesView(CompMixin, ListView, FormView):
template_name = 'compilacao/text_notificacoes.html' template_name = 'compilacao/text_notificacoes.html'
form_class = TextNotificacoesForm form_class = TextNotificacoesForm
permission_required = 'compilacao.view_dispositivo_notificacoes'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = TextoArticulado.objects.get(pk=self.kwargs['ta_id']) self.object = TextoArticulado.objects.get(pk=self.kwargs['ta_id'])
return super(TextNotificacoesView, self).get(request, *args, **kwargs) return super(TextNotificacoesView, self).get(request, *args, **kwargs)

8
sapl/templates/compilacao/dispositivo_form.html

@ -10,10 +10,10 @@
{% url 'sapl.compilacao:dispositivo_edit_vigencia' object.ta_id object.pk as edit_vigencia_url %} {% url 'sapl.compilacao:dispositivo_edit_vigencia' object.ta_id object.pk as edit_vigencia_url %}
{% url 'sapl.compilacao:dispositivo_edit_alteracao' object.ta_id object.pk as edit_alteracao_url %} {% url 'sapl.compilacao:dispositivo_edit_alteracao' object.ta_id object.pk as edit_alteracao_url %}
{% url 'sapl.compilacao:dispositivo_edit_definidor_vigencia' object.ta_id object.pk as edit_definidor_vigencia_url %} {% url 'sapl.compilacao:dispositivo_edit_definidor_vigencia' object.ta_id object.pk as edit_definidor_vigencia_url %}
<li {% if request.get_full_path == edit_url %}class="active"{%endif%}><a class="btn-warning" href="{{ edit_url }}">{% trans 'Dados Básicos' %}</a></li> {% if perms.compilacao.change_dispositivo_edicao_avancada %}<li {% if request.get_full_path == edit_url %}class="active"{%endif%}><a class="btn-warning" href="{{ edit_url }}">{% trans 'Dados Básicos' %}</a></li>{% endif %}
<li {% if request.get_full_path == edit_vigencia_url %}class="active"{%endif%}><a class="btn-warning" href="{{ edit_vigencia_url }}" >{% trans 'Vigência' %}</a></li> {% if perms.compilacao.change_dispositivo_edicao_avancada %}<li {% if request.get_full_path == edit_vigencia_url %}class="active"{%endif%}><a class="btn-warning" href="{{ edit_vigencia_url }}" >{% trans 'Vigência' %}</a></li>{% endif %}
<li {% if request.get_full_path == edit_definidor_vigencia_url %}class="active"{%endif%}><a class="btn-danger" href="{{ edit_definidor_vigencia_url }}" >{% trans 'Definidor de Vigência' %}</a></li> {% if perms.compilacao.change_dispositivo_de_vigencia_global %}<li {% if request.get_full_path == edit_definidor_vigencia_url %}class="active"{%endif%}><a class="btn-danger" href="{{ edit_definidor_vigencia_url }}" >{% trans 'Definidor de Vigência' %}</a></li>{% endif %}
<li {% if request.get_full_path == edit_alteracao_url %}class="active"{%endif%}><a class="btn-danger" href="{{ edit_alteracao_url }}" >{% trans 'Alteração' %}</a></li> {% if perms.compilacao.change_dispositivo_registros_compilacao %}<li {% if request.get_full_path == edit_alteracao_url %}class="active"{%endif%}><a class="btn-danger" href="{{ edit_alteracao_url }}" >{% trans 'Alteração' %}</a></li>{% endif %}
</ul> </ul>
{% endblock sections_nav %}{% trans '' %} {% endblock sections_nav %}{% trans '' %}

2
sapl/templates/compilacao/publicacao_list.html

@ -5,11 +5,13 @@
{% block base_content %} {% block base_content %}
{% if perms.compilacao.add_publicacao %}
<div class="actions btn-group pull-right" role="group"> <div class="actions btn-group pull-right" role="group">
<a href="{{ view.create_url }}" class="btn btn-default"> <a href="{{ view.create_url }}" class="btn btn-default">
{% trans 'Adicionar'%} {%model_verbose_name 'sapl.compilacao.models.Publicacao'%} {% trans 'Adicionar'%} {%model_verbose_name 'sapl.compilacao.models.Publicacao'%}
</a> </a>
</div> </div>
{% endif %}
{% if not object_list %} {% if not object_list %}
<p>{{ NO_ENTRIES_MSG }}</p> <p>{{ NO_ENTRIES_MSG }}</p>

2
sapl/templates/compilacao/textoarticulado_list.html

@ -8,12 +8,14 @@
{% endblock detail_content %} {% endblock detail_content %}
{% block actions %} {% block actions %}
{% if perms.compilacao.add_textoarticulado %}
<div class="actions btn-group pull-right clearfix" role="group"> <div class="actions btn-group pull-right clearfix" role="group">
<a href="{{ view.create_url }}" class="btn btn-default"> <a href="{{ view.create_url }}" class="btn btn-default">
{% trans 'Adicionar'%} {%model_verbose_name 'sapl.compilacao.models.TextoArticulado'%} {% trans 'Adicionar'%} {%model_verbose_name 'sapl.compilacao.models.TextoArticulado'%}
</a> </a>
{% include 'compilacao/textoarticulado_menu_config.html' %} {% include 'compilacao/textoarticulado_menu_config.html' %}
</div> </div>
{% endif %}
{% endblock actions %} {% endblock actions %}
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">

5
sapl/templates/compilacao/tipotextoarticulado_detail.html

@ -9,8 +9,9 @@
<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">
<a class="btn btn-default" href="{% url 'sapl.compilacao:tipo_ta_edit' object.pk %}">{% trans 'Editar' %}</a> {% if perms.compilacao.change_tipotextoarticulado %}<a class="btn btn-default" href="{% url 'sapl.compilacao:tipo_ta_edit' object.pk %}">{% trans 'Editar' %}</a>{% endif %}
<a class="btn btn-default" href="{% url 'sapl.compilacao:tipo_ta_delete' object.pk %}">{% trans 'Excluir' %}</a> {% if perms.compilacao.delete_tipotextoarticulado %}<a class="btn btn-default" href="{% url 'sapl.compilacao:tipo_ta_delete' object.pk %}">{% trans 'Excluir' %}</a>{% endif %}
</div> </div>
{% endblock actions %} {% endblock actions %}
</div> </div>

2
sapl/templates/compilacao/tipotextoarticulado_list.html

@ -5,11 +5,13 @@
{% block base_content %} {% block base_content %}
{% block actions %} {% block actions %}
{% if perms.compilacao.add_tipotextoarticulado %}
<div class="actions btn-group pull-right" role="group"> <div class="actions btn-group pull-right" role="group">
<a href="{{ view.create_url }}" class="btn btn-default"> <a href="{{ view.create_url }}" class="btn btn-default">
{% trans 'Adicionar'%} {%model_verbose_name 'sapl.compilacao.models.TipoTextoArticulado'%} {% trans 'Adicionar'%} {%model_verbose_name 'sapl.compilacao.models.TipoTextoArticulado'%}
</a> </a>
</div> </div>
{% endif %}
{% endblock actions %} {% endblock actions %}
{% if not object_list %} {% if not object_list %}

6
sapl/urls.py

@ -17,7 +17,7 @@ from django.conf import settings
from django.conf.urls import include, url from django.conf.urls import include, url
from django.conf.urls.static import static from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView, RedirectView
from django.views.static import serve as view_static_server from django.views.static import serve as view_static_server
import sapl.api.urls import sapl.api.urls
@ -33,6 +33,7 @@ import sapl.protocoloadm.urls
import sapl.relatorios.urls import sapl.relatorios.urls
import sapl.sessao.urls import sapl.sessao.urls
urlpatterns = [ urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='index.html')), url(r'^$', TemplateView.as_view(template_name='index.html')),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
@ -53,6 +54,9 @@ urlpatterns = [
url(r'', include(sapl.base.urls)), url(r'', include(sapl.base.urls)),
url(r'', include(sapl.api.urls)), url(r'', include(sapl.api.urls)),
url(r'^favicon\.ico$', RedirectView.as_view(
url='/static/img/favicon.ico', permanent=True)),
] ]

Loading…
Cancel
Save