From f82e4af987fb2c4d30cd886100f2ad0f099bcaf7 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 29 Jun 2016 17:18:28 -0300 Subject: [PATCH] =?UTF-8?q?#43=20Atestar=20conv=C3=AAnio=20e=20respons?= =?UTF-8?q?=C3=A1vel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sigi/apps/home/templatetags/menu_conf.yaml | 7 ++ sigi/apps/solicitacoes/layouts.yaml | 1 - sigi/apps/usuarios/forms.py | 56 ++++++++- .../migrations/0007_auto_20160628_1609.py | 29 +++++ sigi/apps/usuarios/migrations/0008_atesto.py | 31 +++++ .../0009_usuario_atesto_conveniado.py | 21 ++++ .../migrations/0010_auto_20160629_1448.py | 45 +++++++ sigi/apps/usuarios/models.py | 31 ++++- sigi/apps/usuarios/urls.py | 19 ++- sigi/apps/usuarios/views.py | 113 +++++++++++++++++- templates/usuarios/convenio.html | 24 ++++ templates/usuarios/convenio_list.html | 24 ++++ templates/usuarios/responsavel.html | 33 +++++ templates/usuarios/responsavel_list.html | 26 ++++ 14 files changed, 446 insertions(+), 14 deletions(-) create mode 100644 sigi/apps/usuarios/migrations/0007_auto_20160628_1609.py create mode 100644 sigi/apps/usuarios/migrations/0008_atesto.py create mode 100644 sigi/apps/usuarios/migrations/0009_usuario_atesto_conveniado.py create mode 100644 sigi/apps/usuarios/migrations/0010_auto_20160629_1448.py create mode 100644 templates/usuarios/convenio.html create mode 100644 templates/usuarios/convenio_list.html create mode 100644 templates/usuarios/responsavel.html create mode 100644 templates/usuarios/responsavel_list.html diff --git a/sigi/apps/home/templatetags/menu_conf.yaml b/sigi/apps/home/templatetags/menu_conf.yaml index 161947a..23ed5e2 100644 --- a/sigi/apps/home/templatetags/menu_conf.yaml +++ b/sigi/apps/home/templatetags/menu_conf.yaml @@ -123,3 +123,10 @@ main_menu: url: saberes/dashboard/cursos-sem-turoria/ - title: Cursos com Tutoria url: saberes/dashboard/cursos-com-turoria/ + - title: Atesto + url: '/' + children: + - title: Convênio + url: convenio + - title: Responsável + url: responsavel diff --git a/sigi/apps/solicitacoes/layouts.yaml b/sigi/apps/solicitacoes/layouts.yaml index cfbf36f..ef0757c 100644 --- a/sigi/apps/solicitacoes/layouts.yaml +++ b/sigi/apps/solicitacoes/layouts.yaml @@ -6,7 +6,6 @@ Sistema: Solicitacao: Solicitação: - - codigo - usuario - sistema - casa_legislativa diff --git a/sigi/apps/usuarios/forms.py b/sigi/apps/usuarios/forms.py index 47d528d..afe0797 100644 --- a/sigi/apps/usuarios/forms.py +++ b/sigi/apps/usuarios/forms.py @@ -5,7 +5,7 @@ from datetime import datetime from captcha.fields import CaptchaField 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.contrib.auth.forms import (AuthenticationForm, PasswordResetForm, SetPasswordForm) @@ -25,6 +25,60 @@ from sigi.apps.crud.utils import YES_NO_CHOICES 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'''

+ Ao atestar a responsabilidade deste convênio você + estará assumindo responsabilidade por qualquer + problema que poderá ocorrer pela existência de dados + incorretos.

'''), + 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'''

+ Ao atestar o convênio deste usuário você estará + assumindo resonsabilidade por qualquer problema + que poderá ocorrer pela existência de dados + incorretos.

'''), + row1, + form_actions( + save_label='Atestar'))) + + class LoginForm(AuthenticationForm): username = forms.CharField( label=u"Username", max_length=30, diff --git a/sigi/apps/usuarios/migrations/0007_auto_20160628_1609.py b/sigi/apps/usuarios/migrations/0007_auto_20160628_1609.py new file mode 100644 index 0000000..65c2839 --- /dev/null +++ b/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?'), + ), + ] diff --git a/sigi/apps/usuarios/migrations/0008_atesto.py b/sigi/apps/usuarios/migrations/0008_atesto.py new file mode 100644 index 0000000..f6abff9 --- /dev/null +++ b/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', + }, + ), + ] diff --git a/sigi/apps/usuarios/migrations/0009_usuario_atesto_conveniado.py b/sigi/apps/usuarios/migrations/0009_usuario_atesto_conveniado.py new file mode 100644 index 0000000..433ebcf --- /dev/null +++ b/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'), + ), + ] diff --git a/sigi/apps/usuarios/migrations/0010_auto_20160629_1448.py b/sigi/apps/usuarios/migrations/0010_auto_20160629_1448.py new file mode 100644 index 0000000..4955547 --- /dev/null +++ b/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'), + ), + ] diff --git a/sigi/apps/usuarios/models.py b/sigi/apps/usuarios/models.py index 024324e..95c0723 100644 --- a/sigi/apps/usuarios/models.py +++ b/sigi/apps/usuarios/models.py @@ -64,6 +64,23 @@ class ConfirmaEmail(models.Model): 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): u''' Usuário cadastrado via web @@ -89,11 +106,6 @@ class Usuario(models.Model): email = email = models.EmailField(unique=True, verbose_name=_(u'Email')) email_confirmado = models.BooleanField( 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( max_length=9, null=True, @@ -121,6 +133,15 @@ class Usuario(models.Model): 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): verbose_name = _(u'Usuário') verbose_name_plural = _(u'Usuários') diff --git a/sigi/apps/usuarios/urls.py b/sigi/apps/usuarios/urls.py index d9be142..93dfdc2 100644 --- a/sigi/apps/usuarios/urls.py +++ b/sigi/apps/usuarios/urls.py @@ -9,15 +9,17 @@ from django.views.generic.base import TemplateView from sigi.apps.usuarios.forms import (LoginForm, RecuperacaoMudarSenhaForm, RecuperarSenhaEmailForm) -from sigi.apps.usuarios.views import (ConfirmarEmailView, HabilitarDetailView, +from sigi.apps.usuarios.views import (ConfirmarEmailView, ConveniadoListView, + ConveniadoView, HabilitarDetailView, HabilitarEditView, MudarSenhaView, + ResponsavelListView, ResponsavelView, UsuarioCrud) from .apps import AppConfig app_name = AppConfig.name -EMAIL_SEND_USER='atendimento@interlegis.leg.br' +EMAIL_SEND_USER = 'atendimento@interlegis.leg.br' recuperar_email = [ url(ur'^atendimento/recuperar/recuperar_senha/$', @@ -60,6 +62,17 @@ urlpatterns = recuperar_email + [ HabilitarEditView.as_view(), name=u'habilitar_edit'), url(ur'^atendimento/usuario/(?P\d+)/mudar_senha$', MudarSenhaView.as_view(), name=u'mudar_senha'), - url(ur'^usuario/confirmar/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})$', + url(ur'^usuario/confirmar/(?P[0-9A-Za-z_\-]+)/' + '(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})$', ConfirmarEmailView.as_view(), name=u'confirmar_email'), + + url(ur'^responsavel$', ResponsavelListView.as_view(), + name=u'responsavel_list'), + url(ur'^responsavel/(?P\d+)/$', ResponsavelView.as_view(), + name=u'responsavel_update'), + + url(ur'^convenio$', ConveniadoListView.as_view(), + name=u'convenio_list'), + url(ur'^convenio/(?P\d+)/$', ConveniadoView.as_view(), + name=u'convenio_update'), ] diff --git a/sigi/apps/usuarios/views.py b/sigi/apps/usuarios/views.py index 321627a..e795e6a 100644 --- a/sigi/apps/usuarios/views.py +++ b/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.mixins import LoginRequiredMixin 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.urlresolvers import reverse +from django.http import HttpResponseRedirect from django.shortcuts import redirect from django.utils import timezone from django.utils.encoding import force_bytes 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, CrudDetailView, CrudListView, CrudUpdateView) from sigi.apps.crud.utils import str2bool -from .forms import (HabilitarEditForm, MudarSenhaForm, UsuarioEditForm, - UsuarioForm) -from .models import ConfirmaEmail, User, Usuario +from .forms import (ConveniadoForm, HabilitarEditForm, MudarSenhaForm, + ResponsavelForm, UsuarioEditForm, UsuarioForm) +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): diff --git a/templates/usuarios/convenio.html b/templates/usuarios/convenio.html new file mode 100644 index 0000000..4c2aded --- /dev/null +++ b/templates/usuarios/convenio.html @@ -0,0 +1,24 @@ +{% extends "admin/base_site.html" %} +{% load i18n crispy_forms_tags %} + +{% block content %} + + + + + + + + + +
Dados da Casa Legislativa
+ Casa: {{casa}}
+ CNJ: {{casa.cnpj}}
+ Município: {{casa.municipio}}
+ Email: {{casa.email}}
+ Cep: {{casa.cep}}
+ Página: {{casa.pagina_web}}
+ Telefone: {{casa.telefone}}
+
+ {% crispy form %} +{% endblock %} diff --git a/templates/usuarios/convenio_list.html b/templates/usuarios/convenio_list.html new file mode 100644 index 0000000..28ef331 --- /dev/null +++ b/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 %} +
+ Lista para atesto de convênio + + + + + + + {% for object in object_list %} + + + + {% endfor %} +
Casa Legislativa
{{object.casa_legislativa}}
+
+ {% else %} +

Não há nenhum usuário para ser verificado.

+ {% endif %} +{% endblock %} diff --git a/templates/usuarios/responsavel.html b/templates/usuarios/responsavel.html new file mode 100644 index 0000000..0c89ef4 --- /dev/null +++ b/templates/usuarios/responsavel.html @@ -0,0 +1,33 @@ +{% extends "admin/base_site.html" %} +{% load i18n crispy_forms_tags %} + +{% block content %} + + + + + + + + + + + +
Dados informado pelo UsuárioDados da Casa Legislativa
+ Nome completo: {{usuario.nome_completo}}
+ Email: {{usuario.email}}
+ CPF: {{usuario.cpf}}
+ RG: {{usuario.rg}}
+ Cargo: {{usuario.cargo}}
+ Vinculo: {{usuario.vinculo}}
+
+ Casa: {{casa}}
+ CNJ: {{casa.cnpj}}
+ Município: {{casa.municipio}}
+ Email: {{casa.email}}
+ Cep: {{casa.cep}}
+ Página: {{casa.pagina_web}}
+ Telefone: {{casa.telefone}}
+
+ {% crispy form %} +{% endblock %} diff --git a/templates/usuarios/responsavel_list.html b/templates/usuarios/responsavel_list.html new file mode 100644 index 0000000..36d1458 --- /dev/null +++ b/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 %} +
+ Lista para atesto de responsável + + + + + + + + {% for object in object_list %} + + + + + {% endfor %} +
Nome UsuárioCasa Legislativa
{{object.nome_completo}}{{object.casa_legislativa}}
+
+ {% else %} +

Não há nenhum usuário para ser verificado.

+ {% endif %} +{% endblock %}