|
|
@ -1,5 +1,6 @@ |
|
|
|
|
|
|
|
from django.conf import settings |
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin |
|
|
|
from django.contrib.auth.models import Group |
|
|
|
from django.contrib.auth.tokens import default_token_generator |
|
|
@ -8,7 +9,7 @@ from django.core.urlresolvers import reverse |
|
|
|
from django.db.models import Count, Q |
|
|
|
from django.http import HttpResponseRedirect |
|
|
|
from django.utils.encoding import force_bytes |
|
|
|
from django.utils.http import urlsafe_base64_encode |
|
|
|
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode |
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
|
|
from django.views.generic.base import TemplateView |
|
|
|
from django_filters.views import FilterView |
|
|
@ -21,6 +22,7 @@ from sapl.crud.base import CrudAux |
|
|
|
from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa |
|
|
|
from sapl.parlamentares.models import Parlamentar |
|
|
|
from sapl.sessao.models import OrdemDia, SessaoPlenaria |
|
|
|
from sapl.utils import sapl_logger |
|
|
|
|
|
|
|
from .forms import (CasaLegislativaForm, ConfiguracoesAppForm, |
|
|
|
RelatorioAtasFilterSet, |
|
|
@ -36,6 +38,18 @@ def get_casalegislativa(): |
|
|
|
return CasaLegislativa.objects.first() |
|
|
|
|
|
|
|
|
|
|
|
class ConfirmarEmailView(TemplateView): |
|
|
|
template_name = "email/confirma.html" |
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
uid = urlsafe_base64_decode(self.kwargs['uidb64']) |
|
|
|
user = get_user_model().objects.get(id=uid) |
|
|
|
user.is_active = True |
|
|
|
user.save() |
|
|
|
context = self.get_context_data(**kwargs) |
|
|
|
return self.render_to_response(context) |
|
|
|
|
|
|
|
|
|
|
|
class TipoAutorCrud(CrudAux): |
|
|
|
model = TipoAutor |
|
|
|
help_path = 'tipo-autor' |
|
|
@ -57,7 +71,9 @@ class AutorCrud(CrudAux): |
|
|
|
def delete(self, *args, **kwargs): |
|
|
|
self.object = self.get_object() |
|
|
|
|
|
|
|
# FIXME melhorar captura de grupo de Autor, levando em conta trad |
|
|
|
if self.object.user: |
|
|
|
# FIXME melhorar captura de grupo de Autor, levando em conta |
|
|
|
# trad |
|
|
|
grupo = Group.objects.filter(name='Autor')[0] |
|
|
|
self.object.user.groups.remove(grupo) |
|
|
|
|
|
|
@ -67,22 +83,30 @@ class AutorCrud(CrudAux): |
|
|
|
layout_key = None |
|
|
|
form_class = AutorForm |
|
|
|
|
|
|
|
def form_valid(self, form): |
|
|
|
# devido a implement do form o form_valid do Crud deve ser pulado |
|
|
|
return super(CrudAux.UpdateView, self).form_valid(form) |
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
if request.user.is_superuser: |
|
|
|
self.form_class = AutorFormForAdmin |
|
|
|
return CrudAux.UpdateView.post(self, request, *args, **kwargs) |
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
if request.user.is_superuser: |
|
|
|
self.form_class = AutorFormForAdmin |
|
|
|
return CrudAux.UpdateView.get(self, request, *args, **kwargs) |
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
|
|
|
|
|
# FIXME try except - testar envio de emails |
|
|
|
|
|
|
|
pk_autor = self.object.id |
|
|
|
url_reverse = reverse('sapl.base:autor_detail', |
|
|
|
kwargs={'pk': pk_autor}) |
|
|
|
try: |
|
|
|
kwargs = {} |
|
|
|
user = self.object.user |
|
|
|
|
|
|
|
"""if user.is_active: |
|
|
|
return reverse('sapl.base:autor_detail', |
|
|
|
kwargs={'pk': pk_autor})""" |
|
|
|
if not user: |
|
|
|
return url_reverse |
|
|
|
|
|
|
|
kwargs['token'] = default_token_generator.make_token(user) |
|
|
|
kwargs['uidb64'] = urlsafe_base64_encode(force_bytes(user.pk)) |
|
|
@ -99,18 +123,25 @@ class AutorCrud(CrudAux): |
|
|
|
"Caso você não tenha feito este cadastro, por favor " + |
|
|
|
"ignore esta mensagem. Caso tenha, clique " + |
|
|
|
"no link abaixo\n" + url_base + |
|
|
|
reverse('sapl.materia:confirmar_email', kwargs=kwargs)) |
|
|
|
reverse('sapl.base:confirmar_email', kwargs=kwargs)) |
|
|
|
remetente = [settings.EMAIL_SEND_USER] |
|
|
|
destinatario = [user.email] |
|
|
|
send_mail(assunto, mensagem, remetente, destinatario, |
|
|
|
fail_silently=False) |
|
|
|
return reverse('sapl.base:autor_detail', |
|
|
|
kwargs={'pk': pk_autor}) |
|
|
|
except: |
|
|
|
sapl_logger.error( |
|
|
|
_('Erro no envio de email na edição de Autores.')) |
|
|
|
return url_reverse |
|
|
|
|
|
|
|
class CreateView(CrudAux.CreateView): |
|
|
|
form_class = AutorForm |
|
|
|
layout_key = None |
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
if request.user.is_superuser: |
|
|
|
self.form_class = AutorFormForAdmin |
|
|
|
return CrudAux.CreateView.post(self, request, *args, **kwargs) |
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
|
if request.user.is_superuser: |
|
|
|
self.form_class = AutorFormForAdmin |
|
|
@ -118,9 +149,15 @@ class AutorCrud(CrudAux): |
|
|
|
|
|
|
|
def get_success_url(self): |
|
|
|
pk_autor = self.object.id |
|
|
|
# FIXME try except - testar envio de emails |
|
|
|
url_reverse = reverse('sapl.base:autor_detail', |
|
|
|
kwargs={'pk': pk_autor}) |
|
|
|
try: |
|
|
|
kwargs = {} |
|
|
|
user = self.object.user |
|
|
|
|
|
|
|
if not user: |
|
|
|
return url_reverse |
|
|
|
|
|
|
|
kwargs['token'] = default_token_generator.make_token(user) |
|
|
|
kwargs['uidb64'] = urlsafe_base64_encode(force_bytes(user.pk)) |
|
|
|
assunto = "SAPL - Confirmação de Conta" |
|
|
@ -136,14 +173,15 @@ class AutorCrud(CrudAux): |
|
|
|
"Caso você não tenha feito este cadastro, por favor " + |
|
|
|
"ignore esta mensagem. Caso tenha, clique " + |
|
|
|
"no link abaixo\n" + url_base + |
|
|
|
reverse('sapl.materia:confirmar_email', kwargs=kwargs)) |
|
|
|
remetente = settings.EMAIL_SEND_USER |
|
|
|
reverse('sapl.base:confirmar_email', kwargs=kwargs)) |
|
|
|
remetente = [settings.EMAIL_SEND_USER] |
|
|
|
destinatario = [user.email] |
|
|
|
send_mail(assunto, mensagem, remetente, destinatario, |
|
|
|
fail_silently=False) |
|
|
|
|
|
|
|
return reverse('sapl.base:autor_detail', |
|
|
|
kwargs={'pk': pk_autor}) |
|
|
|
except: |
|
|
|
sapl_logger.error( |
|
|
|
_('Erro no envio de email na criação de Autores.')) |
|
|
|
return url_reverse |
|
|
|
|
|
|
|
|
|
|
|
class RelatorioAtasView(FilterView): |
|
|
|