diff --git a/media/css/diagnosticos/diagnosticos_categoria_model_form.css b/media/css/diagnosticos/diagnosticos_categoria_model_form.css index 99e381c..5b67b25 100644 --- a/media/css/diagnosticos/diagnosticos_categoria_model_form.css +++ b/media/css/diagnosticos/diagnosticos_categoria_model_form.css @@ -1,4 +1,28 @@ label.attr { display: inline-block; - width: 100px; + width: 30%; } + +div.ui-field-contain input.ui-input-text, .ui-field-contain textarea.ui-input-text, .ui-field-contain .ui-input-search { + width: 65%; +} +div.ui-field-contain.phone .ui-select { + width: 30%; + float: left; + margin: -0.5em 0; +} + +div.ui-field-contain.phone .ui-select .ui-btn-text { + text: left; + padding-left: 0.2em; +} + +div.ui-field-contain.phone .ui-select .ui-btn { + margin: 0.5em 10px 0.5em 0px; +} + +div.ui-field-contain.phone .ui-select .ui-btn-inner { + padding-left: 15px; +} + + diff --git a/sigi/apps/casas/models.py b/sigi/apps/casas/models.py index 9260973..81de46d 100644 --- a/sigi/apps/casas/models.py +++ b/sigi/apps/casas/models.py @@ -93,8 +93,8 @@ class Funcionario(models.Model): casa_legislativa = models.ForeignKey(CasaLegislativa) nome = models.CharField('nome completo', max_length=60, blank=True) nome.alphabetic_filter = True - nota = models.CharField(max_length=70, blank=True) - email = models.EmailField('e-mail', blank=True) + nota = models.CharField(max_length=70, null=True, blank=True) + email = models.EmailField('e-mail', null=True, blank=True) telefones = generic.GenericRelation('contatos.Telefone') endereco = generic.GenericRelation('contatos.Endereco') cargo = models.CharField(max_length=100, null=True, blank=True) diff --git a/sigi/apps/contatos/models.py b/sigi/apps/contatos/models.py index 286c9d4..b13e080 100644 --- a/sigi/apps/contatos/models.py +++ b/sigi/apps/contatos/models.py @@ -120,6 +120,7 @@ class Telefone(models.Model): 'código de área', max_length=4, help_text='Exemplo: 31.', + null=True, blank=True ) numero = models.CharField( @@ -130,8 +131,9 @@ class Telefone(models.Model): tipo = models.CharField( max_length=1, choices=TELEFONE_CHOICES, + default= 'I' ) - nota = models.CharField(max_length=70, blank=True) + nota = models.CharField(max_length=70, null=True, blank=True) # guarda o tipo do objeto (classe) vinculado a esse registro content_type = models.ForeignKey(ContentType) diff --git a/sigi/apps/diagnosticos/forms.py b/sigi/apps/diagnosticos/forms.py index 9118829..0f9f9d1 100644 --- a/sigi/apps/diagnosticos/forms.py +++ b/sigi/apps/diagnosticos/forms.py @@ -3,7 +3,9 @@ from copy import deepcopy from django import forms from django.forms.forms import BoundField +from django.contrib.contenttypes.generic import generic_inlineformset_factory from sigi.apps.casas.models import CasaLegislativa, Funcionario +from sigi.apps.contatos.models import Telefone from sigi.apps.diagnosticos.models import Diagnostico from eav.forms import BaseDynamicEntityForm @@ -91,8 +93,26 @@ class CasaLegislativaMobileForm(forms.ModelForm): model = CasaLegislativa fields = ('cnpj', 'logradouro', 'bairro', 'cep', 'email', 'pagina_web') +class TelefoneMobileForm(forms.ModelForm): + pass + class Meta: + model = Telefone + fields = ('numero', 'tipo') class FuncionariosMobileForm(forms.ModelForm): + TelefoneFormSet = generic_inlineformset_factory(Telefone, TelefoneMobileForm, extra=1, can_delete=False) + + def __init__(self, data=None, prefix=None, instance=None, *args, **kwargs): + super(FuncionariosMobileForm, self).__init__(data, prefix=prefix, instance=instance, *args, **kwargs) + self.telefones = self.TelefoneFormSet(data, prefix=prefix, instance=instance) + + def is_valid(self): + return self.telefones.is_valid() and super(FuncionariosMobileForm, self).is_valid() + + def save(self, commit=True): + self.telefones.save(commit) + return super(FuncionariosMobileForm, self).save(commit) + class Meta: model = Funcionario fields = ('nome', 'email', 'cargo', 'funcao', 'tempo_de_servico') diff --git a/sigi/apps/diagnosticos/views.py b/sigi/apps/diagnosticos/views.py index a89bdfb..4840f7c 100644 --- a/sigi/apps/diagnosticos/views.py +++ b/sigi/apps/diagnosticos/views.py @@ -11,6 +11,7 @@ from sigi.apps.diagnosticos.forms import (DiagnosticoMobileForm, CasaLegislativaMobileForm, FuncionariosMobileForm) +@cache_page(5) @login_required(login_url='/mobile/diagnosticos/login') def lista(request): """Consulta os diagnosticos do servidor logado, @@ -26,6 +27,7 @@ def lista(request): return render_to_response('diagnosticos/diagnosticos_list.html', context) +@cache_page(5) @login_required(login_url='/mobile/diagnosticos/login') def categorias(request, id_diagnostico): """Consulta as categorias do diagnostico selecionado @@ -109,8 +111,10 @@ def categoria_contatos(request, id_diagnostico): if request.method == "POST": forms = [FuncionariosMobileForm( request.POST, prefix=f.setor, instance=f) for f, c in funcionarios] - if all([form.is_valid() for form in forms]): - for form in forms: + + # valida e salva um formulario por vez + for form in forms: + if form.is_valid(): form.save() else: forms = [FuncionariosMobileForm(prefix=f.setor, instance=f) diff --git a/sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html b/sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html index 24b883a..f8381cf 100644 --- a/sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html +++ b/sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html @@ -27,6 +27,16 @@ {{ field }} {% endfor %} +