Browse Source

Change fields to add mask

pull/98/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
744582853f
  1. 40
      base/views.py
  2. 2
      templates/base.html

40
base/views.py

@ -1,17 +1,16 @@
import sapl import sapl
from crispy_forms.helper import FormHelper
from django.views.generic.base import TemplateView from crispy_forms.layout import ButtonHolder, Fieldset, Layout, Submit
from .models import CasaLegislativa
from django.forms import ModelForm
from django import forms from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.forms import ModelForm
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from vanilla import GenericView 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 from .models import CasaLegislativa
class HelpView(TemplateView): class HelpView(TemplateView):
# XXX treat non existing template as a 404!!!! # XXX treat non existing template as a 404!!!!
@ -54,14 +53,29 @@ class CasaLegislativaTabelaAuxForm(ModelForm):
uf = forms.ChoiceField(required=False, uf = forms.ChoiceField(required=False,
label='UF', label='UF',
choices=[(a,a) for a in ESTADOS], choices=[(a, a) for a in ESTADOS],
widget=forms.Select( widget=forms.Select(
attrs={'class': 'selector'})) attrs={'class': 'selector'}))
informacao_geral = forms.CharField(widget=forms.Textarea, informacao_geral = forms.CharField(widget=forms.Textarea,
label='informacao_geral', label='informacao_geral',
required=True) required=True)
telefone = forms.CharField(label='Telefone',
required=True,
widget=forms.TextInput(
attrs={'class': 'telefone'}))
cep = forms.CharField(label='Cep',
required=True,
widget=forms.TextInput(
attrs={'class': 'cep'}))
fax = forms.CharField(label='Fax',
required=True,
widget=forms.TextInput(
attrs={'class': 'telefone'}))
class Meta: class Meta:
model = CasaLegislativa model = CasaLegislativa
@ -130,6 +144,7 @@ class CasaLegislativaTabelaAuxForm(ModelForm):
) )
super(CasaLegislativaTabelaAuxForm, self).__init__(*args, **kwargs) super(CasaLegislativaTabelaAuxForm, self).__init__(*args, **kwargs)
class CasaLegislativaTableAuxView(FormMixin, GenericView): class CasaLegislativaTableAuxView(FormMixin, GenericView):
template_name = "base/casa_leg_table_aux.html" template_name = "base/casa_leg_table_aux.html"
@ -153,7 +168,8 @@ class CasaLegislativaTableAuxView(FormMixin, GenericView):
except ObjectDoesNotExist: except ObjectDoesNotExist:
casa_save = form.save(commit=False) casa_save = form.save(commit=False)
else: else:
casa_save = CasaLegislativaTabelaAuxForm(request.POST, instance = casa) casa_save = CasaLegislativaTabelaAuxForm(
request.POST, instance=casa)
if 'logotipo' in request.FILES: if 'logotipo' in request.FILES:
casa_save.logotipo = request.FILES['logotipo'] casa_save.logotipo = request.FILES['logotipo']

2
templates/base.html

@ -225,7 +225,7 @@
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
$('.telefone').mask("(99) 9999-9999", {placeholder:"(__)____ -____"}); $('.telefone').mask("(99) 9999-9999", {placeholder:"(__) ____ -____"});
$('.cpf').mask("000.000.000-00", {placeholder:"___.___.___-__"}); $('.cpf').mask("000.000.000-00", {placeholder:"___.___.___-__"});
$('.cep').mask("00000-000", {placeholder:"_____-___"}); $('.cep').mask("00000-000", {placeholder:"_____-___"});
}); });

Loading…
Cancel
Save