Browse Source

#43 Atestar convênio e responsável

pull/6/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
committed by Luciano Almeida
parent
commit
f82e4af987
  1. 7
      sigi/apps/home/templatetags/menu_conf.yaml
  2. 1
      sigi/apps/solicitacoes/layouts.yaml
  3. 56
      sigi/apps/usuarios/forms.py
  4. 29
      sigi/apps/usuarios/migrations/0007_auto_20160628_1609.py
  5. 31
      sigi/apps/usuarios/migrations/0008_atesto.py
  6. 21
      sigi/apps/usuarios/migrations/0009_usuario_atesto_conveniado.py
  7. 45
      sigi/apps/usuarios/migrations/0010_auto_20160629_1448.py
  8. 31
      sigi/apps/usuarios/models.py
  9. 19
      sigi/apps/usuarios/urls.py
  10. 113
      sigi/apps/usuarios/views.py
  11. 24
      templates/usuarios/convenio.html
  12. 24
      templates/usuarios/convenio_list.html
  13. 33
      templates/usuarios/responsavel.html
  14. 26
      templates/usuarios/responsavel_list.html

7
sigi/apps/home/templatetags/menu_conf.yaml

@ -123,3 +123,10 @@ main_menu:
url: saberes/dashboard/cursos-sem-turoria/ url: saberes/dashboard/cursos-sem-turoria/
- title: Cursos com Tutoria - title: Cursos com Tutoria
url: saberes/dashboard/cursos-com-turoria/ url: saberes/dashboard/cursos-com-turoria/
- title: Atesto
url: '/'
children:
- title: Convênio
url: convenio
- title: Responsável
url: responsavel

1
sigi/apps/solicitacoes/layouts.yaml

@ -6,7 +6,6 @@ Sistema:
Solicitacao: Solicitacao:
Solicitação: Solicitação:
- codigo
- usuario - usuario
- sistema - sistema
- casa_legislativa - casa_legislativa

56
sigi/apps/usuarios/forms.py

@ -5,7 +5,7 @@ from datetime import datetime
from captcha.fields import CaptchaField from captcha.fields import CaptchaField
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import Fieldset, Layout, Submit from crispy_forms.layout import HTML, Fieldset, Layout, Submit
from django import forms from django import forms
from django.contrib.auth.forms import (AuthenticationForm, PasswordResetForm, from django.contrib.auth.forms import (AuthenticationForm, PasswordResetForm,
SetPasswordForm) SetPasswordForm)
@ -25,6 +25,60 @@ from sigi.apps.crud.utils import YES_NO_CHOICES
from .models import Telefone, Usuario from .models import Telefone, Usuario
class ResponsavelForm(ModelForm):
responsavel = forms.TypedChoiceField(
widget=forms.Select(),
label=_(u'Responsavel?'),
choices=YES_NO_CHOICES)
class Meta(object):
model = Usuario
fields = ['responsavel']
def __init__(self, *args, **kwargs):
super(ResponsavelForm, self).__init__(*args, **kwargs)
row1 = sigi.apps.crispy_layout_mixin.to_row([(u'responsavel', 12)])
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(_(u'Atestar Responsável'),
HTML(u'''<p align="center"><font size="4" color="red">
Ao atestar a responsabilidade deste convênio você
estará assumindo responsabilidade por qualquer
problema que poderá ocorrer pela existência de dados
incorretos.</font></p>'''),
row1,
form_actions(
save_label='Atestar')))
class ConveniadoForm(ModelForm):
conveniado = forms.TypedChoiceField(
widget=forms.Select(),
label=_(u'Conveniado?'),
choices=YES_NO_CHOICES)
class Meta(object):
model = Usuario
fields = ['conveniado']
def __init__(self, *args, **kwargs):
super(ConveniadoForm, self).__init__(*args, **kwargs)
row1 = sigi.apps.crispy_layout_mixin.to_row([(u'conveniado', 12)])
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(_(u'Atestar Conveniado'),
HTML(u'''<p align="center"><font size="4" color="red">
Ao atestar o convênio deste usuário você estará
assumindo resonsabilidade por qualquer problema
que poderá ocorrer pela existência de dados
incorretos.</font></p>'''),
row1,
form_actions(
save_label='Atestar')))
class LoginForm(AuthenticationForm): class LoginForm(AuthenticationForm):
username = forms.CharField( username = forms.CharField(
label=u"Username", max_length=30, label=u"Username", max_length=30,

29
sigi/apps/usuarios/migrations/0007_auto_20160628_1609.py

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-28 16:09
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('usuarios', '0006_remove_usuario_search_text'),
]
operations = [
migrations.RemoveField(
model_name='usuario',
name='habilitado',
),
migrations.AlterField(
model_name='usuario',
name='conveniado',
field=models.BooleanField(default=False, verbose_name='Conveniado?'),
),
migrations.AlterField(
model_name='usuario',
name='responsavel',
field=models.BooleanField(default=False, verbose_name='Rspons\xe1vel?'),
),
]

31
sigi/apps/usuarios/migrations/0008_atesto.py

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-29 13:56
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('usuarios', '0007_auto_20160628_1609'),
]
operations = [
migrations.CreateModel(
name='Atesto',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('data', models.DateTimeField(default=django.utils.timezone.now)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Atesto',
'verbose_name_plural': 'Atestos',
},
),
]

21
sigi/apps/usuarios/migrations/0009_usuario_atesto_conveniado.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-29 13:57
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('usuarios', '0008_atesto'),
]
operations = [
migrations.AddField(
model_name='usuario',
name='atesto_conveniado',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='usuarios.Atesto'),
),
]

45
sigi/apps/usuarios/migrations/0010_auto_20160629_1448.py

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-29 14:48
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('usuarios', '0009_usuario_atesto_conveniado'),
]
operations = [
migrations.CreateModel(
name='AtestoConvenio',
fields=[
('atesto_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='usuarios.Atesto')),
],
bases=('usuarios.atesto',),
),
migrations.CreateModel(
name='AtestoResponsavel',
fields=[
('atesto_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='usuarios.Atesto')),
],
bases=('usuarios.atesto',),
),
migrations.AlterField(
model_name='usuario',
name='atesto_conveniado',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='usuarios.AtestoConvenio'),
),
migrations.AlterField(
model_name='usuario',
name='responsavel',
field=models.BooleanField(default=False, verbose_name='Respons\xe1vel?'),
),
migrations.AddField(
model_name='usuario',
name='atesto_responsavel',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='usuarios.AtestoResponsavel'),
),
]

31
sigi/apps/usuarios/models.py

@ -64,6 +64,23 @@ class ConfirmaEmail(models.Model):
verbose_name_plural = _(u'Emails') verbose_name_plural = _(u'Emails')
class Atesto(models.Model):
user = models.ForeignKey(User)
data = models.DateTimeField(default=timezone.now)
class Meta(object):
verbose_name = _(u'Atesto')
verbose_name_plural = _(u'Atestos')
class AtestoResponsavel(Atesto):
pass
class AtestoConvenio(Atesto):
pass
class Usuario(models.Model): class Usuario(models.Model):
u''' u'''
Usuário cadastrado via web Usuário cadastrado via web
@ -89,11 +106,6 @@ class Usuario(models.Model):
email = email = models.EmailField(unique=True, verbose_name=_(u'Email')) email = email = models.EmailField(unique=True, verbose_name=_(u'Email'))
email_confirmado = models.BooleanField( email_confirmado = models.BooleanField(
default=False, verbose_name=_(u'Email confirmado?')) default=False, verbose_name=_(u'Email confirmado?'))
habilitado = models.BooleanField(
default=False,
verbose_name=_(u'Habilitado?'))
conveniado = models.BooleanField(default=False)
responsavel = models.BooleanField(default=False)
rg = models.CharField( rg = models.CharField(
max_length=9, max_length=9,
null=True, null=True,
@ -121,6 +133,15 @@ class Usuario(models.Model):
verbose_name=_(u'Casa Legislativa') verbose_name=_(u'Casa Legislativa')
) )
responsavel = models.BooleanField(
default=False,
verbose_name=_(u'Responsável?'))
conveniado = models.BooleanField(
default=False,
verbose_name=_(u'Conveniado?'))
atesto_conveniado = models.ForeignKey(AtestoConvenio, null=True)
atesto_responsavel = models.ForeignKey(AtestoResponsavel, null=True)
class Meta(object): class Meta(object):
verbose_name = _(u'Usuário') verbose_name = _(u'Usuário')
verbose_name_plural = _(u'Usuários') verbose_name_plural = _(u'Usuários')

19
sigi/apps/usuarios/urls.py

@ -9,15 +9,17 @@ from django.views.generic.base import TemplateView
from sigi.apps.usuarios.forms import (LoginForm, RecuperacaoMudarSenhaForm, from sigi.apps.usuarios.forms import (LoginForm, RecuperacaoMudarSenhaForm,
RecuperarSenhaEmailForm) RecuperarSenhaEmailForm)
from sigi.apps.usuarios.views import (ConfirmarEmailView, HabilitarDetailView, from sigi.apps.usuarios.views import (ConfirmarEmailView, ConveniadoListView,
ConveniadoView, HabilitarDetailView,
HabilitarEditView, MudarSenhaView, HabilitarEditView, MudarSenhaView,
ResponsavelListView, ResponsavelView,
UsuarioCrud) UsuarioCrud)
from .apps import AppConfig from .apps import AppConfig
app_name = AppConfig.name app_name = AppConfig.name
EMAIL_SEND_USER='atendimento@interlegis.leg.br' EMAIL_SEND_USER = 'atendimento@interlegis.leg.br'
recuperar_email = [ recuperar_email = [
url(ur'^atendimento/recuperar/recuperar_senha/$', url(ur'^atendimento/recuperar/recuperar_senha/$',
@ -60,6 +62,17 @@ urlpatterns = recuperar_email + [
HabilitarEditView.as_view(), name=u'habilitar_edit'), HabilitarEditView.as_view(), name=u'habilitar_edit'),
url(ur'^atendimento/usuario/(?P<pk>\d+)/mudar_senha$', url(ur'^atendimento/usuario/(?P<pk>\d+)/mudar_senha$',
MudarSenhaView.as_view(), name=u'mudar_senha'), MudarSenhaView.as_view(), name=u'mudar_senha'),
url(ur'^usuario/confirmar/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})$', url(ur'^usuario/confirmar/(?P<uidb64>[0-9A-Za-z_\-]+)/'
'(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})$',
ConfirmarEmailView.as_view(), name=u'confirmar_email'), ConfirmarEmailView.as_view(), name=u'confirmar_email'),
url(ur'^responsavel$', ResponsavelListView.as_view(),
name=u'responsavel_list'),
url(ur'^responsavel/(?P<pk>\d+)/$', ResponsavelView.as_view(),
name=u'responsavel_update'),
url(ur'^convenio$', ConveniadoListView.as_view(),
name=u'convenio_list'),
url(ur'^convenio/(?P<pk>\d+)/$', ConveniadoView.as_view(),
name=u'convenio_update'),
] ]

113
sigi/apps/usuarios/views.py

@ -7,21 +7,126 @@ from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.tokens import default_token_generator from django.contrib.auth.tokens import default_token_generator
from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import send_mail from django.core.mail import send_mail
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils import timezone from django.utils import timezone
from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode
from django.views.generic import DetailView, FormView, TemplateView from django.views.generic import (CreateView, DetailView, FormView, ListView,
TemplateView)
from django.views.generic.edit import FormMixin
from sigi.apps.crud.base import (Crud, CrudBaseMixin, CrudCreateView, from sigi.apps.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDetailView, CrudListView, CrudUpdateView) CrudDetailView, CrudListView, CrudUpdateView)
from sigi.apps.crud.utils import str2bool from sigi.apps.crud.utils import str2bool
from .forms import (HabilitarEditForm, MudarSenhaForm, UsuarioEditForm, from .forms import (ConveniadoForm, HabilitarEditForm, MudarSenhaForm,
UsuarioForm) ResponsavelForm, UsuarioEditForm, UsuarioForm)
from .models import ConfirmaEmail, User, Usuario from .models import (AtestoConvenio, AtestoResponsavel, ConfirmaEmail, User,
Usuario)
class ResponsavelListView(ListView):
template_name = u'usuarios/responsavel_list.html'
model = Usuario
queryset = Usuario.objects.filter(conveniado=True, responsavel=False)
ordering = [u'nome_completo', u'casa_legislativa']
class ConveniadoListView(ListView):
template_name = u'usuarios/convenio_list.html'
model = Usuario
queryset = Usuario.objects.filter(conveniado=False, responsavel=False)
ordering = [u'casa_legislativa']
class ConveniadoView(CreateView):
template_name = u'usuarios/convenio.html'
form_class = ConveniadoForm
def post(self, request, *args, **kwargs):
form = ConveniadoForm(request.POST)
usuario = Usuario.objects.get(pk=self.kwargs['pk'])
if usuario.atesto_conveniado:
atesto = usuario.atesto_conveniado
atesto.data = timezone.now()
atesto.user = request.user
atesto.save()
else:
atesto = AtestoConvenio.objects.create(
data=timezone.now(), user=request.user)
usuario.atesto_conveniado = atesto
usuario.conveniado = form.data['conveniado']
usuario.save()
return HttpResponseRedirect(self.get_success_url())
def get_context_data(self, **kwargs):
context = {}
context = super(ConveniadoView, self).get_context_data(**kwargs)
context[u'usuario'] = self.get_object()
context[u'casa'] = self.get_object().casa_legislativa
return context
def get_object(self, queryset=None):
obj = Usuario.objects.get(pk=self.kwargs['pk'])
return obj
def get_initial(self):
if self.get_object():
self.initial[u'conveniado'] = self.get_object().conveniado
return self.initial.copy()
def get_success_url(self):
return reverse(u'usuarios:convenio_list')
class ResponsavelView(CreateView):
template_name = u'usuarios/responsavel.html'
form_class = ResponsavelForm
def post(self, request, *args, **kwargs):
form = ResponsavelForm(request.POST)
usuario = Usuario.objects.get(pk=self.kwargs['pk'])
if usuario.atesto_responsavel:
atesto = usuario.atesto_responsavel
atesto.data = timezone.now()
atesto.user = request.user
atesto.save()
else:
atesto = AtestoResponsavel.objects.create(
data=timezone.now(), user=request.user)
usuario.atesto_responsavel = atesto
usuario.responsavel = form.data['responsavel']
usuario.save()
return HttpResponseRedirect(self.get_success_url())
def get_context_data(self, **kwargs):
context = {}
context = super(ResponsavelView, self).get_context_data(**kwargs)
context[u'usuario'] = self.get_object()
context[u'casa'] = self.get_object().casa_legislativa
return context
def get_object(self, queryset=None):
obj = Usuario.objects.get(pk=self.kwargs['pk'])
return obj
def get_initial(self):
if self.get_object():
self.initial[u'responsavel'] = self.get_object().responsavel
return self.initial.copy()
def get_success_url(self):
return reverse(u'usuarios:responsavel_list')
class UsuarioCrud(Crud): class UsuarioCrud(Crud):

24
templates/usuarios/convenio.html

@ -0,0 +1,24 @@
{% extends "admin/base_site.html" %}
{% load i18n crispy_forms_tags %}
{% block content %}
<table class="table table-striped table-bordered">
<thead class="thead-default">
<tr>
<th>Dados da Casa Legislativa</th>
</tr>
</thead>
<tr>
<td>
<b>Casa:</b> {{casa}}<br />
<b>CNJ:</b> {{casa.cnpj}}<br />
<b>Município:</b> {{casa.municipio}}<br />
<b>Email:</b> {{casa.email}}<br />
<b>Cep:</b> {{casa.cep}}<br />
<b>Página:</b> {{casa.pagina_web}}<br />
<b>Telefone:</b> {{casa.telefone}}<br />
</td>
</tr>
</table>
{% crispy form %}
{% endblock %}

24
templates/usuarios/convenio_list.html

@ -0,0 +1,24 @@
{% extends "admin/base_site.html" %}
{% load i18n crispy_forms_tags %}
{% block content %}
{% if object_list|length >= 1 %}
<fieldset>
<legend>Lista para atesto de convênio</legend>
<table class="table table-striped table-bordered">
<thead class="thead-default">
<tr>
<th>Casa Legislativa</th>
</tr>
</thead>
{% for object in object_list %}
<tr>
<td><a href="{% url 'usuarios:convenio_update' object.pk %}">{{object.casa_legislativa}}</a></td>
</tr>
{% endfor %}
</table>
</fieldset>
{% else %}
<p align='center'><font size='4'>Não há nenhum usuário para ser verificado.</font></p>
{% endif %}
{% endblock %}

33
templates/usuarios/responsavel.html

@ -0,0 +1,33 @@
{% extends "admin/base_site.html" %}
{% load i18n crispy_forms_tags %}
{% block content %}
<table class="table table-striped table-bordered">
<thead class="thead-default">
<tr>
<th>Dados informado pelo Usuário</th>
<th>Dados da Casa Legislativa</th>
</tr>
</thead>
<tr>
<td>
<b>Nome completo:</b> {{usuario.nome_completo}}<br />
<b>Email:</b> {{usuario.email}}<br />
<b>CPF:</b> {{usuario.cpf}}<br />
<b>RG:</b> {{usuario.rg}}<br />
<b>Cargo:</b> {{usuario.cargo}}<br />
<b>Vinculo:</b> {{usuario.vinculo}}<br />
</td>
<td>
<b>Casa:</b> {{casa}}<br />
<b>CNJ:</b> {{casa.cnpj}}<br />
<b>Município:</b> {{casa.municipio}}<br />
<b>Email:</b> {{casa.email}}<br />
<b>Cep:</b> {{casa.cep}}<br />
<b>Página:</b> {{casa.pagina_web}}<br />
<b>Telefone:</b> {{casa.telefone}}<br />
</td>
</tr>
</table>
{% crispy form %}
{% endblock %}

26
templates/usuarios/responsavel_list.html

@ -0,0 +1,26 @@
{% extends "admin/base_site.html" %}
{% load i18n crispy_forms_tags %}
{% block content %}
{% if object_list|length >= 1 %}
<fieldset>
<legend>Lista para atesto de responsável</legend>
<table class="table table-striped table-bordered">
<thead class="thead-default">
<tr>
<th>Nome Usuário</th>
<th>Casa Legislativa</th>
</tr>
</thead>
{% for object in object_list %}
<tr>
<td><a href="{% url 'usuarios:responsavel_update' object.pk %}">{{object.nome_completo}}</a></td>
<td>{{object.casa_legislativa}}</td>
</tr>
{% endfor %}
</table>
</fieldset>
{% else %}
<p align='center'><font size='4'>Não há nenhum usuário para ser verificado.</font></p>
{% endif %}
{% endblock %}
Loading…
Cancel
Save