Browse Source

Simplifica DocumentoAdministrativoForm

pull/222/head
Marcio Mazza 9 years ago
parent
commit
719cc87005
  1. 50
      protocoloadm/forms.py
  2. 19
      protocoloadm/migrations/0007_auto_20160218_1429.py
  3. 6
      protocoloadm/models.py
  4. 2
      protocoloadm/views.py

50
protocoloadm/forms.py

@ -1,11 +1,12 @@
from datetime import date from datetime import date
import sapl
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import Fieldset, Layout, Submit from crispy_forms.layout import HTML, Field, Fieldset, Layout, Submit
from django import forms from django import forms
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
import sapl
from materia.models import TipoMateriaLegislativa from materia.models import TipoMateriaLegislativa
from sapl.layout import form_actions from sapl.layout import form_actions
@ -429,34 +430,6 @@ class TramitacaoAdmForm(ModelForm):
class DocumentoAdministrativoForm(ModelForm): class DocumentoAdministrativoForm(ModelForm):
data = forms.DateField(label=u'Data',
input_formats=['%d/%m/%Y'],
required=False,
widget=forms.DateInput(
format='%d/%m/%Y',
attrs={'class': 'dateinput'}))
data_fim_prazo = forms.DateField(label=u'Data Fim Prazo',
input_formats=['%d/%m/%Y'],
required=False,
widget=forms.DateInput(
format='%d/%m/%Y',
attrs={'class': 'dateinput'}))
tramitacao = forms.ChoiceField(required=True,
label='Em Tramitação?',
choices=tramitacao(),
widget=forms.Select(
attrs={'class': 'selector'}))
assunto = forms.CharField(
label='Assunto', required=False,
widget=forms.Textarea())
observacao = forms.CharField(
label='Observação', required=False,
widget=forms.Textarea())
class Meta: class Meta:
model = DocumentoAdministrativo model = DocumentoAdministrativo
fields = ['tipo', fields = ['tipo',
@ -470,46 +443,39 @@ class DocumentoAdministrativoForm(ModelForm):
'dias_prazo', 'dias_prazo',
'data_fim_prazo', 'data_fim_prazo',
'observacao', 'observacao',
'texto_integral' 'texto_integral',
] ]
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
row1 = sapl.layout.to_row( row1 = sapl.layout.to_row(
[('tipo', 4), [('tipo', 4), ('numero', 4), ('ano', 4)])
('numero', 4),
('ano', 4)])
row2 = sapl.layout.to_row( row2 = sapl.layout.to_row(
[('data', 6), [('data', 6), ('numero_protocolo', 6)])
('numero_protocolo', 6)])
row3 = sapl.layout.to_row( row3 = sapl.layout.to_row(
[('assunto', 12)]) [('assunto', 12)])
row4 = sapl.layout.to_row( row4 = sapl.layout.to_row(
[('interessado', 9), [('interessado', 9), ('tramitacao', 3)])
('tramitacao', 3)])
row5 = sapl.layout.to_row( row5 = sapl.layout.to_row(
[('texto_integral', 12)]) [('texto_integral', 12)])
row6 = sapl.layout.to_row( row6 = sapl.layout.to_row(
[('dias_prazo', 6), [('dias_prazo', 6), ('data_fim_prazo', 6)])
('data_fim_prazo', 6)])
row7 = sapl.layout.to_row( row7 = sapl.layout.to_row(
[('observacao', 12)]) [('observacao', 12)])
self.helper = FormHelper() self.helper = FormHelper()
self.helper.layout = Layout( self.helper.layout = Layout(
Fieldset('Formulário de Cadastro',
Fieldset('Identificação Básica', Fieldset('Identificação Básica',
row1, row2, row3, row4, row5), row1, row2, row3, row4, row5),
Fieldset('Outras Informações', Fieldset('Outras Informações',
row6, row7), row6, row7),
form_actions(more=[Submit('Excluir', 'Excluir')]), form_actions(more=[Submit('Excluir', 'Excluir')]),
),
) )
super(DocumentoAdministrativoForm, self).__init__( super(DocumentoAdministrativoForm, self).__init__(
*args, **kwargs) *args, **kwargs)

19
protocoloadm/migrations/0007_auto_20160218_1429.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('protocoloadm', '0006_auto_20160216_1015'),
]
operations = [
migrations.AlterField(
model_name='documentoadministrativo',
name='tramitacao',
field=models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], verbose_name='Em Tramitação?'),
),
]

6
protocoloadm/models.py

@ -2,7 +2,7 @@ from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from materia.models import Autor, TipoMateriaLegislativa, UnidadeTramitacao from materia.models import Autor, TipoMateriaLegislativa, UnidadeTramitacao
from sapl.utils import make_choices from sapl.utils import YES_NO_CHOICES, make_choices
class TipoDocumentoAdministrativo(models.Model): class TipoDocumentoAdministrativo(models.Model):
@ -40,7 +40,9 @@ class DocumentoAdministrativo(models.Model):
blank=True, null=True, verbose_name=_('Dias Prazo')) blank=True, null=True, verbose_name=_('Dias Prazo'))
data_fim_prazo = models.DateField( data_fim_prazo = models.DateField(
blank=True, null=True, verbose_name=_('Data Fim Prazo')) blank=True, null=True, verbose_name=_('Data Fim Prazo'))
tramitacao = models.BooleanField(verbose_name=_('Em Tramitação?')) tramitacao = models.BooleanField(
verbose_name=_('Em Tramitação?'),
choices=YES_NO_CHOICES)
assunto = models.TextField(verbose_name=_('Assunto')) assunto = models.TextField(verbose_name=_('Assunto'))
observacao = models.TextField( observacao = models.TextField(
blank=True, verbose_name=_('Observação')) blank=True, verbose_name=_('Observação'))

2
protocoloadm/views.py

@ -328,14 +328,12 @@ class CriarDocumentoProtocolo(FormMixin, GenericView):
template_name = "protocoloadm/criar_documento.html" template_name = "protocoloadm/criar_documento.html"
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
numero = self.kwargs['pk'] numero = self.kwargs['pk']
ano = self.kwargs['ano'] ano = self.kwargs['ano']
protocolo = Protocolo.objects.get(ano=ano, numero=numero) protocolo = Protocolo.objects.get(ano=ano, numero=numero)
form = DocumentoAdministrativoForm( form = DocumentoAdministrativoForm(
initial=criar_documento(protocolo)) initial=criar_documento(protocolo))
return self.render_to_response({ return self.render_to_response({
'protocolo': protocolo,
'form': form}) 'form': form})
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):

Loading…
Cancel
Save