From b1d9d47a7764254dae09c28551b11acf9581863f Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 1 Mar 2016 09:08:54 -0300 Subject: [PATCH] Adiciona campo exclude ao crud gerado automaticamente Fix #224 --- crud.py | 7 +++--- materia/forms.py | 1 + materia/migrations/0019_auto_20160229_1321.py | 19 ++++++++++++++++ materia/migrations/0020_auto_20160229_1324.py | 22 +++++++++++++++++++ materia/models.py | 4 ++-- materia/views.py | 3 ++- 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 materia/migrations/0019_auto_20160229_1321.py create mode 100644 materia/migrations/0020_auto_20160229_1324.py diff --git a/crud.py b/crud.py index 80a2cff5b..9f5ed1cc3 100644 --- a/crud.py +++ b/crud.py @@ -62,14 +62,13 @@ def get_field_display(obj, fieldname): class CrispyLayoutFormMixin(object): def get_form_class(self): - layout = self.layout class CrispyForm(forms.ModelForm): class Meta: model = self.model - exclude = [] + exclude = self.exclude def __init__(self, *args, **kwargs): super(CrispyForm, self).__init__(*args, **kwargs) @@ -254,13 +253,15 @@ class Crud(object): create_mixin=CrudCreateMixin, detail_mixin=CrudDetailMixin, update_mixin=CrudUpdateMixin, - delete_mixin=CrudDeleteMixin): + delete_mixin=CrudDeleteMixin, + exclude=[]): class CrudMixin(base_mixin): pass CrudMixin.model = model CrudMixin.help_path = help_path CrudMixin.layout = layout + CrudMixin.exclude = exclude class CrudListView(CrudMixin, list_mixin, ListView): pass diff --git a/materia/forms.py b/materia/forms.py index 5c9434a6e..40d62f687 100644 --- a/materia/forms.py +++ b/materia/forms.py @@ -513,6 +513,7 @@ class FormularioSimplificadoForm(ModelForm): 'em_tramitacao', 'ementa', 'texto_original'] + exclude = ['anexadas'] def __init__(self, *args, **kwargs): diff --git a/materia/migrations/0019_auto_20160229_1321.py b/materia/migrations/0019_auto_20160229_1321.py new file mode 100644 index 000000000..02f0f3e81 --- /dev/null +++ b/materia/migrations/0019_auto_20160229_1321.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0018_merge'), + ] + + operations = [ + migrations.AlterField( + model_name='materialegislativa', + name='anexadas', + field=models.ManyToManyField(to='materia.MateriaLegislativa', blank=True, related_name='anexo_de', through='materia.Anexada'), + ), + ] diff --git a/materia/migrations/0020_auto_20160229_1324.py b/materia/migrations/0020_auto_20160229_1324.py new file mode 100644 index 000000000..cbe51e7c4 --- /dev/null +++ b/materia/migrations/0020_auto_20160229_1324.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.utils.timezone import utc +import datetime + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0019_auto_20160229_1321'), + ] + + operations = [ + migrations.AlterField( + model_name='materialegislativa', + name='data_apresentacao', + field=models.DateField(default=datetime.datetime(2016, 2, 29, 16, 24, 24, 963568, tzinfo=utc), verbose_name='Data Apresentação'), + preserve_default=False, + ), + ] diff --git a/materia/models.py b/materia/models.py index 27d7c6716..c41f8c623 100644 --- a/materia/models.py +++ b/materia/models.py @@ -65,8 +65,7 @@ class MateriaLegislativa(models.Model): ano = models.PositiveSmallIntegerField(verbose_name=_('Ano')) numero_protocolo = models.PositiveIntegerField( blank=True, null=True, verbose_name=_('Núm. Protocolo')) - data_apresentacao = models.DateField( - blank=True, null=True, verbose_name=_('Data Apresentação')) + data_apresentacao = models.DateField(verbose_name=_('Data Apresentação')) tipo_apresentacao = models.CharField( max_length=1, blank=True, verbose_name=_('Tipo de Apresentação'), @@ -111,6 +110,7 @@ class MateriaLegislativa(models.Model): # XXX novo anexadas = models.ManyToManyField( 'self', + blank=True, through='Anexada', symmetrical=False, related_name='anexo_de', diff --git a/materia/views.py b/materia/views.py index b0c18a74f..55a660fe5 100644 --- a/materia/views.py +++ b/materia/views.py @@ -73,6 +73,7 @@ tipo_fim_relatoria_crud = Crud( ]) materia_legislativa_crud = Crud( + MateriaLegislativa, '', [ [_('Identificação Básica'), @@ -99,7 +100,7 @@ materia_legislativa_crud = Crud( [('ementa', 12)], [('indexacao', 12)], [('observacao', 12)]], - ]) + ], exclude=['anexadas']) Anexada_crud = Crud( Anexada, '', [