Browse Source

Anexo audiencia (#2319)

* Documento acessorio de audiencia publica

* inclusão do arquivo subnav.yaml

* adicionar documento acessorio funcionando

* Fix de erro ao mostrar Documento Acessório

* Alteração de forms.py, models.py e views.py de acordo com mudanças solicitadas.
pull/2329/head
AndreSouto 6 years ago
committed by Edward
parent
commit
fce7a6d6fa
  1. 29
      sapl/audiencia/forms.py
  2. 33
      sapl/audiencia/migrations/0007_anexoaudienciapublica.py
  3. 28
      sapl/audiencia/migrations/0008_auto_20181023_1051.py
  4. 19
      sapl/audiencia/migrations/0009_remove_anexoaudienciapublica_indexacao.py
  5. 46
      sapl/audiencia/models.py
  6. 5
      sapl/audiencia/urls.py
  7. 44
      sapl/audiencia/views.py
  8. 1
      sapl/rules/map_rules.py
  9. 5
      sapl/templates/audiencia/layouts.yaml
  10. 5
      sapl/templates/audiencia/subnav.yaml

29
sapl/audiencia/forms.py

@ -2,7 +2,11 @@ from django import forms
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import transaction from django.db import transaction
from django.utils.translation import ugettext_lazy as _ 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.materia.models import MateriaLegislativa, TipoMateriaLegislativa
from sapl.utils import timezone from sapl.utils import timezone
@ -102,3 +106,26 @@ class AudienciaForm(forms.ModelForm):
raise ValidationError(msg) raise ValidationError(msg)
return cleaned_data 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)

33
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',
},
),
]

28
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),
),
]

19
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',
),
]

46
sapl/audiencia/models.py

@ -1,5 +1,6 @@
import reversion import reversion
from django.db import models from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from model_utils import Choices from model_utils import Choices
from sapl.materia.models import MateriaLegislativa from sapl.materia.models import MateriaLegislativa
@ -147,3 +148,48 @@ class AudienciaPublica(models.Model):
force_update=force_update, force_update=force_update,
using=using, using=using,
update_fields=update_fields) 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,
update_fields=update_fields)

5
sapl/audiencia/urls.py

@ -1,10 +1,11 @@
from django.conf.urls import include, url 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 from .apps import AppConfig
app_name = AppConfig.name app_name = AppConfig.name
urlpatterns = [ urlpatterns = [
url(r'^audiencia/', include(AudienciaCrud.get_urls())), url(r'^audiencia/', include(AudienciaCrud.get_urls() +
AnexoAudienciaPublicaCrud.get_urls())),
] ]

44
sapl/audiencia/views.py

@ -1,11 +1,13 @@
import sapl
from django.http import HttpResponse from django.http import HttpResponse
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.views.decorators.clickjacking import xframe_options_exempt from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic import UpdateView 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 .forms import AudienciaForm, AnexoAudienciaPublicaForm
from .models import AudienciaPublica from .models import AudienciaPublica, AnexoAudienciaPublica
def index(request): def index(request):
@ -70,3 +72,39 @@ class AudienciaCrud(Crud):
return super().get(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

1
sapl/rules/map_rules.py

@ -66,6 +66,7 @@ rules_group_audiencia = {
'rules': [ 'rules': [
(audiencia.AudienciaPublica, __base__), (audiencia.AudienciaPublica, __base__),
(audiencia.TipoAudienciaPublica, __base__), (audiencia.TipoAudienciaPublica, __base__),
(audiencia.AnexoAudienciaPublica, __base__),
] ]
} }

5
sapl/templates/audiencia/layouts.yaml

@ -22,3 +22,8 @@ AudienciaPublicaDetail:
- upload_pauta upload_ata upload_anexo - upload_pauta upload_ata upload_anexo
- observacao - observacao
- audiencia_cancelada - audiencia_cancelada
AnexoAudienciaPublica:
{% trans 'Documento Acessório' %}:
- assunto
- arquivo

5
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
Loading…
Cancel
Save