Browse Source

Add CasaLegislativaView

pull/98/head
Eduardo Calil 9 years ago
parent
commit
2f38f39874
  1. 20
      base/migrations/0002_casalegislativa_codigo.py
  2. 20
      base/migrations/0003_auto_20160107_1122.py
  3. 26
      base/migrations/0004_auto_20160107_1158.py
  4. 21
      base/models.py
  5. 6
      base/urls.py
  6. 159
      base/views.py
  7. 8
      templates/base/casa_leg_table_aux.html
  8. 2
      templates/sistema.html

20
base/migrations/0002_casalegislativa_codigo.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('base', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='casalegislativa',
name='codigo',
field=models.CharField(verbose_name='Codigo', default=1, max_length=100),
preserve_default=False,
),
]

20
base/migrations/0003_auto_20160107_1122.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import base.models
class Migration(migrations.Migration):
dependencies = [
('base', '0002_casalegislativa_codigo'),
]
operations = [
migrations.AlterField(
model_name='casalegislativa',
name='logotipo',
field=models.FileField(null=True, upload_to=base.models.get_casa_media_path, verbose_name='Logotipo', blank=True),
),
]

26
base/migrations/0004_auto_20160107_1158.py

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('base', '0003_auto_20160107_1122'),
]
operations = [
migrations.RemoveField(
model_name='casalegislativa',
name='cor_borda',
),
migrations.RemoveField(
model_name='casalegislativa',
name='cor_fundo',
),
migrations.RemoveField(
model_name='casalegislativa',
name='cor_principal',
),
]

21
base/models.py

@ -1,10 +1,19 @@
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
def get_sessao_media_path(instance, subpath, filename):
return './casa/%s/%s/%s' % (instance.numero, subpath, filename)
def get_casa_media_path(instance, filename):
import ipdb; ipdb.set_trace()
return get_sessao_media_path(instance, 'Logotipo', filename)
class CasaLegislativa(models.Model): class CasaLegislativa(models.Model):
# TODO ajustar todos os max_length !!!! # TODO ajustar todos os max_length !!!!
# cod_casa => id (pk) # cod_casa => id (pk)
codigo = models.CharField(max_length=100, verbose_name=_('Codigo'))
nome = models.CharField(max_length=100, verbose_name=_('Nome')) nome = models.CharField(max_length=100, verbose_name=_('Nome'))
sigla = models.CharField(max_length=100, verbose_name=_('Sigla')) sigla = models.CharField(max_length=100, verbose_name=_('Sigla'))
endereco = models.CharField(max_length=100, verbose_name=_('Endereço')) endereco = models.CharField(max_length=100, verbose_name=_('Endereço'))
@ -13,13 +22,11 @@ class CasaLegislativa(models.Model):
uf = models.CharField(max_length=100, verbose_name=_('UF')) uf = models.CharField(max_length=100, verbose_name=_('UF'))
telefone = models.CharField(max_length=100, verbose_name=_('Telefone')) telefone = models.CharField(max_length=100, verbose_name=_('Telefone'))
fax = models.CharField(max_length=100, verbose_name=_('Fax')) fax = models.CharField(max_length=100, verbose_name=_('Fax'))
cor_fundo = models.CharField( logotipo = models.FileField(
max_length=100, verbose_name=_('Cor de fundo')) blank=True,
cor_borda = models.CharField( null=True,
max_length=100, verbose_name=_('Cor da borda')) upload_to=get_casa_media_path,
cor_principal = models.CharField( verbose_name=_('Logotipo'))
max_length=100, verbose_name=_('Cor principal'))
logotipo = models.CharField(max_length=100, verbose_name=_('Logotipo'))
endereco_web = models.CharField(max_length=100, verbose_name=_('HomePage')) endereco_web = models.CharField(max_length=100, verbose_name=_('HomePage'))
email = models.CharField(max_length=100, verbose_name=_('E-mail')) email = models.CharField(max_length=100, verbose_name=_('E-mail'))
informacao_geral = models.CharField( informacao_geral = models.CharField(

6
base/urls.py

@ -1,11 +1,15 @@
from django.conf.urls import url from django.conf.urls import url
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from .views import HelpView
from .views import HelpView, CasaLegislativaTableAuxView
urlpatterns = [ urlpatterns = [
url(r'^sistema/', TemplateView.as_view(template_name='sistema.html')), url(r'^sistema/', TemplateView.as_view(template_name='sistema.html')),
url(r'^ajuda/(?P<topic>\w+)$', HelpView.as_view(), name='help_topic'), url(r'^ajuda/(?P<topic>\w+)$', HelpView.as_view(), name='help_topic'),
url(r'^ajuda/', TemplateView.as_view(template_name='ajuda/index.html'), url(r'^ajuda/', TemplateView.as_view(template_name='ajuda/index.html'),
name='help_base'), name='help_base'),
url(r'^casa-legislativa$',
CasaLegislativaTableAuxView.as_view(), name='casa_legislativa'),
] ]

159
base/views.py

@ -1,5 +1,17 @@
import sapl
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from .models import CasaLegislativa
from django.forms import ModelForm
from django import forms
from django.views.generic.edit import FormMixin
from vanilla import GenericView
from crispy_forms.helper import FormHelper
from crispy_forms.layout import (HTML, ButtonHolder, Column, Fieldset, Layout,
Submit)
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
class HelpView(TemplateView): class HelpView(TemplateView):
# XXX treat non existing template as a 404!!!! # XXX treat non existing template as a 404!!!!
@ -7,3 +19,150 @@ class HelpView(TemplateView):
def get_template_names(self): def get_template_names(self):
print(self.kwargs['topic']) print(self.kwargs['topic'])
return ['ajuda/%s.html' % self.kwargs['topic']] return ['ajuda/%s.html' % self.kwargs['topic']]
ESTADOS = ["AC",
"AL",
"AM",
"AP",
"BA",
"CE",
"DF",
"ES",
"GO",
"MA",
"MG",
"MS",
"MT",
"PA",
"PB",
"PE",
"PI",
"PR",
"RJ",
"RN",
"RO",
"RR",
"RS",
"SC",
"SE",
"SP",
"TO"]
class CasaLegislativaTabelaAuxForm(ModelForm):
uf = forms.ChoiceField(required=False,
label='UF',
choices=[(a,a) for a in ESTADOS],
widget=forms.Select(
attrs={'class': 'selector'}))
informacao_geral = forms.CharField(widget=forms.Textarea,
label='informacao_geral',
required=True)
class Meta:
model = CasaLegislativa
fields = ['codigo',
'nome',
'sigla',
'endereco',
'cep',
'municipio',
'uf',
'telefone',
'fax',
'logotipo',
'endereco_web',
'email',
'informacao_geral']
def __init__(self, *args, **kwargs):
row1 = sapl.layout.to_row(
[('codigo', 2),
('nome', 5),
('sigla', 5)])
row2 = sapl.layout.to_row(
[('endereco', 8),
('cep', 4)])
row3 = sapl.layout.to_row(
[('municipio', 10),
('uf', 2)])
row4 = sapl.layout.to_row(
[('telefone', 6),
('fax', 6)])
row5 = sapl.layout.to_row(
[('logotipo', 12)])
row6 = sapl.layout.to_row(
[('endereco_web', 12)])
row7 = sapl.layout.to_row(
[('email', 12)])
row8 = sapl.layout.to_row(
[('informacao_geral', 12)])
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(
'Dados Básicos',
row1,
row2,
row3,
row4,
row5,
row6,
row7,
row8,
ButtonHolder(
Submit('submit', 'Salvar',
css_class='button primary')
)
)
)
super(CasaLegislativaTabelaAuxForm, self).__init__(*args, **kwargs)
class CasaLegislativaTableAuxView(FormMixin, GenericView):
template_name = "base/casa_leg_table_aux.html"
def get(self, request, *args, **kwargs):
try:
casa = CasaLegislativa.objects.first()
except ObjectDoesNotExist:
form = CasaLegislativaTabelaAuxForm()
else:
form = CasaLegislativaTabelaAuxForm(instance=casa)
return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs):
form = CasaLegislativaTabelaAuxForm(request.POST or request.FILES)
if form.is_valid():
try:
casa = CasaLegislativa.objects.first()
except ObjectDoesNotExist:
casa_save = form.save(commit=False)
else:
casa_save = CasaLegislativaTabelaAuxForm(request.POST, instance = casa)
if 'logotipo' in request.FILES:
casa_save.logotipo = request.FILES['logotipo']
casa_save.save()
return self.form_valid(form)
else:
return self.render_to_response({'form': form})
def get_success_url(self):
return reverse('casa_legislativa')

8
templates/base/casa_leg_table_aux.html

@ -0,0 +1,8 @@
{% extends "crud/detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block actions %} {% endblock %}
{% block detail_content %}
{% crispy form %}
{% endblock detail_content %}

2
templates/sistema.html

@ -18,7 +18,7 @@
<h5>Configuração Inicial</h5> <h5>Configuração Inicial</h5>
<ul class="small-block-grid-1 medium-block-grid-2 large-block-grid-2"> <ul class="small-block-grid-1 medium-block-grid-2 large-block-grid-2">
<li><a href="#">Casa Legislativa</a></li> <li><a href="{% url 'casa_legislativa' %}">Casa Legislativa</a></li>
</ul> </ul>
<h5>Módulo Parlamentares</h5> <h5>Módulo Parlamentares</h5>

Loading…
Cancel
Save