Browse Source

Fix #623

pull/626/head
Eduardo Edson Batista Cordeiro Alves 8 years ago
parent
commit
ee55071a1f
  1. 8
      sapl/materia/forms.py
  2. 53
      sapl/materia/views.py
  3. 6
      sapl/templates/materia/autor_form.html
  4. 5
      sapl/templates/materia/layouts.yaml

8
sapl/materia/forms.py

@ -1,5 +1,6 @@
from datetime import datetime
import django_filters
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout
from django import forms
@ -11,7 +12,6 @@ from django.db import models, transaction
from django.db.models import Max
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
import django_filters
from sapl.comissoes.models import Comissao
from sapl.crispy_layout_mixin import form_actions, to_row
@ -26,7 +26,6 @@ from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
Numeracao, Proposicao, Relatoria, TipoMateriaLegislativa,
Tramitacao, UnidadeTramitacao)
ANO_CHOICES = [('', '---------')] + RANGE_ANOS
@ -662,9 +661,8 @@ class AutorForm(ModelForm):
'email',
'nome',
'tipo',
'cargo',
'parlamentar',
'comissao']
'cargo']
widgets = {'nome': forms.HiddenInput()}
def valida_igualdade(self, texto1, texto2, msg):
if texto1 != texto2:

53
sapl/materia/views.py

@ -118,21 +118,64 @@ class TipoAutorCrud(Crud):
return permissao_tb_aux(self)
def montar_helper_autor(self):
autor_row = montar_row_autor('nome')
self.helper = FormHelper()
self.helper.layout = SaplFormLayout(*self.get_layout())
# Adiciona o novo campo 'autor' e mecanismo de busca
self.helper.layout[0][0].append(HTML(autor_label))
self.helper.layout[0][0].append(HTML(autor_modal))
self.helper.layout[0][1] = autor_row
# Adiciona espaço entre o novo campo e os botões
# self.helper.layout[0][4][1].append(HTML('<br /><br />'))
# Remove botões que estão fora do form
self.helper.layout[1].pop()
# Adiciona novos botões dentro do form
self.helper.layout[0][4][0].insert(2, form_actions(more=[
HTML('<a href="{{ view.cancel_url }}"'
' class="btn btn-inverse">Cancelar</a>')]))
class AutorCrud(Crud):
model = Autor
help_path = 'autor'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
list_field_names = ['tipo', 'nome',
'username', 'cargo']
list_field_names = ['tipo', 'nome']
def has_permission(self):
return permissao_tb_aux(self)
class UpdateView(CrudUpdateView):
form_class = AutorForm
layout_key = 'AutorCreate'
def __init__(self, *args, **kwargs):
montar_helper_autor(self)
super(UpdateView, self).__init__(*args, **kwargs)
def get_context_data(self, **kwargs):
context = super(UpdateView, self).get_context_data(**kwargs)
context['helper'] = self.helper
return context
class CreateView(CrudCreateView):
form_class = AutorForm
layout_key = 'AutorCreate'
def __init__(self, *args, **kwargs):
montar_helper_autor(self)
super(CreateView, self).__init__(*args, **kwargs)
def get_context_data(self, **kwargs):
context = super(CreateView, self).get_context_data(**kwargs)
context['helper'] = self.helper
return context
def get_success_url(self):
pk_autor = Autor.objects.get(
email=self.request.POST.get('email')).id
@ -663,9 +706,9 @@ class TramitacaoCrud(MasterDetailCrud):
return HttpResponseRedirect(url)
def montar_row_autor():
def montar_row_autor(name):
autor_row = to_row(
[('autor', 0),
[(name, 0),
(Button('pesquisar',
'Pesquisar Autor',
css_class='btn btn-primary btn-sm'), 2),
@ -677,7 +720,7 @@ def montar_row_autor():
def montar_helper_documento_acessorio(self):
autor_row = montar_row_autor()
autor_row = montar_row_autor('autor')
self.helper = FormHelper()
self.helper.layout = SaplFormLayout(*self.get_layout())

6
sapl/templates/materia/autor_form.html

@ -0,0 +1,6 @@
{% extends "base.html" %}
{% load i18n crispy_forms_tags %}
{% block base_content %}
{% crispy form helper %}
{% endblock %}

5
sapl/templates/materia/layouts.yaml

@ -58,10 +58,11 @@ Autor:
AutorCreate:
Autor:
- tipo:3 nome
- tipo
- nome
- username:4 senha:4 senha_confirma:4
- email:6 confirma_email:6
- cargo:4 parlamentar:4 comissao:4
- cargo
Autoria:
{% trans 'Autoria' %}:

Loading…
Cancel
Save