diff --git a/sapl/audiencia/forms.py b/sapl/audiencia/forms.py old mode 100644 new mode 100755 index 9f55d3e6d..4bd265b72 --- a/sapl/audiencia/forms.py +++ b/sapl/audiencia/forms.py @@ -2,7 +2,11 @@ from django import forms from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.db import transaction from django.utils.translation import ugettext_lazy as _ -from sapl.audiencia.models import AudienciaPublica, TipoAudienciaPublica +from sapl.audiencia.models import AudienciaPublica, TipoAudienciaPublica, AnexoAudienciaPublica +from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout + +from crispy_forms.helper import FormHelper +from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.utils import timezone @@ -102,3 +106,26 @@ class AudienciaForm(forms.ModelForm): raise ValidationError(msg) return cleaned_data + + +class AnexoAudienciaPublicaForm(forms.ModelForm): + + class Meta: + model = AnexoAudienciaPublica + fields = ['arquivo', + 'assunto'] + + def __init__(self, *args, **kwargs): + + row1 = to_row( + [('arquivo', 4)]) + + row2 = to_row( + [('assunto', 12)]) + + self.helper = FormHelper() + self.helper.layout = SaplFormLayout( + Fieldset(_('Identificação Básica'), + row1, row2)) + super(AnexoAudienciaPublicaForm, self).__init__( + *args, **kwargs) diff --git a/sapl/audiencia/migrations/0007_anexoaudienciapublica.py b/sapl/audiencia/migrations/0007_anexoaudienciapublica.py new file mode 100644 index 000000000..b322cc741 --- /dev/null +++ b/sapl/audiencia/migrations/0007_anexoaudienciapublica.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2018-10-17 20:27 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import sapl.utils + + +class Migration(migrations.Migration): + + dependencies = [ + ('audiencia', '0006_auto_20180808_0856'), + ] + + operations = [ + migrations.CreateModel( + name='AnexoAudienciaPublica', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nome', models.CharField(max_length=30, verbose_name='Nome')), + ('arquivo', models.FileField(blank=True, null=True, upload_to=sapl.utils.texto_upload_path, verbose_name='Arquivo')), + ('data', models.DateField(blank=True, null=True, verbose_name='Data')), + ('assunto', models.TextField(blank=True, verbose_name='Assunto')), + ('indexacao', models.TextField(blank=True)), + ('audiencia', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='audiencia.AudienciaPublica')), + ], + options={ + 'verbose_name': 'Documento Acessório', + 'verbose_name_plural': 'Documentos Acessórios', + }, + ), + ] diff --git a/sapl/audiencia/migrations/0008_auto_20181023_1051.py b/sapl/audiencia/migrations/0008_auto_20181023_1051.py new file mode 100644 index 000000000..70c491a4c --- /dev/null +++ b/sapl/audiencia/migrations/0008_auto_20181023_1051.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.8 on 2018-10-23 13:51 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('audiencia', '0007_anexoaudienciapublica'), + ] + + operations = [ + migrations.AlterModelOptions( + name='anexoaudienciapublica', + options={'verbose_name': 'Anexo de Documento Acessório', 'verbose_name_plural': 'Anexo de Documentos Acessórios'}, + ), + migrations.RemoveField( + model_name='anexoaudienciapublica', + name='nome', + ), + migrations.AlterField( + model_name='anexoaudienciapublica', + name='data', + field=models.DateField(auto_now=True, null=True), + ), + ] diff --git a/sapl/audiencia/migrations/0009_remove_anexoaudienciapublica_indexacao.py b/sapl/audiencia/migrations/0009_remove_anexoaudienciapublica_indexacao.py new file mode 100644 index 000000000..e35a7a2a7 --- /dev/null +++ b/sapl/audiencia/migrations/0009_remove_anexoaudienciapublica_indexacao.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.8 on 2018-10-23 13:55 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('audiencia', '0008_auto_20181023_1051'), + ] + + operations = [ + migrations.RemoveField( + model_name='anexoaudienciapublica', + name='indexacao', + ), + ] diff --git a/sapl/audiencia/models.py b/sapl/audiencia/models.py old mode 100644 new mode 100755 index 477a442d9..684f27625 --- a/sapl/audiencia/models.py +++ b/sapl/audiencia/models.py @@ -1,5 +1,6 @@ import reversion from django.db import models +from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from model_utils import Choices from sapl.materia.models import MateriaLegislativa @@ -143,6 +144,51 @@ class AudienciaPublica(models.Model): self.upload_ata = upload_ata self.upload_anexo = upload_anexo + return models.Model.save(self, force_insert=force_insert, + force_update=force_update, + using=using, + update_fields=update_fields) + + +@reversion.register() +class AnexoAudienciaPublica(models.Model): + audiencia = models.ForeignKey(AudienciaPublica, + on_delete=models.PROTECT) + arquivo = models.FileField( + blank=True, + null=True, + upload_to=texto_upload_path, + verbose_name=_('Arquivo')) + data = models.DateField(auto_now=timezone.now,blank=True, null=True) + assunto = models.TextField( + blank=True, verbose_name=_('Assunto')) + + class Meta: + verbose_name = _('Anexo de Documento Acessório') + verbose_name_plural = _('Anexo de Documentos Acessórios') + + def __str__(self): + return self.assunto + + def delete(self, using=None, keep_parents=False): + if self.arquivo: + self.arquivo.delete() + + return models.Model.delete( + self, using=using, keep_parents=keep_parents) + + def save(self, force_insert=False, force_update=False, using=None, + update_fields=None): + + if not self.pk and self.arquivo: + arquivo = self.arquivo + self.arquivo = None + models.Model.save(self, force_insert=force_insert, + force_update=force_update, + using=using, + update_fields=update_fields) + self.arquivo = arquivo + return models.Model.save(self, force_insert=force_insert, force_update=force_update, using=using, diff --git a/sapl/audiencia/urls.py b/sapl/audiencia/urls.py old mode 100644 new mode 100755 index ece3bf1fb..bdf02beca --- a/sapl/audiencia/urls.py +++ b/sapl/audiencia/urls.py @@ -1,10 +1,11 @@ from django.conf.urls import include, url -from sapl.audiencia.views import (index, AudienciaCrud) +from sapl.audiencia.views import (index, AudienciaCrud,AnexoAudienciaPublicaCrud) from .apps import AppConfig app_name = AppConfig.name urlpatterns = [ - url(r'^audiencia/', include(AudienciaCrud.get_urls())), + url(r'^audiencia/', include(AudienciaCrud.get_urls() + + AnexoAudienciaPublicaCrud.get_urls())), ] \ No newline at end of file diff --git a/sapl/audiencia/views.py b/sapl/audiencia/views.py old mode 100644 new mode 100755 index 0a8da8af1..93d214683 --- a/sapl/audiencia/views.py +++ b/sapl/audiencia/views.py @@ -1,11 +1,13 @@ +import sapl + from django.http import HttpResponse from django.core.urlresolvers import reverse from django.views.decorators.clickjacking import xframe_options_exempt from django.views.generic import UpdateView -from sapl.crud.base import RP_DETAIL, RP_LIST, Crud +from sapl.crud.base import RP_DETAIL, RP_LIST, Crud, MasterDetailCrud -from .forms import AudienciaForm -from .models import AudienciaPublica +from .forms import AudienciaForm, AnexoAudienciaPublicaForm +from .models import AudienciaPublica, AnexoAudienciaPublica def index(request): @@ -18,7 +20,7 @@ class AudienciaCrud(Crud): class BaseMixin(Crud.BaseMixin): list_field_names = ['numero', 'nome', 'tipo', 'materia', - 'data'] + 'data'] ordering = 'nome', 'numero', 'tipo', 'data' class ListView(Crud.ListView): @@ -69,4 +71,40 @@ class AudienciaCrud(Crud): def get(self, request, *args, **kwargs): return super().get(request, *args, **kwargs) + +class AudienciaPublicaMixin: + + def has_permission(self): + app_config = sapl.base.models.AppConfig.objects.last() + if app_config and app_config.documentos_administrativos == 'O': + return True + + return super().has_permission() + + +class AnexoAudienciaPublicaCrud(MasterDetailCrud): + model = AnexoAudienciaPublica + parent_field = 'audiencia' + help_topic = 'numeracao_docsacess' + + class BaseMixin(MasterDetailCrud.BaseMixin): + list_field_names = ['assunto'] + + class CreateView(MasterDetailCrud.CreateView): + form_class = AnexoAudienciaPublicaForm + layout_key = None + + class UpdateView(MasterDetailCrud.UpdateView): + form_class = AnexoAudienciaPublicaForm + + class ListView(AudienciaPublicaMixin, MasterDetailCrud.ListView): + + def get_queryset(self): + qs = super(MasterDetailCrud.ListView, self).get_queryset() + kwargs = {self.crud.parent_field: self.kwargs['pk']} + return qs.filter(**kwargs).order_by('-data', '-id') + + class DetailView(AudienciaPublicaMixin, + MasterDetailCrud.DetailView): + pass \ No newline at end of file diff --git a/sapl/rules/map_rules.py b/sapl/rules/map_rules.py index 1a2d1fe8b..342f3383a 100644 --- a/sapl/rules/map_rules.py +++ b/sapl/rules/map_rules.py @@ -66,6 +66,7 @@ rules_group_audiencia = { 'rules': [ (audiencia.AudienciaPublica, __base__), (audiencia.TipoAudienciaPublica, __base__), + (audiencia.AnexoAudienciaPublica, __base__), ] } diff --git a/sapl/templates/audiencia/layouts.yaml b/sapl/templates/audiencia/layouts.yaml index 90433db63..8e93b9f3a 100644 --- a/sapl/templates/audiencia/layouts.yaml +++ b/sapl/templates/audiencia/layouts.yaml @@ -21,4 +21,9 @@ AudienciaPublicaDetail: - url_audio url_video - upload_pauta upload_ata upload_anexo - observacao - - audiencia_cancelada \ No newline at end of file + - audiencia_cancelada + +AnexoAudienciaPublica: + {% trans 'Documento Acessório' %}: + - assunto + - arquivo \ No newline at end of file diff --git a/sapl/templates/audiencia/subnav.yaml b/sapl/templates/audiencia/subnav.yaml new file mode 100644 index 000000000..e6dce83bf --- /dev/null +++ b/sapl/templates/audiencia/subnav.yaml @@ -0,0 +1,5 @@ +{% load i18n common_tags %} +- title: {% trans 'Início' %} + url: audienciapublica_detail +- title: {% trans 'Documento Acessório' %} + url: anexoaudienciapublica_list \ No newline at end of file