diff --git a/sigi/apps/eventos/admin.py b/sigi/apps/eventos/admin.py index 9d8b745..0656646 100644 --- a/sigi/apps/eventos/admin.py +++ b/sigi/apps/eventos/admin.py @@ -21,18 +21,17 @@ class ModeloDeclaracaoAdmin(admin.ModelAdmin): list_display = ('nome', 'formato') formfield_overrides = {HTMLField: {'widget': AdminTinyMCE}} - -class EquipeInline(admin.TabularInline): +class EquipeInline(admin.StackedInline): model = Equipe -class ConviteInline(admin.TabularInline): +class ConviteInline(admin.StackedInline): model = Convite raw_id_fields = ('casa',) -class ModuloInline(admin.TabularInline): +class ModuloInline(admin.StackedInline): model = Modulo -class AnexoInline(admin.TabularInline): +class AnexoInline(admin.StackedInline): model = Anexo exclude = ('data_pub',) diff --git a/sigi/apps/eventos/templates/eventos/declaracao_pdf.html b/sigi/apps/eventos/templates/eventos/declaracao_pdf.html index d545fe4..484ca7f 100644 --- a/sigi/apps/eventos/templates/eventos/declaracao_pdf.html +++ b/sigi/apps/eventos/templates/eventos/declaracao_pdf.html @@ -1,24 +1,18 @@ -{% extends 'base_report.html' %} +{% extends 'pdf/base_report.html' %} {% load i18n %} -{% block pagesize %}{{ pagesize }}{% endblock pagesize %} -{% block pagemargin %}4cm {{ pagemargin }}cm {{ pagemargin }}cm 2cm{% endblock pagemargin %} +{% block page_size %}{{ pagesize }}{% endblock page_size %} +{% block page_margin %}4cm {{ pagemargin }}cm {{ pagemargin }}cm 2cm{% endblock page_margin %} -{% block report %} - {% for convite in evento.convite_set.all %} - {% with convite.casa as casa %} - {% for nome in convite.nomes_participantes.splitlines %} - {% block text_body %}{% endblock %} - - {% endfor %} - {% endwith %} - {% endfor %} -{% endblock %} - -{%block page_foot%} - - - - -
-{% endblock %} +{% block main_content %} + {% for convite in evento.convite_set.all %} + {% with convite.casa as casa %} + {% for nome in convite.nomes_participantes.splitlines %} + {% block text_body %}{% endblock %} + {% if not forloop.last %} +
+ {% endif %} + {% endfor %} + {% endwith %} + {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/sigi/apps/eventos/templates/eventos/seleciona_modelo.html b/sigi/apps/eventos/templates/eventos/seleciona_modelo.html index c3180f0..e733c1c 100644 --- a/sigi/apps/eventos/templates/eventos/seleciona_modelo.html +++ b/sigi/apps/eventos/templates/eventos/seleciona_modelo.html @@ -1,25 +1,48 @@ {% extends "admin/base_site.html" %} -{% load i18n bootstrap3 %} +{% load i18n static %} -{% block content_title %} -

{% trans 'Emitir declaração de comparecimento' %}

+{% block extrastyle %} + {{ block.super }} + {% endblock %} +{% block breadcrumbs %}{% endblock %} + +{% block messages %} + {% if error %} + + {% endif %} +{% endblock messages %} + {% block content %} -{% if error %} - -{% endif %} -
-
{% csrf_token %} - {% csrf_token %} -
- {% bootstrap_form form %} +
+
+
+ {% trans 'Emitir declaração de comparecimento' %} + + {% csrf_token %} +
+ {{ form }} +
+ +
+
+
+
+ + + undo + {% trans "Voltar" %} + +
+
- - {% trans "Voltar" %} - +
{% endblock %} diff --git a/sigi/apps/eventos/urls.py b/sigi/apps/eventos/urls.py index 5e4494d..433daa5 100644 --- a/sigi/apps/eventos/urls.py +++ b/sigi/apps/eventos/urls.py @@ -3,6 +3,8 @@ from sigi.apps.eventos import views urlpatterns = [ path('calendario/', views.calendario, name='eventos-calendario'), + path('evento//declaracao/', views.declaracao, + name='evento-declaracao'), ] # from django.conf.urls import patterns, url diff --git a/sigi/apps/eventos/views.py b/sigi/apps/eventos/views.py index 9701d00..d31e2b9 100644 --- a/sigi/apps/eventos/views.py +++ b/sigi/apps/eventos/views.py @@ -1,9 +1,14 @@ import calendar import datetime import locale +from django.contrib.admin.sites import site from django.contrib.auth.decorators import login_required -from django.shortcuts import render +from django.http import HttpResponse +from django.shortcuts import render, get_object_or_404 +from django.template import Template, Context from django.utils.translation import to_locale, get_language, gettext as _ +from django_weasyprint.utils import django_url_fetcher +from weasyprint import HTML from sigi.apps.eventos.models import Evento, Equipe, Convite, Modulo from sigi.apps.eventos.forms import SelecionaModeloForm from sigi.apps.servidores.models import Servidor @@ -400,36 +405,42 @@ def calendario(request): # return response -# @login_required -# def declaracao(request, id): -# if request.method == 'POST': -# form = SelecionaModeloForm(request.POST) -# if form.is_valid(): -# evento = get_object_or_404(Evento, id=id) -# modelo = form.cleaned_data['modelo'] -# template_string = ( -# """ -# {% extends "eventos/declaracao_pdf.html" %} -# {% block text_body %}""" + -# modelo.texto + """ -# {% endblock %} -# """ -# ) -# context = Context( -# {'pagesize': modelo.formato, -# 'pagemargin': modelo.margem, -# 'evento': evento, -# 'data': datetime.date.today(), -# } -# ) -# template = Template(template_string) -# # return HttpResponse(template.render(context)) -# return pdf_renderer(template, context, 'declaracao.pdf') -# else: -# form = SelecionaModeloForm() - -# return render( -# request, -# 'eventos/seleciona_modelo.html', -# {'form': form, 'evento_id': id} -# ) \ No newline at end of file +@login_required +def declaracao(request, id): + if request.method == 'POST': + form = SelecionaModeloForm(request.POST) + if form.is_valid(): + evento = get_object_or_404(Evento, id=id) + modelo = form.cleaned_data['modelo'] + template_string = ( + """ + {% extends "eventos/declaracao_pdf.html" %} + {% block text_body %}""" + + modelo.texto + """ + {% endblock %} + """ + ) + context = Context({ + 'pagesize': modelo.formato, + 'pagemargin': modelo.margem, + 'evento': evento, + 'data': datetime.date.today(), + }) + string = Template(template_string).render(context) + # return HttpResponse(string) + response = HttpResponse(headers={ + 'Content-Type': "application/pdf", + 'Content-Disposition': 'attachment; filename="declaração.pdf"' + }) + pdf = HTML(string=string, url_fetcher=django_url_fetcher, + encoding="utf-8", base_url=request.build_absolute_uri('/')) + pdf.write_pdf(target=response) + return response + else: + form = SelecionaModeloForm() + + context = site.each_context(request) + context['form'] = form + context['evento_id'] = id + + return render(request, 'eventos/seleciona_modelo.html', context) \ No newline at end of file diff --git a/sigi/templates/pdf/base.html b/sigi/templates/pdf/base.html index b771339..b3eed670 100644 --- a/sigi/templates/pdf/base.html +++ b/sigi/templates/pdf/base.html @@ -1,45 +1,46 @@ {% load static i18n %} - - - - - - {% block extra_head %}{% endblock extra_head %} - {% block title %}{% endblock title %} - - - {% block body_content %}{% endblock body_content %} - + + + + + + {% block extra_head %}{% endblock extra_head %} + {% block title %}{% endblock title %} + + + {% block body_content %}{% endblock body_content %} +