Skip to content

Commit

Permalink
Poprawki raportu slotów - autor - generowanie PDF
Browse files Browse the repository at this point in the history
Użyj bardziej efektywnej metody pobierania danych do generowania PDF do raportu autorów
  • Loading branch information
mpasternak committed Aug 29, 2021
1 parent 8fff6e1 commit 5b0f9b7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
3 changes: 2 additions & 1 deletion HISTORY.rst
Expand Up @@ -15,7 +15,8 @@ Historia zmian
wg kryterium bycia lub nie wydawnictwem nadrzędnym dla innego rekordu (b/n),
* przycisk "Pobierz wg ISBN" w module redagowania, do pobierania odpowiedników z PBN po ISBN - interaktywnie
(b/n),
* matchuj prace po ISBN - wyłącznie rekordy nadrzędne (b/n)
* matchuj prace po ISBN - wyłącznie rekordy nadrzędne (b/n),
* użyj bardziej efektywnej metody pobierania danych do generowania PDF do raportu autorów (b/n),

202108.1075
-----------
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Expand Up @@ -67,6 +67,7 @@ pymed-iplweb==0.8.10
django-taggit==1.3.0
django-taggit-serializer==0.1.7
WeasyPrint==52.4
django-weasyprint>=1.1.0
requests-oauthlib==1.3.0
django-cacheops==6.0
# https://stackoverflow.com/questions/68208931/django-runtimeerror-at-admin-users-user-1-change-single-thread-executor-alrea
Expand Down
7 changes: 6 additions & 1 deletion requirements.txt
Expand Up @@ -118,6 +118,7 @@ django==3.0.14
# django-static-sitemaps
# django-tables2
# django-taggit
# django-weasyprint
# django-webmaster-verification
# djangorestframework
django-admin-sortable2==1.0
Expand Down Expand Up @@ -212,6 +213,8 @@ django-taggit==1.3.0
# django-taggit-serializer
django-taggit-serializer==0.1.7
# via -r requirements.in
django-weasyprint==1.1.0.post1
# via -r requirements.in
django-webmaster-verification==0.3.0
# via -r requirements.in
djangorestframework==3.11.2
Expand Down Expand Up @@ -415,7 +418,9 @@ vine==1.3.0
# amqp
# celery
weasyprint==52.4
# via -r requirements.in
# via
# -r requirements.in
# django-weasyprint
webencodings==0.5.1
# via
# bleach
Expand Down
21 changes: 21 additions & 0 deletions src/raport_slotow/tests/test_views/test_raport_slotow_autor.py
@@ -0,0 +1,21 @@
import sys

import pytest
from django.urls import reverse


@pytest.mark.skipif(
sys.platform == "darwin",
reason="WeasyPrint+cffi https://github.com/Kozea/WeasyPrint/issues/1432",
)
def test_RaportSlotow_get_pdf(admin_app, autor_jan_kowalski):
url = reverse("raport_slotow:index")

form_page = admin_app.get(url)
form_page.forms[0]["obiekt"].force_value(autor_jan_kowalski.pk)

raport_page = form_page.forms[0].submit().maybe_follow()

pdf_page = raport_page.click("pobierz PDF")

assert pdf_page.status_code == 200
10 changes: 2 additions & 8 deletions src/raport_slotow/views/autor.py
Expand Up @@ -5,6 +5,7 @@
from django.urls import reverse
from django.views.generic import FormView, TemplateView
from django_tables2 import MultiTableMixin, RequestConfig
from django_weasyprint.utils import django_url_fetcher

from formdefaults.helpers import FormDefaultsMixin
from raport_slotow.forms import AutorRaportSlotowForm
Expand Down Expand Up @@ -199,20 +200,13 @@ def get(self, request, *args, **kwargs):
# Jeżeli nagle będziemy mieli jakis zahasłowany statyczny asset, to będzie
# trzeba go tutaj udostępnić, żeby WeasyPrint miał ułatwione zadanie.
# (mpasternak, 17.03.2021)

# W przypadku niektórych certyfikatów WeasyPrint zawiedzie i nie bedzie mógł pobrać
# danych ze strony. Ponieważ pobieramy sami-od-siebie, pozwolimy sobie na coś takiego:

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

from weasyprint import HTML

response = HttpResponse(
content=HTML(
string=ret.render().content,
base_url=self.request.build_absolute_uri(),
url_fetcher=django_url_fetcher,
).write_pdf(),
content_type="application/pdf",
)
Expand Down

0 comments on commit 5b0f9b7

Please sign in to comment.