Browse Source

Adiciona preview de foto na adição e edição de parlamentar

pull/313/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
committed by Edward Ribeiro
parent
commit
cc8315e5b7
  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.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from floppyforms import ClearableFileInput
import crispy_layout_mixin
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
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(
label=_('Legislatura'),
@ -25,10 +38,6 @@ class ParlamentarCreateForm(ModelForm):
required=True,
)
class Meta:
model = Parlamentar
exclude = []
@transaction.atomic
def save(self, commit=True):
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,
FiliacaoForm, MandatoEditForm, MandatoForm,
ParlamentarCreateForm)
ParlamentarCreateForm, ParlamentarForm)
from .models import (CargoMesa, Coligacao, ComposicaoMesa, Dependente,
Filiacao, Legislatura, Mandato, NivelInstrucao,
Parlamentar, Partido, SessaoLegislativa, SituacaoMilitar,
@ -35,6 +35,9 @@ class ParlamentarCrud(Crud):
model = Parlamentar
help_path = ''
class UpdateView(crud.base.CrudUpdateView):
form_class = ParlamentarForm
class CreateView(crud.base.CrudCreateView):
form_class = ParlamentarCreateForm

21
requirements/dev-requirements.txt

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

2
sapl/settings.py

@ -59,6 +59,8 @@ INSTALLED_APPS = (
'djangobower',
'bootstrap3', # basically for django_admin_bootstrapped
'crispy_forms',
'easy_thumbnails',
'floppyforms',
'sass_processor',
'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