diff --git a/base/migrations/0007_auto_20160107_1837.py b/base/migrations/0007_auto_20160107_1837.py new file mode 100644 index 000000000..9c102a411 --- /dev/null +++ b/base/migrations/0007_auto_20160107_1837.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import base.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0006_auto_20160107_1257'), + ] + + operations = [ + migrations.AlterField( + model_name='casalegislativa', + name='informacao_geral', + field=models.CharField(blank=True, max_length=100, verbose_name='Informação Geral', null=True), + ), + migrations.AlterField( + model_name='casalegislativa', + name='logotipo', + field=models.ImageField(blank=True, upload_to=base.models.get_casa_media_path, verbose_name='Logotipo', null=True), + ), + ] diff --git a/base/models.py b/base/models.py index de8105776..dad967e61 100644 --- a/base/models.py +++ b/base/models.py @@ -2,11 +2,10 @@ from django.db import models 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) + return './casa/%s/%s/%s' % (instance.codigo, 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): @@ -22,7 +21,7 @@ class CasaLegislativa(models.Model): uf = models.CharField(max_length=100, verbose_name=_('UF')) telefone = models.CharField(max_length=100, blank=True, null=True, verbose_name=_('Telefone')) fax = models.CharField(max_length=100, blank=True, null=True, verbose_name=_('Fax')) - logotipo = models.FileField( + logotipo = models.ImageField( blank=True, null=True, upload_to=get_casa_media_path, diff --git a/base/views.py b/base/views.py index 58138cc16..664b18680 100644 --- a/base/views.py +++ b/base/views.py @@ -1,6 +1,6 @@ import sapl from crispy_forms.helper import FormHelper -from crispy_forms.layout import ButtonHolder, Fieldset, Layout, Submit +from crispy_forms.layout import ButtonHolder, HTML, Fieldset, Layout, Submit from django import forms from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse @@ -11,6 +11,8 @@ from vanilla import GenericView from .models import CasaLegislativa +from sapl import settings + class HelpView(TemplateView): # XXX treat non existing template as a 404!!!! @@ -76,7 +78,7 @@ class CasaLegislativaTabelaAuxForm(ModelForm): fax = forms.CharField(label='Fax', required=False, widget=forms.TextInput( - attrs={'class': 'telefone'})) + attrs={'class': 'telefone'})) class Meta: @@ -135,6 +137,10 @@ class CasaLegislativaTabelaAuxForm(ModelForm): row3, row4, row5, + HTML("""{% if form.logotipo.value %} + + {% endif %}""", ), row6, row7, row8, @@ -162,7 +168,7 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView): return self.render_to_response({'form': form}) def post(self, request, *args, **kwargs): - form = CasaLegislativaTabelaAuxForm(request.POST or request.FILES) + form = CasaLegislativaTabelaAuxForm(request.POST, request.FILES) if form.is_valid(): try: @@ -171,13 +177,8 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView): 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() - + request.POST, request.FILES, instance=casa).save(commit=False) + casa_save.save() return self.form_valid(form) else: return self.render_to_response({'form': form}) diff --git a/sapl/settings.py b/sapl/settings.py index 7e4f81b1a..f9f2c7639 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -86,6 +86,8 @@ TEMPLATES = [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', + "django.core.context_processors.media", + "django.core.context_processors.static", 'django.contrib.messages.context_processors.messages', 'sapl.context_processors.parliament_info', ], @@ -94,6 +96,7 @@ TEMPLATES = [ }, ] + WSGI_APPLICATION = 'sapl.wsgi.application' # Database @@ -139,6 +142,7 @@ STATICFILES_FINDERS = ( ) MEDIA_ROOT = BASE_DIR.child("media") +MEDIA_URL = '/media/' DAB_FIELD_RENDERER = \ 'django_admin_bootstrapped.renderers.BootstrapFieldRenderer' diff --git a/sessao/urls.py b/sessao/urls.py index 237453faa..13624b8b9 100644 --- a/sessao/urls.py +++ b/sessao/urls.py @@ -17,6 +17,8 @@ from sessao.views import (EditExpedienteOrdemDiaView, EditMateriaOrdemDiaView, VotacaoView, sessao_crud, tipo_expediente_crud, tipo_resultado_votacao_crud, tipo_sessao_crud) +from sapl import settings + urlpatterns_sessao = sessao_crud.urlpatterns + [ url(r'^(?P\d+)/expediente$', ExpedienteView.as_view(), name='expediente'), @@ -87,14 +89,16 @@ urlpatterns_sessao = sessao_crud.urlpatterns + [ PautaSessaoListView.as_view(), name='list_pauta_sessao'), url(r'^(?P\d+)/pauta-sessao-detail$', PautaSessaoDetailView.as_view(), name='pauta_sessao_detail'), - url(r'^cadastro$', SessaoCadastroView.as_view(), name='sessao_cadastro') + url(r'^cadastro$', SessaoCadastroView.as_view(), name='sessao_cadastro'), ] sessao_urls = urlpatterns_sessao, sessao_crud.namespace, sessao_crud.namespace urlpatterns = [ url(r'^sessao/', include(urlpatterns_sessao, sessao_crud.namespace, sessao_crud.namespace)), - url(r'^sistema/sessao-plenaria/tipo/', include(tipo_sessao_crud.urls)), + url(r'^media/(?P.*)$', 'django.views.static.serve', + {'document_root': settings.MEDIA_ROOT}), + url(r'^sistema/sessao-plenaria/tipo/', include(tipo_sessao_crud.urls)), url(r'^sistema/sessao-plenaria/tipo-resultado-votacao/', include(tipo_resultado_votacao_crud.urls)), url(r'^sistema/sessao-plenaria/tipo-expediente/',