From 44d41b73c5d057a362980af372153dda03e99fe8 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Thu, 15 Sep 2016 16:58:46 -0300 Subject: [PATCH] Cria o modulo app config --- sapl/base/forms.py | 10 ++++++- sapl/base/migrations/0017_appconfig.py | 24 +++++++++++++++++ sapl/base/models.py | 33 ++++++++++++++++++++++- sapl/base/urls.py | 6 +++-- sapl/base/views.py | 36 ++++++++++++++++++++++++-- sapl/templates/base/layouts.yaml | 4 +++ sapl/templates/sistema.html | 1 + 7 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 sapl/base/migrations/0017_appconfig.py diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 595814d34..8a28dabbe 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -15,7 +15,7 @@ from sapl.settings import MAX_IMAGE_UPLOAD_SIZE from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput, autor_label, autor_modal) -from .models import CasaLegislativa +from .models import AppConfig, CasaLegislativa class RangeWidgetOverride(forms.MultiWidget): @@ -284,3 +284,11 @@ class LoginForm(AuthenticationForm): widget=forms.PasswordInput( attrs={ 'class': 'form-control', 'name': 'password'})) + + +class ConfiguracoesAppForm(ModelForm): + class Meta: + model = AppConfig + fields = ['documentos_administrativos', + 'sequencia_numeracao', + 'painel_aberto'] diff --git a/sapl/base/migrations/0017_appconfig.py b/sapl/base/migrations/0017_appconfig.py new file mode 100644 index 000000000..d162248c8 --- /dev/null +++ b/sapl/base/migrations/0017_appconfig.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-09-15 18:19 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0016_auto_20160701_0940'), + ] + + operations = [ + migrations.CreateModel( + name='AppConfig', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('documentos_administrativos', models.CharField(blank=True, choices=[('O', 'Ostensivo'), ('R', 'Restritivo')], max_length=1, null=True, verbose_name='Ostensivo/Restritivo')), + ('sequencia_numeracao', models.CharField(blank=True, choices=[('A', 'Sequencial por ano'), ('U', 'Sequencial único')], max_length=1, null=True, verbose_name='Sequência de numeração')), + ('painel_aberto', models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], verbose_name='Painel aberto para usuário anônimo')), + ], + ), + ] diff --git a/sapl/base/models.py b/sapl/base/models.py index 966f66de3..9e8e59613 100644 --- a/sapl/base/models.py +++ b/sapl/base/models.py @@ -3,7 +3,14 @@ from django.contrib.contenttypes.models import ContentType from django.db import models from django.utils.translation import ugettext_lazy as _ -from sapl.utils import UF +from sapl.utils import UF, YES_NO_CHOICES + + +TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')), + ('R', _('Restritivo'))) + +SEQUENCIA_NUMERACAO = (('A', _('Sequencial por ano')), + ('U', _('Sequencial único'))) def get_sessao_media_path(instance, subpath, filename): @@ -68,3 +75,27 @@ class ProblemaMigracao(models.Model): class Meta: verbose_name = _('Problema na Migração') verbose_name_plural = _('Problemas na Migração') + + +class AppConfig(models.Model): + documentos_administrativos = models.CharField( + max_length=1, + verbose_name=_('Ostensivo/Restritivo'), + choices=TIPO_DOCUMENTO_ADMINISTRATIVO) + + sequencia_numeracao = models.CharField( + max_length=1, + verbose_name=_('Sequência de numeração'), + choices=SEQUENCIA_NUMERACAO) + + painel_aberto = models.BooleanField( + verbose_name=_('Painel aberto para usuário anônimo'), + choices=YES_NO_CHOICES) + + class Meta: + verbose_name = _('Configurações da Aplicação') + verbose_name_plural = _('Configurações da Aplicação') + + def __str__(self): + return _('Configurações da Aplicação - %(id)s') % { + 'id': self.id} diff --git a/sapl/base/urls.py b/sapl/base/urls.py index 60804abea..196b7d36d 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -4,7 +4,8 @@ from django.views.generic.base import TemplateView from .apps import AppConfig from .forms import LoginForm -from .views import (CasaLegislativaCrud, HelpView, RelatorioAtasView, +from .views import (AppConfigCrud, + CasaLegislativaCrud, HelpView, RelatorioAtasView, RelatorioHistoricoTramitacaoView, RelatorioMateriasPorAnoAutorTipoView, RelatorioMateriasPorAutorView, @@ -22,7 +23,8 @@ urlpatterns = [ url(r'^ajuda/(?P\w+)$', HelpView.as_view(), name='help_topic'), url(r'^ajuda/', TemplateView.as_view(template_name='ajuda/index.html'), name='help_base'), - url(r'^casa_legislativa/', include(CasaLegislativaCrud.get_urls())), + url(r'^casa-legislativa/', include(CasaLegislativaCrud.get_urls())), + url(r'^app-config/', include(AppConfigCrud.get_urls())), url(r'^login/$', views.login, { 'template_name': 'base/login.html', 'authentication_form': LoginForm}, diff --git a/sapl/base/views.py b/sapl/base/views.py index d813d4aff..34c3d7534 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -6,6 +6,7 @@ from django.db.models import Count, Q from django.http import HttpResponseRedirect from django.utils.translation import ugettext_lazy as _ from django.views.generic.base import TemplateView +from django.views.generic.edit import BaseCreateView from django_filters.views import FilterView from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, @@ -16,13 +17,14 @@ from sapl.sessao.models import (OrdemDia, PresencaOrdemDia, SessaoPlenaria, SessaoPlenariaPresenca) from sapl.utils import permissao_tb_aux -from .forms import (CasaLegislativaForm, RelatorioAtasFilterSet, +from .forms import (CasaLegislativaForm, ConfiguracoesAppForm, + RelatorioAtasFilterSet, RelatorioHistoricoTramitacaoFilterSet, RelatorioMateriasPorAnoAutorTipoFilterSet, RelatorioMateriasPorAutorFilterSet, RelatorioMateriasTramitacaoilterSet, RelatorioPresencaSessaoFilterSet) -from .models import CasaLegislativa +from .models import AppConfig, CasaLegislativa def get_casalegislativa(): @@ -259,3 +261,33 @@ class SistemaView(PermissionRequiredMixin, TemplateView): def has_permission(self): return permissao_tb_aux(self) + + +class AppConfigCrud(Crud): + model = AppConfig + help_path = '' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + list_field_names = ['documentos_administrativos', + 'sequencia_numeracao', + 'painel_aberto'] + + def has_permission(self): + return permissao_tb_aux(self) + + class CreateView(PermissionRequiredMixin, CrudCreateView): + form_class = ConfiguracoesAppForm + + def get(self, request, *args, **kwargs): + app_config = AppConfig.objects.last() + if app_config: + return HttpResponseRedirect( + reverse('sapl.base:appconfig_update', + kwargs={'pk': app_config.pk})) + else: + self.object = None + return super(BaseCreateView, self).get( + request, *args, **kwargs) + + class UpdateView(PermissionRequiredMixin, CrudUpdateView): + form_class = ConfiguracoesAppForm diff --git a/sapl/templates/base/layouts.yaml b/sapl/templates/base/layouts.yaml index 4e84ee4cd..ebe0abc8b 100644 --- a/sapl/templates/base/layouts.yaml +++ b/sapl/templates/base/layouts.yaml @@ -9,3 +9,7 @@ CasaLegislativa: - endereco_web - email - informacao_geral + +AppConfig: + {% trans 'Configurações da Aplicação' %}: + - documentos_administrativos sequencia_numeracao painel_aberto diff --git a/sapl/templates/sistema.html b/sapl/templates/sistema.html index cc28d831d..bbb3d90ce 100644 --- a/sapl/templates/sistema.html +++ b/sapl/templates/sistema.html @@ -6,6 +6,7 @@

Configuração Inicial

Módulo Parlamentares