Browse Source

Fix #1960 (#1962)

* Fix #1960

* Tira ipdb
pull/1967/head
Victor Fabre 7 years ago
committed by Edward
parent
commit
acc619c13e
  1. 55
      sapl/protocoloadm/forms.py
  2. 5
      sapl/protocoloadm/urls.py
  3. 22
      sapl/protocoloadm/views.py
  4. 1
      sapl/templates/protocoloadm/protocoloadm_detail.html

55
sapl/protocoloadm/forms.py

@ -758,6 +758,7 @@ class DocumentoAdministrativoForm(ModelForm):
super(DocumentoAdministrativoForm, self).__init__(
*args, **kwargs)
class DesvincularDocumentoForm(ModelForm):
numero = forms.CharField(required=True,
@ -817,3 +818,57 @@ class DesvincularDocumentoForm(ModelForm):
)
super(DesvincularDocumentoForm, self).__init__(
*args, **kwargs)
class DesvincularMateriaForm(forms.Form):
numero = forms.CharField(required=True,
label=_('Número da Matéria'))
ano = forms.ChoiceField(required=True,
label=_('Ano da Matéria'),
choices=RANGE_ANOS,
widget=forms.Select(attrs={'class': 'selector'}))
tipo = forms.ModelChoiceField(label=_('Tipo de Matéria'),
required=True,
queryset=TipoMateriaLegislativa.objects.all(),
empty_label='------')
def clean(self):
super(DesvincularMateriaForm, self).clean()
cleaned_data = self.cleaned_data
if not self.is_valid():
return cleaned_data
numero = cleaned_data['numero']
ano = cleaned_data['ano']
tipo = cleaned_data['tipo']
try:
materia = MateriaLegislativa.objects.get(numero=numero, ano=ano, tipo=tipo)
if not materia.numero_protocolo:
raise forms.ValidationError(
_("%s %s/%s não se encontra vinculada a nenhum protocolo" % (tipo, numero, ano)))
except ObjectDoesNotExist:
raise forms.ValidationError(
_("%s %s/%s não existe" % (tipo, numero, ano)))
return cleaned_data
def __init__(self, *args, **kwargs):
super(DesvincularMateriaForm, self).__init__(*args, **kwargs)
row1 = to_row(
[('numero', 4),
('ano', 4),
('tipo', 4)])
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(_('Identificação da Matéria'),
row1,
HTML(" "),
form_actions(label='Desvincular')
)
)

5
sapl/protocoloadm/urls.py

@ -16,7 +16,8 @@ from sapl.protocoloadm.views import (AnularProtocoloAdmView,
TramitacaoAdmCrud,
atualizar_numero_documento,
doc_texto_integral,
DesvincularDocumentoView)
DesvincularDocumentoView,
DesvincularMateriaView)
from .apps import AppConfig
@ -64,6 +65,8 @@ urlpatterns_protocolo = [
AnularProtocoloAdmView.as_view(), name='anular_protocolo'),
url(r'^protocoloadm/desvincular-documento',
DesvincularDocumentoView.as_view(), name='desvincular_documento'),
url(r'^protocoloadm/desvincular-materia',
DesvincularMateriaView.as_view(), name='desvincular_materia'),
url(r'^protocoloadm/protocolar-mat',
ProtocoloMateriaView.as_view(), name='protocolar_mat'),

22
sapl/protocoloadm/views.py

@ -13,6 +13,7 @@ from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.views.generic import CreateView, ListView
from django.views.generic.base import RedirectView, TemplateView
from django.views.generic.edit import FormView
from django_filters.views import FilterView
import sapl
@ -30,7 +31,7 @@ from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
DocumentoAdministrativoFilterSet,
DocumentoAdministrativoForm, ProtocoloDocumentForm,
ProtocoloFilterSet, ProtocoloMateriaForm,
TramitacaoAdmEditForm, TramitacaoAdmForm, DesvincularDocumentoForm)
TramitacaoAdmEditForm, TramitacaoAdmForm, DesvincularDocumentoForm, DesvincularMateriaForm)
from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo,
StatusTramitacaoAdministrativo,
TipoDocumentoAdministrativo, TramitacaoAdministrativo)
@ -722,6 +723,7 @@ def atualizar_numero_documento(request):
return response
class DesvincularDocumentoView(PermissionRequiredMixin, CreateView):
template_name = 'protocoloadm/anular_protocoloadm.html'
form_class = DesvincularDocumentoForm
@ -738,3 +740,21 @@ class DesvincularDocumentoView(PermissionRequiredMixin, CreateView):
documento.protocolo = None
documento.save()
return redirect(self.get_success_url())
class DesvincularMateriaView(PermissionRequiredMixin, FormView):
template_name = 'protocoloadm/anular_protocoloadm.html'
form_class = DesvincularMateriaForm
form_valid_message = _('Matéria desvinculado com sucesso!')
permission_required = ('protocoloadm.action_anular_protocolo', )
def get_success_url(self):
return reverse('sapl.protocoloadm:protocolo')
def form_valid(self, form):
materia = MateriaLegislativa.objects.get(numero=form.cleaned_data['numero'],
ano=form.cleaned_data['ano'],
tipo=form.cleaned_data['tipo'])
materia.numero_protocolo = None
materia.save()
return redirect(self.get_success_url())

1
sapl/templates/protocoloadm/protocoloadm_detail.html

@ -6,5 +6,6 @@
<a href="{% url 'sapl.protocoloadm:protocolar_doc' %}" class="btn btn-default">{% trans 'Protocolar Documento' %}</a>
<a href="{% url 'sapl.protocoloadm:anular_protocolo' %}" class="btn btn-default btn-excluir">{% trans 'Anular Protocolo' %}</a>
<a href="{% url 'sapl.protocoloadm:desvincular_documento' %}" class="btn btn-default btn-excluir">{% trans 'Desvincular Documentos' %}</a>
<a href="{% url 'sapl.protocoloadm:desvincular_materia' %}" class="btn btn-default btn-excluir">{% trans 'Desvincular Matérias' %}</a>
</div>
{% endblock editions %}

Loading…
Cancel
Save