diff --git a/compilacao/forms.py b/compilacao/forms.py index e7c27e8ca..e765b28d2 100644 --- a/compilacao/forms.py +++ b/compilacao/forms.py @@ -1,5 +1,3 @@ -import sys - from crispy_forms.helper import FormHelper from crispy_forms_foundation.layout import (HTML, Column, Div, Fieldset, Layout, Row) @@ -10,10 +8,10 @@ from django.core.exceptions import NON_FIELD_ERRORS from django.forms.models import ModelForm from django.utils.translation import ugettext_lazy as _ -from compilacao.models import (Dispositivo, Nota, TextoArticulado, TipoNota, - TipoTextoArticulado, TipoVide, Vide, - PARTICIPACAO_SOCIAL_CHOICES) -from compilacao.utils import to_column, to_row, FormLayout +from compilacao.models import (PARTICIPACAO_SOCIAL_CHOICES, Dispositivo, Nota, + TextoArticulado, TipoNota, TipoTextoArticulado, + TipoVide, Vide) +from compilacao.utils import YES_NO_CHOICES, FormLayout, to_column, to_row class UpLoadImportFileForm(forms.Form): @@ -31,6 +29,39 @@ ta_error_messages = { } +class TipoTaForm(ModelForm): + sigla = forms.CharField(label='Sigla') + descricao = forms.CharField(label='Descrição') + + participacao_social = forms.NullBooleanField( + label=_('Participação Social'), + widget=forms.Select(choices=YES_NO_CHOICES), + required=True) + + class Meta: + model = TipoTextoArticulado + fields = ['sigla', + 'descricao', + 'content_type', + 'participacao_social', + ] + + def __init__(self, *args, **kwargs): + + row1 = to_row([ + ('sigla', 2), + ('descricao', 4), + ('content_type', 3), + ('participacao_social', 3), + ]) + + self.helper = FormHelper() + self.helper.layout = FormLayout( + Fieldset(_('Identificação Básica'), + row1, css_class="large-12")) + super(TipoTaForm, self).__init__(*args, **kwargs) + + class TaForm(ModelForm): tipo_ta = forms.ModelChoiceField( label=_('Tipo do Texto Articulado'), diff --git a/compilacao/migrations/0040_auto_20160106_1956.py b/compilacao/migrations/0040_auto_20160106_1956.py new file mode 100644 index 000000000..e621839d6 --- /dev/null +++ b/compilacao/migrations/0040_auto_20160106_1956.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('compilacao', '0039_auto_20151226_1433'), + ] + + operations = [ + migrations.RemoveField( + model_name='tipotextoarticulado', + name='model', + ), + migrations.AddField( + model_name='tipotextoarticulado', + name='content_type', + field=models.ForeignKey(verbose_name='Modelo Integrado', blank=True, default=None, null=True, to='contenttypes.ContentType'), + ), + ] diff --git a/compilacao/models.py b/compilacao/models.py index 70cb373fd..be6d0dfdd 100644 --- a/compilacao/models.py +++ b/compilacao/models.py @@ -63,12 +63,10 @@ class BaseModel(models.Model): class TipoTextoArticulado(models.Model): sigla = models.CharField(max_length=3, verbose_name=_('Sigla')) descricao = models.CharField(max_length=50, verbose_name=_('Descrição')) - model = models.CharField( - default='', - blank=True, null=True, - max_length=50, - unique=True, - verbose_name=_('Modelagem Django')) + content_type = models.ForeignKey( + ContentType, + blank=True, null=True, default=None, + verbose_name=_('Modelo Integrado')) participacao_social = models.NullBooleanField( default=False, blank=True, null=True, diff --git a/compilacao/templatetags/compilacao_filters.py b/compilacao/templatetags/compilacao_filters.py index 46726906a..a8dfe91b9 100644 --- a/compilacao/templatetags/compilacao_filters.py +++ b/compilacao/templatetags/compilacao_filters.py @@ -5,7 +5,6 @@ from django.db.models import Q from compilacao.models import Dispositivo, TipoDispositivo - register = template.Library() @@ -161,6 +160,14 @@ def field_verbose_name(instance, field_name): return instance._meta.get_field(field_name).verbose_name +@register.simple_tag +def fieldclass_verbose_name(class_name, field_name): + cls = get_class( + 'compilacao.models.' + class_name) + return cls._meta.get_field( + field_name).verbose_name + + @register.simple_tag def model_verbose_name(class_name): model = get_class('compilacao.models.' + class_name) diff --git a/compilacao/urls.py b/compilacao/urls.py index 1fae0972b..f767469f2 100644 --- a/compilacao/urls.py +++ b/compilacao/urls.py @@ -1,8 +1,8 @@ from django.conf.urls import include, url from compilacao import views -from compilacao.views import tipo_nota_crud, tipo_vide_crud,\ - tipo_publicacao_crud, veiculo_publicacao_crud +from compilacao.views import (tipo_nota_crud, tipo_publicacao_crud, + tipo_vide_crud, veiculo_publicacao_crud) urlpatterns_compilacao = [ url(r'^$', views.TaListView.as_view(), name='ta_list'), @@ -61,13 +61,16 @@ urlpatterns_compilacao = [ views.DispositivoSearchFragmentFormView.as_view(), name='search_dispositivo'), - url(r'^config/tipo-textoarticulado$', views.TipoTaListView.as_view(), name='tipo_ta_list'), url(r'^config/tipo-textoarticulado/create$', views.TipoTaCreateView.as_view(), name='tipo_ta_create'), url(r'^config/tipo-textoarticulado/(?P[0-9]+)$', views.TipoTaDetailView.as_view(), name='tipo_ta_detail'), + url(r'^config/tipo-textoarticulado/(?P[0-9]+)/edit$', + views.TipoTaUpdateView.as_view(), name='tipo_ta_edit'), + url(r'^config/tipo-textoarticulado/(?P[0-9]+)/delete$', + views.TipoTaDeleteView.as_view(), name='tipo_ta_delete'), url(r'^config/tipo-nota/', include(tipo_nota_crud.urls)), diff --git a/compilacao/utils.py b/compilacao/utils.py index 8b7ddd3fd..db48bd286 100644 --- a/compilacao/utils.py +++ b/compilacao/utils.py @@ -1,18 +1,17 @@ from braces.views import FormMessagesMixin from crispy_forms.helper import FormHelper from crispy_forms_foundation.layout import Column, Fieldset, Row -from crispy_forms_foundation.layout.base import Layout, Div, HTML +from crispy_forms_foundation.layout.base import HTML, Div, Layout from crispy_forms_foundation.layout.buttons import Submit from django import forms from django.conf.urls import url -from django.core.urlresolvers import reverse_lazy, reverse +from django.core.urlresolvers import reverse, reverse_lazy from django.utils.functional import cached_property from django.utils.translation import ugettext_lazy as _ from django.views.generic.detail import DetailView -from django.views.generic.edit import CreateView, UpdateView, DeleteView +from django.views.generic.edit import CreateView, DeleteView, UpdateView from django.views.generic.list import ListView - NO_ENTRIES_MSG = _('Não existem registros') diff --git a/compilacao/views.py b/compilacao/views.py index 63ab63601..bb3d6389e 100644 --- a/compilacao/views.py +++ b/compilacao/views.py @@ -1,17 +1,14 @@ +import sys from collections import OrderedDict from datetime import datetime, timedelta -import sys from braces.views import FormMessagesMixin -from crispy_forms.helper import FormHelper -from crispy_forms_foundation.layout.containers import Fieldset from django import forms from django.contrib.auth.decorators import login_required from django.contrib.contenttypes.models import ContentType from django.core.signing import Signer from django.core.urlresolvers import reverse, reverse_lazy from django.db.models import Q -from django.forms.models import ModelForm from django.http.response import (HttpResponse, HttpResponseRedirect, JsonResponse) from django.shortcuts import get_object_or_404, redirect @@ -24,15 +21,13 @@ from django.views.generic.edit import CreateView, DeleteView, UpdateView from django.views.generic.list import ListView from compilacao import utils -from compilacao.forms import TaForm, NotaForm, VideForm +from compilacao.forms import NotaForm, TaForm, TipoTaForm, VideForm from compilacao.models import (Dispositivo, Nota, PerfilEstruturalTextoArticulado, TextoArticulado, TipoDispositivo, TipoNota, - TipoTextoArticulado, Vide, TipoVide, - TipoPublicacao, VeiculoPublicacao, - PARTICIPACAO_SOCIAL_CHOICES) -from compilacao.utils import build_crud, to_row, FormLayout - + TipoPublicacao, TipoTextoArticulado, TipoVide, + VeiculoPublicacao, Vide) +from compilacao.utils import build_crud DISPOSITIVO_SELECT_RELATED = ( 'tipo_dispositivo', @@ -89,7 +84,7 @@ class IntegracaoTaView(TemplateView): if not ta.exists(): ta = TextoArticulado() tipo_ta = TipoTextoArticulado.objects.filter( - model=item.__class__.__name__.lower())[:1] + content_type=related_object_type)[:1] if tipo_ta.exists(): ta.tipo_ta = tipo_ta[0] ta.content_object = item @@ -149,7 +144,7 @@ def get_integrations_view_names(): def choice_extenal_views(): integrations_view_names = get_integrations_view_names() - result = [] + result = [(None, '-------------'), ] for item in integrations_view_names: ct = ContentType.objects.filter( model=item.model.__name__.lower(), @@ -161,46 +156,23 @@ def choice_extenal_views(): return result -class TipoTaForm(ModelForm): - sigla = forms.CharField(label='Sigla') - descricao = forms.CharField(label='Descrição') - - participacao_social = forms.NullBooleanField( - label=_('Participação Social'), - widget=forms.Select(choices=PARTICIPACAO_SOCIAL_CHOICES), - required=False) - - class Meta: - model = TipoTextoArticulado - fields = ['sigla', - 'descricao', - 'model', - 'participacao_social', - ] - - def __init__(self, *args, **kwargs): +class CompMixin(object): - row1 = to_row([ - ('sigla', 2), - ('descricao', 4), - ('model', 3), - ('participacao_social', 3), - ]) - - self.helper = FormHelper() - self.helper.layout = FormLayout( - Fieldset(_('Identificação Básica'), - row1, css_class="large-12")) - super(TipoTaForm, self).__init__(*args, **kwargs) + @property + def title(self): + return self.get_object() class TipoTaListView(ListView): model = TipoTextoArticulado paginate_by = 10 verbose_name = model._meta.verbose_name - title = model._meta.verbose_name_plural create_url = reverse_lazy('tipo_ta_create') + @property + def title(self): + return self.model._meta.verbose_name_plural + class TipoTaCreateView(FormMessagesMixin, CreateView): model = TipoTextoArticulado @@ -212,31 +184,67 @@ class TipoTaCreateView(FormMessagesMixin, CreateView): def get(self, request, *args, **kwargs): self.object = None form = self.get_form() - form.fields['model'] = forms.ChoiceField( + form.fields['content_type'] = forms.ChoiceField( choices=choice_extenal_views(), - label='Associação', required=False) + label=_('Modelo Integrado'), required=False) return self.render_to_response(self.get_context_data(form=form)) def get_success_url(self): return reverse_lazy('tipo_ta_detail', kwargs={'pk': self.object.id}) + @property + def cancel_url(self): + return reverse_lazy('tipo_ta_list') + + +class TipoTaDetailView(CompMixin, DetailView): + model = TipoTextoArticulado + + +class TipoTaUpdateView(CompMixin, UpdateView): + model = TipoTextoArticulado + form_class = TipoTaForm + template_name = "compilacao/form.html" + + def get(self, request, *args, **kwargs): + self.object = self.get_object() + form = self.get_form() + form.fields['content_type'] = forms.ChoiceField( + choices=choice_extenal_views(), + label=_('Modelo Integrado'), required=False) + return self.render_to_response(self.get_context_data(form=form)) + + def get_success_url(self): + return reverse_lazy('tipo_ta_detail', kwargs={'pk': self.kwargs['pk']}) + + @property + def cancel_url(self): + return reverse_lazy('tipo_ta_detail', kwargs={'pk': self.kwargs['pk']}) -class TipoTaDetailView(DetailView): + +class TipoTaDeleteView(CompMixin, DeleteView): model = TipoTextoArticulado + template_name = "compilacao/confirm_delete.html" @property - def title(self): - return self.get_object() + def detail_url(self): + return reverse_lazy('tipo_ta_detail', kwargs={'pk': self.kwargs['pk']}) + + def get_success_url(self): + return reverse_lazy('tipo_ta_list') class TaListView(ListView): model = TextoArticulado paginate_by = 10 verbose_name = model._meta.verbose_name - title = model._meta.verbose_name_plural create_url = reverse_lazy('ta_create') + @property + def title(self): + return self.model._meta.verbose_name_plural + def get_context_data(self, **kwargs): context = super(TaListView, self).get_context_data(**kwargs) paginator = context['paginator'] @@ -270,15 +278,23 @@ class TaCreateView(FormMessagesMixin, CreateView): def get_success_url(self): return reverse_lazy('ta_detail', kwargs={'pk': self.object.id}) + @property + def cancel_url(self): + return reverse_lazy('ta_list') + -class TaUpdateView(UpdateView): +class TaUpdateView(CompMixin, UpdateView): model = TextoArticulado form_class = TaForm template_name = "compilacao/form.html" - @property - def title(self): - return self.get_object() + def get(self, request, *args, **kwargs): + self.object = self.get_object() + form = self.get_form() + # if self.object and self.object.content_object: + # form.fields['tipo_ta'].required = False + # form.fields['tipo_ta'].widget.attrs['disabled'] = 'disabled' + return self.render_to_response(self.get_context_data(form=form)) def get_success_url(self): return reverse_lazy('ta_detail', kwargs={'pk': self.kwargs['pk']}) @@ -288,12 +304,9 @@ class TaUpdateView(UpdateView): return reverse_lazy('ta_detail', kwargs={'pk': self.kwargs['pk']}) -class TaDeleteView(DeleteView): +class TaDeleteView(CompMixin, DeleteView): model = TextoArticulado - - @property - def title(self): - return self.get_object() + template_name = "compilacao/confirm_delete.html" @property def detail_url(self): @@ -318,10 +331,10 @@ class TextView(ListView): def get(self, request, *args, **kwargs): ta = TextoArticulado.objects.get(pk=self.kwargs['ta_id']) - self.title = ta + self.object = ta if ta.content_object: item = ta.content_object - self.title = item + self.object = item if hasattr(item, 'ementa') and item.ementa: ta.ementa = item.ementa else: diff --git a/compilacao/views2.py b/compilacao/views2.py index c1b2d6169..4c09763f3 100644 --- a/compilacao/views2.py +++ b/compilacao/views2.py @@ -1,11 +1,8 @@ from django.utils.translation import ugettext_lazy as _ -from compilacao.models import (PerfilEstruturalTextoArticulado, - TipoDispositivo, TipoNota, TipoPublicacao, - TipoVide, VeiculoPublicacao) +from compilacao.models import PerfilEstruturalTextoArticulado, TipoDispositivo from sapl.crud import build_crud - perfil_estr_txt_norm = build_crud( PerfilEstruturalTextoArticulado, 'perfil_estrutural', [ diff --git a/materia/urls.py b/materia/urls.py index 5768a807e..e7ddf4317 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -9,13 +9,14 @@ from materia.views import (AutoriaEditView, AutoriaView, MateriaLegislativaPesquisaView, MateriaTaView, NumeracaoEditView, NumeracaoView, PesquisaMateriaListView, ProposicaoListView, - ProposicaoView, RelatoriaEditView, RelatoriaView, - TramitacaoEditView, TramitacaoView, autor_crud, - materia_legislativa_crud, orgao_crud, origem_crud, - regime_tramitacao_crud, status_tramitacao_crud, - tipo_autor_crud, tipo_documento_crud, - tipo_fim_relatoria_crud, tipo_materia_crud, - tipo_proposicao_crud, unidade_tramitacao_crud) + ProposicaoTaView, ProposicaoView, RelatoriaEditView, + RelatoriaView, TramitacaoEditView, TramitacaoView, + autor_crud, materia_legislativa_crud, orgao_crud, + origem_crud, regime_tramitacao_crud, + status_tramitacao_crud, tipo_autor_crud, + tipo_documento_crud, tipo_fim_relatoria_crud, + tipo_materia_crud, tipo_proposicao_crud, + unidade_tramitacao_crud) materia_legislativa_patterns = materia_legislativa_crud.urlpatterns @@ -28,6 +29,8 @@ urlpatterns = [ url(r'^materia/(?P[0-9]+)/ta$', MateriaTaView.as_view(), name='materia_ta'), + url(r'^materia/proposicao/(?P[0-9]+)/ta$', + ProposicaoTaView.as_view(), name='proposicao_ta'), url(r'^sistema/proposicoes/tipo/', include(tipo_proposicao_crud.urls)), diff --git a/materia/views.py b/materia/views.py index e20783b4a..3cdda9262 100644 --- a/materia/views.py +++ b/materia/views.py @@ -15,12 +15,12 @@ from django.views.generic import ListView from django.views.generic.edit import FormMixin from vanilla.views import GenericView +import sapl from comissoes.models import Comissao, Composicao from compilacao.views import IntegracaoTaView from norma.models import LegislacaoCitada, NormaJuridica, TipoNormaJuridica from parlamentares.models import Parlamentar from sapl.crud import build_crud -import sapl from .models import (Anexada, Autor, Autoria, DespachoInicial, DocumentoAcessorio, MateriaLegislativa, Numeracao, Orgao, @@ -29,7 +29,6 @@ from .models import (Anexada, Autor, Autoria, DespachoInicial, TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao, Tramitacao, UnidadeTramitacao) - origem_crud = build_crud( Origem, 'origem', [ @@ -952,7 +951,7 @@ class NumeracaoForm(ModelForm): required=True, queryset=TipoMateriaLegislativa.objects.all(), empty_label='Selecione', - ) + ) data_materia = forms.DateField(label='Data', required=False, @@ -1092,7 +1091,7 @@ class DocumentoAcessorioForm(ModelForm): required=True, queryset=TipoDocumento.objects.all(), empty_label='Selecione', - ) + ) data = forms.DateField(label='Data', required=False, @@ -1854,7 +1853,7 @@ class MateriaLegislativaPesquisaForm(forms.Form): required=False, queryset=Autor.objects.all().order_by('tipo'), empty_label='Selecione', - ) + ) # relatores são os parlamentares ativos? relator = forms.ModelChoiceField( @@ -1863,14 +1862,14 @@ class MateriaLegislativaPesquisaForm(forms.Form): queryset=Parlamentar.objects.filter( ativo=True).order_by('nome_parlamentar'), empty_label='Selecione', - ) + ) tipo = forms.ModelChoiceField( label='Tipo de Matéria', required=False, queryset=TipoMateriaLegislativa.objects.all(), empty_label='Selecione', - ) + ) data_apresentacao = forms.DateField(label=u'Data de Apresentação', input_formats=['%d/%m/%Y'], @@ -1896,14 +1895,14 @@ class MateriaLegislativaPesquisaForm(forms.Form): required=False, queryset=UnidadeTramitacao.objects.all(), empty_label='Selecione', - ) + ) situacao = forms.ModelChoiceField( label='Situação', required=False, queryset=StatusTramitacao.objects.all(), empty_label='Selecione', - ) + ) tramitacao = forms.ChoiceField(required=False, label='Tramitando', @@ -2024,3 +2023,7 @@ class PesquisaMateriaListView(FormMixin, ListView): class MateriaTaView(IntegracaoTaView): model = MateriaLegislativa + + +class ProposicaoTaView(IntegracaoTaView): + model = Proposicao diff --git a/norma/migrations/0009_auto_20160106_1511.py b/norma/migrations/0009_auto_20160106_1511.py new file mode 100644 index 000000000..f7c0766cb --- /dev/null +++ b/norma/migrations/0009_auto_20160106_1511.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('norma', '0008_normajuridica_texto_integral'), + ] + + operations = [ + migrations.AlterField( + model_name='normajuridica', + name='tipo', + field=models.ForeignKey(verbose_name='Tipo da Norma Juridica', to='norma.TipoNormaJuridica'), + ), + ] diff --git a/norma/models.py b/norma/models.py index e1e0ec710..cd2c677c8 100644 --- a/norma/models.py +++ b/norma/models.py @@ -72,7 +72,8 @@ class NormaJuridica(models.Model): null=True, upload_to=texto_upload_path, verbose_name=_('Texto Integral')) - tipo = models.ForeignKey(TipoNormaJuridica, verbose_name=_('Tipo da Norma Juridica')) + tipo = models.ForeignKey( + TipoNormaJuridica, verbose_name=_('Tipo da Norma Juridica')) materia = models.ForeignKey(MateriaLegislativa, blank=True, null=True) numero = models.PositiveIntegerField(verbose_name=_('Número')) ano = models.PositiveSmallIntegerField(verbose_name=_('Ano')) diff --git a/norma/views.py b/norma/views.py index f7c64dabb..655b8e89a 100644 --- a/norma/views.py +++ b/norma/views.py @@ -12,15 +12,14 @@ from django.utils.translation import ugettext_lazy as _ from django.views.generic.edit import FormMixin from vanilla.views import GenericView +import sapl from compilacao.views import IntegracaoTaView from materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.crud import build_crud -import sapl from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, TipoNormaJuridica) - assunto_norma_crud = build_crud( AssuntoNorma, 'assunto_norma_juridica', [ diff --git a/static/js/compilacao_view.js b/static/js/compilacao_view.js index 7ec934789..f64c74e40 100644 --- a/static/js/compilacao_view.js +++ b/static/js/compilacao_view.js @@ -5,18 +5,6 @@ $( window ).scroll(function() { $( "section.vigencias" ).addClass("fixed"); }); -$(window).load(function() { - setTimeout(function() { - href = location.href.split('#') - if (href.length == 2) { - height = $( "section.vigencias" ).height(); - $('html, body').animate({ - scrollTop: window.pageYOffset - height - 55 - }, 300); - } - }, 100); -}); - function isElementInViewport (el) { @@ -142,11 +130,19 @@ function textoVigente(item, link) { scrollTop: $(elv).parent().offset().top - 60 }, 0); } - - } $(document).ready(function() { + setTimeout(function() { + var href = location.href.split('#') + if (href.length == 2) { + $('html, body').animate({ + scrollTop: $('#dptt' + href[1] ).offset().top - window.innerHeight / 9 + }, 0); + } + }, 100); + + $("#btn_font_menos").click(function() { $(".dpt").css("font-size", "-=1"); }); diff --git a/templates/compilacao/textoarticulado_confirm_delete.html b/templates/compilacao/confirm_delete.html similarity index 100% rename from templates/compilacao/textoarticulado_confirm_delete.html rename to templates/compilacao/confirm_delete.html diff --git a/templates/compilacao/text_edit.html b/templates/compilacao/text_edit.html index 1004b7c59..8f90e7f57 100644 --- a/templates/compilacao/text_edit.html +++ b/templates/compilacao/text_edit.html @@ -17,13 +17,7 @@

Edição: {{ view.title }} - {% trans 'Texto Multivigente' %}

{% endblock %} - -{% block sections_nav %}{{block.super}} - {% if not object.content_object%} -
{% trans 'Texto' %}
- {%endif %} -{% endblock %} - + {% block base_content %}{{block.super}} diff --git a/templates/compilacao/text_edit_bloco.html b/templates/compilacao/text_edit_bloco.html index 3a7e7f9df..05dc91cd4 100644 --- a/templates/compilacao/text_edit_bloco.html +++ b/templates/compilacao/text_edit_bloco.html @@ -35,7 +35,7 @@