mirror of https://github.com/interlegis/sapl.git
Edward
9 years ago
9 changed files with 73 additions and 136 deletions
@ -0,0 +1,10 @@ |
|||
CasaLegislativa: |
|||
Casa Legislativa: |
|||
- codigo:2 nome sigla |
|||
- endereco:8 cep |
|||
- municipio:10 uf |
|||
- telefone fax |
|||
- logotipo |
|||
- endereco_web |
|||
- email |
|||
- informacao_geral |
@ -1,67 +1,32 @@ |
|||
import os |
|||
from functools import lru_cache |
|||
|
|||
from django.core.exceptions import ObjectDoesNotExist |
|||
from django.core.urlresolvers import reverse |
|||
from django.views.generic import FormView |
|||
from django.views.generic.base import TemplateView |
|||
|
|||
from .forms import CasaLegislativaTabelaAuxForm |
|||
import crud.base |
|||
from crud.base import Crud |
|||
|
|||
from .forms import CasaLegislativaForm |
|||
from .models import CasaLegislativa |
|||
|
|||
|
|||
@lru_cache(maxsize=1) |
|||
def get_casalegislativa(): |
|||
return CasaLegislativa.objects.first() |
|||
|
|||
|
|||
class HelpView(TemplateView): |
|||
# XXX treat non existing template as a 404!!!! |
|||
|
|||
def get_template_names(self): |
|||
return ['ajuda/%s.html' % self.kwargs['topic']] |
|||
|
|||
|
|||
class CasaLegislativaTableAuxView(FormView): |
|||
class CasaLegislativaCrud(Crud): |
|||
model = CasaLegislativa |
|||
help_path = '' |
|||
|
|||
template_name = "base/casa_leg_table_aux.html" |
|||
class BaseMixin(crud.base.CrudBaseMixin): |
|||
list_field_names = ['codigo', 'nome', 'sigla'] |
|||
|
|||
def get(self, request, *args, **kwargs): |
|||
try: |
|||
casa = CasaLegislativa.objects.first() |
|||
except ObjectDoesNotExist: |
|||
form = CasaLegislativaTabelaAuxForm() |
|||
else: |
|||
form = CasaLegislativaTabelaAuxForm(instance=casa) |
|||
class CreateView(crud.base.CrudCreateView): |
|||
form_class = CasaLegislativaForm |
|||
|
|||
return self.render_to_response({'form': form}) |
|||
class UpdateView(crud.base.CrudUpdateView): |
|||
form_class = CasaLegislativaForm |
|||
|
|||
def post(self, request, *args, **kwargs): |
|||
form = CasaLegislativaTabelaAuxForm(request.POST, request.FILES) |
|||
if form.is_valid(): |
|||
casa = CasaLegislativa.objects.first() |
|||
if casa: |
|||
if ("remover" in request.POST or |
|||
(form.cleaned_data['logotipo'] and casa.logotipo)): |
|||
try: |
|||
os.unlink(casa.logotipo.path) |
|||
except OSError: |
|||
pass # Should log this error!!!!! |
|||
casa.logotipo = None |
|||
CasaLegislativaTabelaAuxForm( |
|||
request.POST, |
|||
request.FILES, |
|||
instance=casa |
|||
).save() |
|||
else: |
|||
form.save() |
|||
|
|||
# Invalida cache de consulta |
|||
get_casalegislativa.cache_clear() |
|||
|
|||
return self.form_valid(form) |
|||
else: |
|||
return self.render_to_response({'form': form}) |
|||
class HelpView(TemplateView): |
|||
# XXX treat non existing template as a 404!!!! |
|||
|
|||
def get_success_url(self): |
|||
return reverse('base:casa_legislativa') |
|||
def get_template_names(self): |
|||
return ['ajuda/%s.html' % self.kwargs['topic']] |
|||
|
@ -1,8 +0,0 @@ |
|||
{% extends "crud/detail.html" %} |
|||
{% load i18n %} |
|||
{% load crispy_forms_tags %} |
|||
{% block actions %} {% endblock %} |
|||
|
|||
{% block detail_content %} |
|||
{% crispy form %} |
|||
{% endblock detail_content %} |
@ -0,0 +1,38 @@ |
|||
{% extends "crud/list.html" %} |
|||
{% load i18n %} |
|||
|
|||
{% block base_content %} |
|||
{% if not rows %} |
|||
<p>{{ NO_ENTRIES_MSG }}</p> |
|||
<div class="actions btn-group pull-right" role="group"> |
|||
<a href="{{ view.create_url }}" class="btn btn-default"> |
|||
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %} |
|||
</a> |
|||
</div> |
|||
{% else %} |
|||
<table class="table table-striped table-hover"> |
|||
<thead> |
|||
<tr> |
|||
{% for name in headers %} |
|||
<th>{{ name }}</th> |
|||
{% endfor %} |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
{% for value_list in rows %} |
|||
<tr> |
|||
{% for value, href in value_list %} |
|||
<td> |
|||
{% if href %} |
|||
<a href="{{ href }}">{{ value }}</a> |
|||
{% else %} |
|||
{{ value|safe }} |
|||
{% endif %} |
|||
</td> |
|||
{% endfor %} |
|||
</tr> |
|||
{% endfor %} |
|||
</tbody> |
|||
</table> |
|||
{% endif %} |
|||
{% endblock %} |
Loading…
Reference in new issue