Browse Source

Merge branch 'master' of github.com:interlegis/sapl

pull/626/head
Eduardo Calil 8 years ago
parent
commit
16d6fead12
  1. 8
      sapl/materia/forms.py
  2. 53
      sapl/materia/views.py
  3. 8
      sapl/protocoloadm/urls.py
  4. 2
      sapl/protocoloadm/views.py
  5. 4
      sapl/static/js/app.js
  6. 6
      sapl/templates/materia/autor_form.html
  7. 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())

8
sapl/protocoloadm/urls.py

@ -43,9 +43,9 @@ urlpatterns = [
include(ProtocoloMateriaCrud.get_urls()), name='protocolomat'),
url(r'^protocoloadm/protocolo$',
ProtocoloPesquisaView.as_view(), name='protocolo'),
url(r'^protocoloadm/protocolo_list$',
url(r'^protocoloadm/protocolo-list$',
ProtocoloListView.as_view(), name='protocolo_list'),
url(r'^protocoloadm/(?P<pk>\d+)/(?P<ano>\d+)/protocolo_mostrar$',
url(r'^protocoloadm/(?P<pk>\d+)/(?P<ano>\d+)/protocolo-mostrar$',
ProtocoloMostrarView.as_view(), name='protocolo_mostrar'),
url(r'^protocoloadm/anular-protocolo',
AnularProtocoloAdmView.as_view(), name='anular_protocolo'),
@ -66,12 +66,12 @@ urlpatterns = [
url(r'^protocoloadm/(?P<pk>\d+)/(?P<ano>\d+)/comprovante$',
ComprovanteProtocoloView.as_view(), name='comprovante_protocolo'),
url(r'^protocoloadm/(?P<pk>\d+)/(?P<ano>\d+)/criar_documento$',
url(r'^protocoloadm/(?P<pk>\d+)/(?P<ano>\d+)/criar-documento$',
CriarDocumentoProtocolo.as_view(), name='criar_documento'),
# FIXME: Usado para pesquisar autor
# Melhor forma de fazer?
# Deve mudar de app?
url(r'^proposicao/pesquisar_autor',
url(r'^proposicao/pesquisar-autor',
pesquisa_autores, name='pesquisar_autor'),
]

2
sapl/protocoloadm/views.py

@ -95,7 +95,7 @@ class ProtocoloPesquisaView(PermissionRequiredMixin, FilterView):
kwargs = {'data': self.request.GET or None}
qs = self.get_queryset()
qs = self.get_queryset().order_by('ano', 'numero')
qs = qs.distinct()

4
sapl/static/js/app.js

@ -90,7 +90,7 @@ function autorModal() {
$("#pesquisar").click(function() {
var query = $("#q").val()
$.get("/proposicao/pesquisar_autor?q="+ query, function(
$.get("/proposicao/pesquisar-autor?q="+ query, function(
data, status){
$("#div-resultado").children().remove();
@ -142,7 +142,7 @@ function autorModal() {
if ($(fieldname).length > 0) { // se campo existir
if ($(fieldname).val() != "") { // e não for vazio
var id = $(fieldname).val();
$.get("/proposicao/get_nome_autor?id=" + id, function(data, status){
$.get("/proposicao/get-nome-autor?id=" + id, function(data, status){
$("#nome_autor").text(data.nome);
});
}

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