From 604345d32c3ccff510a565bd30d3477ad30ed871 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Fri, 27 Nov 2015 17:18:19 -0200 Subject: [PATCH] add norma_temporario_crud --- compilacao/forms.py | 41 ++++++++++++++++++--------- compilacao/urls.py | 2 +- compilacao/views.py | 23 ++++++++++++--- norma/models.py | 5 ++-- norma/urls.py | 15 +++++++--- norma/views.py | 12 ++++---- static/js/compilacao_notas.js | 19 +++++++++++-- static/styles/compilacao.scss | 17 +++++++++-- templates/compilacao/edit_bloco.html | 1 - templates/compilacao/index_bloco.html | 18 +++++++----- 10 files changed, 109 insertions(+), 44 deletions(-) diff --git a/compilacao/forms.py b/compilacao/forms.py index 3842bf340..f47cebf0b 100644 --- a/compilacao/forms.py +++ b/compilacao/forms.py @@ -36,11 +36,19 @@ class NotaForm(ModelForm): # All users have visibility. (NPUBL, _('Nota Pública')), ) - + error_messages = { + 'required': _('Este campo é obrigatório'), + 'invalid': _('URL inválida.') + } titulo = forms.CharField(label=' ', required=False) - texto = forms.CharField(label='', widget=forms.Textarea) - url_externa = forms.URLField(label='', required=False) - + texto = forms.CharField( + label='', + widget=forms.Textarea, + error_messages=error_messages) + url_externa = forms.URLField( + label='', + required=False, + error_messages=error_messages) publicidade = forms.ChoiceField( required=True, label='Publicidade', @@ -53,16 +61,21 @@ class NotaForm(ModelForm): queryset=TipoNota.objects.all(), empty_label=None) - publicacao = forms.DateField(label=u'Publicação', - input_formats=['%d/%m/%Y'], - required=True, - widget=forms.DateInput( - format='%d/%m/%Y')) - efetividade = forms.DateField(label=u'Efetividade', - input_formats=['%d/%m/%Y'], - required=True, - widget=forms.DateInput( - format='%d/%m/%Y')) + publicacao = forms.DateField( + label=u'Publicação', + input_formats=['%d/%m/%Y'], + required=True, + widget=forms.DateInput( + format='%d/%m/%Y'), + error_messages=error_messages + ) + efetividade = forms.DateField( + label=u'Efetividade', + input_formats=['%d/%m/%Y'], + required=True, + widget=forms.DateInput( + format='%d/%m/%Y'), + error_messages=error_messages) dispositivo = forms.ModelChoiceField(queryset=Dispositivo.objects.all(), widget=forms.HiddenInput()) pk = forms.IntegerField(widget=forms.HiddenInput(), diff --git a/compilacao/urls.py b/compilacao/urls.py index 7a3c2b012..75089ab82 100644 --- a/compilacao/urls.py +++ b/compilacao/urls.py @@ -31,7 +31,7 @@ urlpatterns_compilacao = [ views.NotasEditView.as_view(), name='nota_edit'), url(r'^(?P[0-9]+)/compilacao/' - '(?P[0-9]+)/nota/delete$', + '(?P[0-9]+)/nota/(?P[0-9]+)/delete$', views.NotasDeleteView.as_view(), name='nota_delete'), ] diff --git a/compilacao/views.py b/compilacao/views.py index 2ab02e82b..3e8b09898 100644 --- a/compilacao/views.py +++ b/compilacao/views.py @@ -6,12 +6,14 @@ from django.contrib.auth.models import User from django.core.signing import Signer from django.core.urlresolvers import reverse from django.db.models import Q -from django.http.response import JsonResponse, HttpResponse +from django.http.response import JsonResponse, HttpResponse,\ + HttpResponseRedirect from django.shortcuts import render from django.utils.dateparse import parse_date from django.utils.translation import ugettext_lazy as _ from django.views.generic.base import TemplateView -from django.views.generic.edit import FormMixin, UpdateView +from django.views.generic.detail import SingleObjectMixin +from django.views.generic.edit import FormMixin, UpdateView, DeleteView from django.views.generic.list import ListView from vanilla.model_views import CreateView @@ -1160,5 +1162,18 @@ class NotasEditView(UpdateView): 'dispositivo_id']}) -class NotasDeleteView(FormMixin, CreateView): - pass +class NotasDeleteView(TemplateView): + + def get(self, request, *args, **kwargs): + nt = Nota.objects.get(pk=self.kwargs['pk']) + success_url = self.get_success_url() + nt.delete() + return HttpResponseRedirect(success_url) + + def get_success_url(self): + return reverse( + 'dispositivo', kwargs={ + 'norma_id': self.kwargs[ + 'norma_id'], + 'dispositivo_id': self.kwargs[ + 'dispositivo_id']}) diff --git a/norma/models.py b/norma/models.py index 265ad129d..875687f1b 100644 --- a/norma/models.py +++ b/norma/models.py @@ -3,7 +3,7 @@ from django.template import defaultfilters from django.utils.translation import ugettext_lazy as _ from materia.models import MateriaLegislativa -from sapl.utils import make_choices +from sapl.utils import make_choices, YES_NO_CHOICES class AssuntoNorma(models.Model): @@ -86,7 +86,8 @@ class NormaJuridica(models.Model): observacao = models.TextField( blank=True, null=True, verbose_name=_('Observação')) complemento = models.NullBooleanField( - blank=True, verbose_name=_('Complementar ?')) + blank=True, verbose_name=_('Complementar ?'), + choices=YES_NO_CHOICES) # XXX was a CharField (attention on migrate) assuntos = models.ManyToManyField( AssuntoNorma, diff --git a/norma/urls.py b/norma/urls.py index 69199c2c3..5e55c8713 100644 --- a/norma/urls.py +++ b/norma/urls.py @@ -1,12 +1,19 @@ from django.conf.urls import include, url -from norma.views import NormaIncluirView, assunto_norma_crud, tipo_norma_crud +from norma.views import NormaIncluirView, assunto_norma_crud, tipo_norma_crud,\ + norma_temporario_crud + +norma_url_patterns = norma_temporario_crud.urlpatterns + [] +# norma_url_patterns = norma_crud.urlpatterns + [] urlpatterns = [ - # url(r'^norma/', include(norma_url_patterns, - # norma_temporario_para_compilacao_crud.namespace, - # norma_temporario_para_compilacao_crud.namespace)), + url(r'^norma/', include(norma_url_patterns, + norma_temporario_crud.namespace, + norma_temporario_crud.namespace)), + + url(r'^sistema/norma/tipo/', include(tipo_norma_crud.urls)), url(r'^sistema/norma/assunto/', include(assunto_norma_crud.urls)), + url(r'^norma/incluir', NormaIncluirView.as_view(), name='norma-incluir'), ] diff --git a/norma/views.py b/norma/views.py index 9304f0cc7..00d2598f0 100644 --- a/norma/views.py +++ b/norma/views.py @@ -30,6 +30,7 @@ tipo_norma_crud = build_crud( ]) norma_crud = build_crud( + NormaJuridica, '', [ [_('Identificação Básica'), @@ -47,19 +48,18 @@ norma_crud = build_crud( [('indexacao', 12)], [('observacao', 12)]], - [_('Assuntos (Classificação) [+] '), + [_('Assuntos (Classificação) [+]'), + [('assunto_norma_FIXME', 12)], [('assunto_norma_FIXME', 12)], [('assunto_norma_FIXME', 12)]], ]) -norma_temporario_para_compilacao_crud = build_crud( - NormaJuridica, 'norma', [ +norma_temporario_crud = build_crud( + NormaJuridica, 'normajuridica', [ [_('Identificação Básica'), - [('tipo', 4), ('numero', 4), ('ano', 4)], - [('data', 4), ('esfera_federacao', 4)], - [('data_publicacao', 3)], + [('tipo', 5), ('numero', 2), ('ano', 2), ('data', 3)], [('ementa', 12)]], ]) diff --git a/static/js/compilacao_notas.js b/static/js/compilacao_notas.js index 8688272c0..c31b2873b 100644 --- a/static/js/compilacao_notas.js +++ b/static/js/compilacao_notas.js @@ -50,6 +50,18 @@ var onSubmitEditForm = function(event) { } ); } +var onDelete = function(event) { + + var id_dispositivo = $(event).closest('.dn').attr('pk'); + var id_nota = $(event).attr('pk'); + var url = 'compilacao/'+id_dispositivo+'/nota/'+id_nota+'/delete' + + $.get( url, function(data) { + $('#dne'+id_dispositivo+' .dne-form').closest('.dpt').html(data) + onReadyNotas(); + } + ); +} function getFormNota(_this, _btn) { var id_dispositivo = $('.dne-exec .dne-form').closest('.dne').attr('pk'); @@ -63,13 +75,12 @@ function getFormNota(_this, _btn) { id_dispositivo = $(_this).attr('pk'); url = 'compilacao/'+id_dispositivo+'/nota/create'; } - else { + else if (_btn == 'btn-edit') { var id_nota = $(_this).attr('pk'); id_dispositivo = $(_this).closest('.dn').attr('pk'); url = 'compilacao/'+id_dispositivo+'/nota/'+id_nota+'/edit' } $('#dne'+id_dispositivo).addClass('dne-exec'); - $('#dne'+id_dispositivo).addClass('dne-exec'); $.get(url).done(function( data ) { $('#dne'+id_dispositivo+' .dne-form').html(data); @@ -79,12 +90,16 @@ function getFormNota(_this, _btn) { function onReadyNotas() { $('.dne .btn-create').off(); $('.dne .btn-edit').off(); + $('.dne .btn-delete').off(); $('.dne .btn-create').click(function(){ getFormNota(this, 'btn-create') }); $('.dn .btn-edit').click(function(){ getFormNota(this, 'btn-edit') }); + $('.dn .btn-delete').click(function(){ + onDelete(this, 'btn-delete') + }); } $(document).ready(function() { onReadyNotas() diff --git a/static/styles/compilacao.scss b/static/styles/compilacao.scss index fbd590873..923c01d95 100644 --- a/static/styles/compilacao.scss +++ b/static/styles/compilacao.scss @@ -209,7 +209,7 @@ $color_actions_border: #CCC; font-size: 1.15em; float:left; .dptt { - z-index: 98; + z-index: 89; position: relative; } } @@ -273,6 +273,7 @@ $color_actions_border: #CCC; font-weight: normal; line-height: 1rem; position: relative; + text-decoration: none; p, ul { font-size: 0.8rem; font-weight: normal; @@ -299,8 +300,6 @@ $color_actions_border: #CCC; padding: 0.5em 0.5em 0em 0.5em; border: 1px solid #c7e3d3; border-top: 0px; - - } &:hover { @@ -323,15 +322,25 @@ $color_actions_border: #CCC; &:hover { color: #787; + a{ + color: #27AE60 !important; + } } + } .ntitulo { font-weight: bold; color: #676; font-size: 90%; + a{ + color: #294 !important; + } } .ntexto { color: #787; + a{ + color: #294 !important; + } } .nowner { color: #27AE60; @@ -342,6 +351,7 @@ $color_actions_border: #CCC; .dptt { .dne { + text-decoration: none; position: relative; display: block; font-size: 0.8rem; @@ -356,6 +366,7 @@ $color_actions_border: #CCC; font-size: 0.8rem; font-weight: normal; line-height: 1rem; + text-decoration: none; } ul.btns-action { diff --git a/templates/compilacao/edit_bloco.html b/templates/compilacao/edit_bloco.html index 4da277ed6..27348e7c9 100644 --- a/templates/compilacao/edit_bloco.html +++ b/templates/compilacao/edit_bloco.html @@ -35,7 +35,6 @@
    diff --git a/templates/compilacao/index_bloco.html b/templates/compilacao/index_bloco.html index 65d7cd202..a1ee1adb3 100644 --- a/templates/compilacao/index_bloco.html +++ b/templates/compilacao/index_bloco.html @@ -46,7 +46,6 @@
  • Excluir
  • {# TODO: User - tratar permissão usuário #}
  • -
  • {{nota.tipo.nome}}
  • {%if nota.owner.first_name%}{{nota.owner.first_name}}{%else%}{{nota.owner}}{%endif%}
  • @@ -54,14 +53,19 @@
  • {{nota.publicacao|date:"d M Y"}}
+ {%if nota.titulo %} +
+ {%if nota.url_externa %}{%endif%} + {{nota.titulo}} + {%if nota.url_externa %}{%endif%} +
+ {%endif%} +
{%if nota.url_externa %}{%endif%} - {%if nota.titulo %}
{{nota.titulo}}
{%endif%} - {%if nota.url_externa %}
{%endif%} - - {%if nota.url_externa %}{%endif%} -
{{ nota.texto}}
- {%if nota.url_externa %}
{%endif%} + {{ nota.texto}} + {%if nota.url_externa %}{%endif%} +
{%comment%}