Browse Source

Merge pull request #313 from interlegis/288-Preview-da-foto

Fix #288 Preview de Imagem em Parlamentar e Casa Legislativa
pull/336/head
Edward 9 years ago
parent
commit
b0fb734d6e
  1. 19
      parlamentares/forms.py
  2. 5
      parlamentares/views.py
  3. 21
      requirements/dev-requirements.txt
  4. 2
      sapl/settings.py
  5. BIN
      static/img/perfil.png
  6. 64
      templates/floppyforms/image_thumbnail.html

19
parlamentares/forms.py

@ -4,6 +4,7 @@ from django import forms
from django.db import transaction from django.db import transaction
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from floppyforms import ClearableFileInput
import crispy_layout_mixin import crispy_layout_mixin
from crispy_layout_mixin import form_actions from crispy_layout_mixin import form_actions
@ -11,7 +12,19 @@ from crispy_layout_mixin import form_actions
from .models import Dependente, Filiacao, Legislatura, Mandato, Parlamentar from .models import Dependente, Filiacao, Legislatura, Mandato, Parlamentar
class ParlamentarCreateForm(ModelForm): class ImageThumbnailFileInput(ClearableFileInput):
template_name = 'floppyforms/image_thumbnail.html'
class ParlamentarForm(ModelForm):
class Meta:
model = Parlamentar
exclude = []
widgets = {'fotografia': ImageThumbnailFileInput}
class ParlamentarCreateForm(ParlamentarForm):
legislatura = forms.ModelChoiceField( legislatura = forms.ModelChoiceField(
label=_('Legislatura'), label=_('Legislatura'),
@ -25,10 +38,6 @@ class ParlamentarCreateForm(ModelForm):
required=True, required=True,
) )
class Meta:
model = Parlamentar
exclude = []
@transaction.atomic @transaction.atomic
def save(self, commit=True): def save(self, commit=True):
parlamentar = super(ParlamentarCreateForm, self).save(commit) parlamentar = super(ParlamentarCreateForm, self).save(commit)

5
parlamentares/views.py

@ -11,7 +11,7 @@ from crud.base import Crud
from .forms import (DependenteEditForm, DependenteForm, FiliacaoEditForm, from .forms import (DependenteEditForm, DependenteForm, FiliacaoEditForm,
FiliacaoForm, MandatoEditForm, MandatoForm, FiliacaoForm, MandatoEditForm, MandatoForm,
ParlamentarCreateForm) ParlamentarCreateForm, ParlamentarForm)
from .models import (CargoMesa, Coligacao, ComposicaoMesa, Dependente, from .models import (CargoMesa, Coligacao, ComposicaoMesa, Dependente,
Filiacao, Legislatura, Mandato, NivelInstrucao, Filiacao, Legislatura, Mandato, NivelInstrucao,
Parlamentar, Partido, SessaoLegislativa, SituacaoMilitar, Parlamentar, Partido, SessaoLegislativa, SituacaoMilitar,
@ -35,6 +35,9 @@ class ParlamentarCrud(Crud):
model = Parlamentar model = Parlamentar
help_path = '' help_path = ''
class UpdateView(crud.base.CrudUpdateView):
form_class = ParlamentarForm
class CreateView(crud.base.CrudCreateView): class CreateView(crud.base.CrudCreateView):
form_class = ParlamentarCreateForm form_class = ParlamentarCreateForm

21
requirements/dev-requirements.txt

@ -1,10 +1,13 @@
-r test-requirements.txt -r test-requirements.txt
autopep8 autopep8==1.2.2
beautifulsoup4 beautifulsoup4==4.4.1
django-debug-toolbar django-debug-toolbar==1.4
django-extensions django-extensions==1.6.1
flake8 django-floppyforms==1.6.1
ipdb easy-thumbnails==2.3
isort flake8==2.5.4
pygraphviz ipdb==0.9.0
pytest-ipdb==0.1-prerelease2 # nao instala sem fixar a versao isort==4.2.2
pygraphviz==1.3rc2
pytest-ipdb==0.1-prerelease2

2
sapl/settings.py

@ -59,6 +59,8 @@ INSTALLED_APPS = (
'djangobower', 'djangobower',
'bootstrap3', # basically for django_admin_bootstrapped 'bootstrap3', # basically for django_admin_bootstrapped
'crispy_forms', 'crispy_forms',
'easy_thumbnails',
'floppyforms',
'sass_processor', 'sass_processor',
'rest_framework', 'rest_framework',

BIN
static/img/perfil.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

64
templates/floppyforms/image_thumbnail.html

@ -0,0 +1,64 @@
{% load i18n staticfiles thumbnail %}
<div id="div_{{ field.auto_id }}"
class="control-group
{% if form_show_errors %}
{% if field.errors %} error{% endif %}
{% endif %}
{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
{% if field.label %}
<label for="{{ field.id_for_label }}"
class="control-label
{{ label_class }}
{% if field.field.required %}
requiredField
{% endif %}">
{{ field.label|safe }}{% if field.field.required %}
<span class="asteriskField">*</span>{% endif %}
</label>
{% endif %}
<div class="controls {{ field_class }}">
<div class="fileupload fileupload-new"
data-provides="fileupload">
{% if value.url %}
<div class="row">
<div class="col-md-12">
<img src="{{ value.url }}"
alt="{{ value }}" class="img-thumbnail"/>
</div>
</div>
<div class="row">
<div class="col-md-12">
<input type="checkbox"
name="{{ checkbox_name }}"
id="{{ checkbox_id }}" />
<label for="{{ checkbox_id }}">
{% trans "Clear" %}
</label>
</div>
</div>
{% else %}
<div class="row">
<div class="col-md-12">
<img src="{% static 'img/perfil.png' %}""
class="img-thumbnail"/>
</div>
</div>
{% endif %}
<div>
<br />
<div class="form-inline">
<input type="{{ type }}" name="{{ name }}"
{% if required %}required{% endif %}
class="filestyle"
data-icon="false"
data-classButton="btn btn-default"
data-classInput="form-control">
</div>
</div>
</div>
{% include 'bootstrap3/layout/help_text_and_errors.html' %}
</div>
</div>
Loading…
Cancel
Save