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

12
sapl/templates/compilacao/publicacao_list.html

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

14
sapl/templates/compilacao/textoarticulado_list.html

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

5
sapl/templates/compilacao/tipotextoarticulado_detail.html

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

12
sapl/templates/compilacao/tipotextoarticulado_list.html

@ -5,11 +5,13 @@
{% block base_content %}
{% block actions %}
<div class="actions btn-group pull-right" role="group">
<a href="{{ view.create_url }}" class="btn btn-default">
{% trans 'Adicionar'%} {%model_verbose_name 'sapl.compilacao.models.TipoTextoArticulado'%}
</a>
</div>
{% if perms.compilacao.add_tipotextoarticulado %}
<div class="actions btn-group pull-right" role="group">
<a href="{{ view.create_url }}" class="btn btn-default">
{% trans 'Adicionar'%} {%model_verbose_name 'sapl.compilacao.models.TipoTextoArticulado'%}
</a>
</div>
{% endif %}
{% endblock actions %}
{% 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.static import static
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
import sapl.api.urls
@ -33,6 +33,7 @@ import sapl.protocoloadm.urls
import sapl.relatorios.urls
import sapl.sessao.urls
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='index.html')),
url(r'^admin/', include(admin.site.urls)),
@ -53,6 +54,9 @@ urlpatterns = [
url(r'', include(sapl.base.urls)),
url(r'', include(sapl.api.urls)),
url(r'^favicon\.ico$', RedirectView.as_view(
url='/static/img/favicon.ico', permanent=True)),
]

Loading…
Cancel
Save