|
@ -1,8 +1,6 @@ |
|
|
|
|
|
|
|
|
import logging |
|
|
import logging |
|
|
import re |
|
|
import re |
|
|
import sapl |
|
|
|
|
|
import weasyprint |
|
|
|
|
|
|
|
|
|
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin |
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin |
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
@ -15,7 +13,10 @@ from django.views.generic import TemplateView, UpdateView |
|
|
from django.views.generic.base import RedirectView |
|
|
from django.views.generic.base import RedirectView |
|
|
from django.views.generic.edit import FormView |
|
|
from django.views.generic.edit import FormView |
|
|
from django_filters.views import FilterView |
|
|
from django_filters.views import FilterView |
|
|
|
|
|
import weasyprint |
|
|
|
|
|
|
|
|
from sapl import settings |
|
|
from sapl import settings |
|
|
|
|
|
import sapl |
|
|
from sapl.base.models import AppConfig |
|
|
from sapl.base.models import AppConfig |
|
|
from sapl.compilacao.views import IntegracaoTaView |
|
|
from sapl.compilacao.views import IntegracaoTaView |
|
|
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, |
|
|
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, |
|
@ -108,7 +109,8 @@ class NormaPesquisaView(FilterView): |
|
|
context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' |
|
|
context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' |
|
|
|
|
|
|
|
|
context['show_results'] = show_results_filter_set(qr) |
|
|
context['show_results'] = show_results_filter_set(qr) |
|
|
context['USE_SOLR'] = settings.USE_SOLR if hasattr(settings, 'USE_SOLR') else False |
|
|
context['USE_SOLR'] = settings.USE_SOLR if hasattr( |
|
|
|
|
|
settings, 'USE_SOLR') else False |
|
|
|
|
|
|
|
|
return context |
|
|
return context |
|
|
|
|
|
|
|
@ -196,9 +198,8 @@ class NormaCrud(Crud): |
|
|
estatisticas_acesso_normas = AppConfig.objects.first().estatisticas_acesso_normas |
|
|
estatisticas_acesso_normas = AppConfig.objects.first().estatisticas_acesso_normas |
|
|
if estatisticas_acesso_normas == 'S': |
|
|
if estatisticas_acesso_normas == 'S': |
|
|
NormaEstatisticas.objects.create(usuario=str(self.request.user), |
|
|
NormaEstatisticas.objects.create(usuario=str(self.request.user), |
|
|
norma_id=kwargs['pk']) |
|
|
norma_id=kwargs['pk']) |
|
|
return super().get(request, *args, **kwargs) |
|
|
return super().get(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteView(Crud.DeleteView): |
|
|
class DeleteView(Crud.DeleteView): |
|
|
|
|
|
|
|
@ -218,12 +219,14 @@ class NormaCrud(Crud): |
|
|
username = self.request.user.username |
|
|
username = self.request.user.username |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
self.logger.debug('user=' + username + '. Tentando obter objeto de modelo da esfera da federação.') |
|
|
self.logger.debug( |
|
|
|
|
|
'user=' + username + '. Tentando obter objeto de modelo da esfera da federação.') |
|
|
esfera = sapl.base.models.AppConfig.objects.last( |
|
|
esfera = sapl.base.models.AppConfig.objects.last( |
|
|
).esfera_federacao |
|
|
).esfera_federacao |
|
|
self.initial['esfera_federacao'] = esfera |
|
|
self.initial['esfera_federacao'] = esfera |
|
|
except: |
|
|
except: |
|
|
self.logger.error('user=' + username + '. Erro ao obter objeto de modelo da esfera da federação.') |
|
|
self.logger.error( |
|
|
|
|
|
'user=' + username + '. Erro ao obter objeto de modelo da esfera da federação.') |
|
|
pass |
|
|
pass |
|
|
self.initial['complemento'] = False |
|
|
self.initial['complemento'] = False |
|
|
return self.initial |
|
|
return self.initial |
|
@ -233,7 +236,7 @@ class NormaCrud(Crud): |
|
|
class ListView(Crud.ListView, RedirectView): |
|
|
class ListView(Crud.ListView, RedirectView): |
|
|
|
|
|
|
|
|
def get_redirect_url(self, *args, **kwargs): |
|
|
def get_redirect_url(self, *args, **kwargs): |
|
|
namespace = self.model._meta.app_config.name |
|
|
namespace = self.model._meta.app_config.name |
|
|
return reverse('%s:%s' % (namespace, 'norma_pesquisa')) |
|
|
return reverse('%s:%s' % (namespace, 'norma_pesquisa')) |
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs): |
|
|
def get(self, request, *args, **kwargs): |
|
@ -332,6 +335,7 @@ class AutoriaNormaCrud(MasterDetailCrud): |
|
|
}) |
|
|
}) |
|
|
return initial |
|
|
return initial |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ImpressosView(PermissionRequiredMixin, TemplateView): |
|
|
class ImpressosView(PermissionRequiredMixin, TemplateView): |
|
|
template_name = 'materia/impressos/impressos.html' |
|
|
template_name = 'materia/impressos/impressos.html' |
|
|
permission_required = ('materia.can_access_impressos', ) |
|
|
permission_required = ('materia.can_access_impressos', ) |
|
@ -339,7 +343,7 @@ class ImpressosView(PermissionRequiredMixin, TemplateView): |
|
|
|
|
|
|
|
|
def gerar_pdf_impressos(request, context, template_name): |
|
|
def gerar_pdf_impressos(request, context, template_name): |
|
|
template = loader.get_template(template_name) |
|
|
template = loader.get_template(template_name) |
|
|
html = template.render(RequestContext(request, context)) |
|
|
html = template.render(context, request) |
|
|
pdf = weasyprint.HTML(string=html, base_url=request.build_absolute_uri() |
|
|
pdf = weasyprint.HTML(string=html, base_url=request.build_absolute_uri() |
|
|
).write_pdf() |
|
|
).write_pdf() |
|
|
|
|
|
|
|
|