Browse Source

corrigindo erros do formulario de conpetencias

diagnosticos
Felipe Vieira 13 years ago
parent
commit
0fe6eeea5d
  1. 26
      media/css/diagnosticos/diagnosticos_categoria_model_form.css
  2. 4
      sigi/apps/casas/models.py
  3. 4
      sigi/apps/contatos/models.py
  4. 20
      sigi/apps/diagnosticos/forms.py
  5. 8
      sigi/apps/diagnosticos/views.py
  6. 10
      sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html
  7. 7
      sigi/templates/diagnosticos/diagnosticos_login.html

26
media/css/diagnosticos/diagnosticos_categoria_model_form.css

@ -1,4 +1,28 @@
label.attr { label.attr {
display: inline-block; 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;
}

4
sigi/apps/casas/models.py

@ -93,8 +93,8 @@ class Funcionario(models.Model):
casa_legislativa = models.ForeignKey(CasaLegislativa) casa_legislativa = models.ForeignKey(CasaLegislativa)
nome = models.CharField('nome completo', max_length=60, blank=True) nome = models.CharField('nome completo', max_length=60, blank=True)
nome.alphabetic_filter = True nome.alphabetic_filter = True
nota = models.CharField(max_length=70, blank=True) nota = models.CharField(max_length=70, null=True, blank=True)
email = models.EmailField('e-mail', blank=True) email = models.EmailField('e-mail', null=True, blank=True)
telefones = generic.GenericRelation('contatos.Telefone') telefones = generic.GenericRelation('contatos.Telefone')
endereco = generic.GenericRelation('contatos.Endereco') endereco = generic.GenericRelation('contatos.Endereco')
cargo = models.CharField(max_length=100, null=True, blank=True) cargo = models.CharField(max_length=100, null=True, blank=True)

4
sigi/apps/contatos/models.py

@ -120,6 +120,7 @@ class Telefone(models.Model):
'código de área', 'código de área',
max_length=4, max_length=4,
help_text='Exemplo: <em>31</em>.', help_text='Exemplo: <em>31</em>.',
null=True,
blank=True blank=True
) )
numero = models.CharField( numero = models.CharField(
@ -130,8 +131,9 @@ class Telefone(models.Model):
tipo = models.CharField( tipo = models.CharField(
max_length=1, max_length=1,
choices=TELEFONE_CHOICES, 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 # guarda o tipo do objeto (classe) vinculado a esse registro
content_type = models.ForeignKey(ContentType) content_type = models.ForeignKey(ContentType)

20
sigi/apps/diagnosticos/forms.py

@ -3,7 +3,9 @@
from copy import deepcopy from copy import deepcopy
from django import forms from django import forms
from django.forms.forms import BoundField 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.casas.models import CasaLegislativa, Funcionario
from sigi.apps.contatos.models import Telefone
from sigi.apps.diagnosticos.models import Diagnostico from sigi.apps.diagnosticos.models import Diagnostico
from eav.forms import BaseDynamicEntityForm from eav.forms import BaseDynamicEntityForm
@ -91,8 +93,26 @@ class CasaLegislativaMobileForm(forms.ModelForm):
model = CasaLegislativa model = CasaLegislativa
fields = ('cnpj', 'logradouro', 'bairro', 'cep', 'email', 'pagina_web') fields = ('cnpj', 'logradouro', 'bairro', 'cep', 'email', 'pagina_web')
class TelefoneMobileForm(forms.ModelForm):
pass
class Meta:
model = Telefone
fields = ('numero', 'tipo')
class FuncionariosMobileForm(forms.ModelForm): 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: class Meta:
model = Funcionario model = Funcionario
fields = ('nome', 'email', 'cargo', 'funcao', 'tempo_de_servico') fields = ('nome', 'email', 'cargo', 'funcao', 'tempo_de_servico')

8
sigi/apps/diagnosticos/views.py

@ -11,6 +11,7 @@ from sigi.apps.diagnosticos.forms import (DiagnosticoMobileForm,
CasaLegislativaMobileForm, FuncionariosMobileForm) CasaLegislativaMobileForm, FuncionariosMobileForm)
@cache_page(5)
@login_required(login_url='/mobile/diagnosticos/login') @login_required(login_url='/mobile/diagnosticos/login')
def lista(request): def lista(request):
"""Consulta os diagnosticos do servidor logado, """Consulta os diagnosticos do servidor logado,
@ -26,6 +27,7 @@ def lista(request):
return render_to_response('diagnosticos/diagnosticos_list.html', context) return render_to_response('diagnosticos/diagnosticos_list.html', context)
@cache_page(5)
@login_required(login_url='/mobile/diagnosticos/login') @login_required(login_url='/mobile/diagnosticos/login')
def categorias(request, id_diagnostico): def categorias(request, id_diagnostico):
"""Consulta as categorias do diagnostico selecionado """Consulta as categorias do diagnostico selecionado
@ -109,8 +111,10 @@ def categoria_contatos(request, id_diagnostico):
if request.method == "POST": if request.method == "POST":
forms = [FuncionariosMobileForm( forms = [FuncionariosMobileForm(
request.POST, prefix=f.setor, instance=f) for f, c in funcionarios] 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() form.save()
else: else:
forms = [FuncionariosMobileForm(prefix=f.setor, instance=f) forms = [FuncionariosMobileForm(prefix=f.setor, instance=f)

10
sigi/templates/diagnosticos/diagnosticos_categoria_contatos_form.html

@ -27,6 +27,16 @@
{{ field }} {{ field }}
</div> </div>
{% endfor %} {% endfor %}
<h4>Telefones</h4>
{% for form in form.telefones.forms %}
<div class="phone" data-role="fieldcontain">
{{ form.tipo }} {{ form.numero}}
{% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
</div>
{% endfor %}
{{ form.telefones.management_form }}
<hr/> <hr/>
{% endfor %} {% endfor %}
</form> </form>

7
sigi/templates/diagnosticos/diagnosticos_login.html

@ -6,6 +6,12 @@
<title>SIGI - Login de Acesso</title> <title>SIGI - Login de Acesso</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" /> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script language=javascript>
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
$.mobile.loadingMessage = 'salvando';
});
</script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script> <script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head> </head>
<body> <body>
@ -28,6 +34,7 @@
<div data-role="content"> <div data-role="content">
<form action="{% url django.contrib.auth.views.login %}" method="POST"> <form action="{% url django.contrib.auth.views.login %}" method="POST">
{% csrf_token %}
<div data-role="fieldcontain" class="ui-hide-label ui-body"> <div data-role="fieldcontain" class="ui-hide-label ui-body">
<label for="username">Usuário:</label> <label for="username">Usuário:</label>
<input type="text" name="username" id="id_username" placeholder="Usuário"> <input type="text" name="username" id="id_username" placeholder="Usuário">

Loading…
Cancel
Save