diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index d36c8b3bf..50dfa2447 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -137,20 +137,32 @@ class AnularProcoloAdmForm(ModelForm): YEARS = get_range_anos() - numero = forms.CharField( - label=_('Número de Protocolo'), required=True) - ano = forms.ChoiceField(required=False, - label='Ano', + numero = forms.CharField(required=True, + label=Protocolo._meta.\ + get_field('numero').verbose_name + ) + ano = forms.ChoiceField(required=True, + label=Protocolo._meta.\ + get_field('ano').verbose_name, choices=YEARS, widget=forms.Select(attrs={'class': 'selector'})) - justificativa_anulacao = forms.CharField( - widget=forms.Textarea, label='Motivo', required=True) + justificativa_anulacao = forms.CharField(required=True, + label=Protocolo._meta.\ + get_field('justificativa_anulacao' + ).verbose_name, + widget=forms.Textarea) def clean(self): cleaned_data = super(AnularProcoloAdmForm, self).clean() + numero = cleaned_data.get("numero") ano = cleaned_data.get("ano") + # se não inserido numero ou ano não prosseguir + # (e ele vai falhar pq numero e ano são obrigatórios) + if not numero or not ano: + return + try: protocolo = Protocolo.objects.get(numero=numero, ano=ano) @@ -330,8 +342,9 @@ class ProtocoloMateriaForm(ModelForm): row1 = crispy_layout_mixin.to_row( [('numeracao', 12)]) row2 = crispy_layout_mixin.to_row( - [('tipo_materia', 6), - ('num_paginas', 6)]) + [('tipo_materia', 4), + ('tipo_protocolo', 4), + ('num_paginas', 4)]) row3 = crispy_layout_mixin.to_row( [('ementa', 12)]) row4 = crispy_layout_mixin.to_row( diff --git a/protocoloadm/migrations/0008_auto_20160308_1436.py b/protocoloadm/migrations/0008_auto_20160308_1436.py new file mode 100644 index 000000000..913921ac3 --- /dev/null +++ b/protocoloadm/migrations/0008_auto_20160308_1436.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-03-08 17:36 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('protocoloadm', '0007_auto_20160218_1429'), + ] + + operations = [ + migrations.AlterField( + model_name='protocolo', + name='ano', + field=models.PositiveSmallIntegerField(verbose_name='Ano do Protocolo'), + ), + ] diff --git a/protocoloadm/models.py b/protocoloadm/models.py index 6b04db2b6..fc9d1715f 100644 --- a/protocoloadm/models.py +++ b/protocoloadm/models.py @@ -88,8 +88,9 @@ class DocumentoAcessorioAdministrativo(models.Model): class Protocolo(models.Model): numero = models.PositiveIntegerField( - blank=True, null=True, verbose_name=_('Número do Protocolo')) - ano = models.PositiveSmallIntegerField() + blank=False, null=False, verbose_name=_('Número de Protocolo')) + ano = models.PositiveSmallIntegerField( + blank=False, null=False, verbose_name=_('Ano do Protocolo')) data = models.DateField() hora = models.TimeField() timestamp = models.DateTimeField() diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 326d262a5..8f1c65326 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -150,7 +150,7 @@ class AnularProtocoloAdmView(FormView): return self.form_invalid(form) -class ProtocoloDocumentoView(FormValidMessageMixin, CreateView): +class ProtocoloDocumentoView(FormValidMessageMixin, FormView): template_name = "protocoloadm/protocolar_documento.html" form_class = ProtocoloDocumentForm @@ -165,8 +165,10 @@ class ProtocoloDocumentoView(FormValidMessageMixin, CreateView): if form.cleaned_data['numeracao'] == '1': numeracao = Protocolo.objects.filter( ano=date.today().year).aggregate(Max('numero')) - else: + elif form.cleaned_data['numeracao'] == '2': numeracao = Protocolo.objects.all().aggregate(Max('numero')) + # else: + # raise ValidationError(_("Campo numeração é obrigatório")) if numeracao['numero__max'] is None: numeracao['numero__max'] = 0 @@ -276,10 +278,6 @@ class ProtocoloMateriaView(FormValidMessageMixin, CreateView): form_class = ProtocoloMateriaForm form_valid_message = _('Matéria cadastrada com sucesso!') - def get_initial(self): - initial = {} - return initial - def post(self, request, *args, **kwargs): form = ProtocoloMateriaForm(request.POST)