From 62160e8440c92fac99ceaf48f12f64e2154d8a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Tue, 3 Dec 2024 18:33:26 +0100 Subject: [PATCH] =?UTF-8?q?PDF=20u=C5=BE=20dost=C3=A1v=C3=A1me=20v=20URL,?= =?UTF-8?q?=20nen=C3=AD=20to=20pot=C5=99eba=20sh=C3=A1n=C4=9Bt=20znovu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/templates/korektury/opraf.html | 4 ---- korektury/views.py | 22 ++++++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/korektury/templates/korektury/opraf.html b/korektury/templates/korektury/opraf.html index 24d58d1d..13082bc2 100644 --- a/korektury/templates/korektury/opraf.html +++ b/korektury/templates/korektury/opraf.html @@ -57,7 +57,6 @@

- @@ -84,7 +83,6 @@
{% csrf_token %} - Přidávání korektur
Zanášení korektur @@ -121,7 +119,6 @@ {% csrf_token %} - @@ -196,7 +193,6 @@ {% csrf_token %} - {% if forloop.last %} diff --git a/korektury/views.py b/korektury/views.py index 664e9a82..f64951c9 100644 --- a/korektury/views.py +++ b/korektury/views.py @@ -56,6 +56,11 @@ class KorekturyView(generic.TemplateView): template_name = 'korektury/opraf.html' form_class = OpravaForm + def setup(self, request, *args, **kwargs): + super().setup(request, *args, **kwargs) + self.pdf_id = self.kwargs["pdf"] + self.pdf = get_object_or_404(KorekturovanePDF, id=self.pdf_id) + def post(self, request, *args, **kwargs): form = self.form_class(request.POST) q = request.POST @@ -77,9 +82,8 @@ class KorekturyView(generic.TemplateView): y = int(q.get('y')) text = q.get('txt') strana = int(q.get('img-id')[4:]) - pdf = KorekturovanePDF.objects.get(id=q.get('pdf')) - op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana,pdf = pdf) + op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana, pdf=self.pdf) op.save() self.send_email_notification_komentar(op,autor) elif (action == 'del'): @@ -132,9 +136,8 @@ class KorekturyView(generic.TemplateView): kom = Komentar.objects.get(id=id) kom.delete() elif (action == 'set-state'): - pdf = KorekturovanePDF.objects.get(id=q.get('pdf')) - pdf.status = q.get('state') # FIXME odchytávat blbosti? - pdf.save() + self.pdf.status = q.get('state') # FIXME odchytávat blbosti? + self.pdf.save() context = self.get_context_data() context['scroll'] = scroll context['autor'] = autor @@ -193,13 +196,12 @@ class KorekturyView(generic.TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - pdf = get_object_or_404(KorekturovanePDF, id=self.kwargs['pdf']) - context['pdf'] = pdf - context['img_prefix'] = pdf.get_prefix() + context['pdf'] = self.pdf + context['img_prefix'] = self.pdf.get_prefix() context['img_path'] = settings.KOREKTURY_IMG_DIR - context['img_indexes'] = range(pdf.stran) + context['img_indexes'] = range(self.pdf.stran) context['form_oprava'] = OpravaForm() - opravy = Oprava.objects.filter(pdf=self.kwargs['pdf']) + opravy = Oprava.objects.filter(pdf=self.pdf_id) zasluhy = {} for o in opravy: if o.autor in zasluhy: