Compare commits
No commits in common. "master" and "upravy_exportu" have entirely different histories.
master
...
upravy_exp
46 changed files with 898 additions and 1443 deletions
|
@ -1,4 +1,4 @@
|
|||
from galerie.models import Obrazek, Galerie, VZDY, ORG, NIKDY, UCASTNIK
|
||||
from galerie.models import Obrazek, Galerie
|
||||
from django.contrib import admin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django import forms
|
||||
|
@ -8,9 +8,8 @@ from django.db import models
|
|||
|
||||
def zverejnit_fotogalerii(modeladmin, request, queryset):
|
||||
'''zverejni vybranou fotogalerii i jeji vsechny podgalerie'''
|
||||
queryset = queryset.filter(zobrazit=ORG)
|
||||
for galerie in queryset:
|
||||
galerie.zobrazit = VZDY
|
||||
galerie.zobrazit = 0
|
||||
galerie.save()
|
||||
zverejnit_fotogalerii(modeladmin, request,
|
||||
Galerie.objects.filter(galerie_up = galerie))
|
||||
|
@ -19,9 +18,8 @@ def zverejnit_fotogalerii(modeladmin, request, queryset):
|
|||
|
||||
def prepnout_fotogalerii_do_org_rezimu(modeladmin, request, queryset):
|
||||
'''zneverjni vybranou fotogalerii i jeji vsechny podgalerie'''
|
||||
queryset = queryset.filter(zobrazit=VZDY)
|
||||
for galerie in queryset:
|
||||
galerie.zobrazit = ORG
|
||||
galerie.zobrazit = 1
|
||||
galerie.save()
|
||||
prepnout_fotogalerii_do_org_rezimu(modeladmin, request,
|
||||
Galerie.objects.filter(galerie_up = galerie))
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 4.2.20 on 2025-04-23 18:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('galerie', '0013_post_split_soustredeni'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='galerie',
|
||||
name='zobrazit',
|
||||
field=models.IntegerField(choices=[(0, 'Vždy'), (1, 'Organizátorům'), (3, 'Účastníkům a orgům'), (2, 'Nikdy')], default=1, verbose_name='Zobrazit?'),
|
||||
),
|
||||
]
|
|
@ -1,19 +0,0 @@
|
|||
# Generated by Django 4.2.16 on 2025-04-30 18:53
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('galerie', '0014_alter_galerie_zobrazit'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='galerie',
|
||||
name='galerie_up',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='galerie.galerie'),
|
||||
),
|
||||
]
|
|
@ -1,19 +0,0 @@
|
|||
# Generated by Django 4.2.16 on 2025-04-30 19:02
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('galerie', '0015_alter_galerie_galerie_up'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='obrazek',
|
||||
name='galerie',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='galerie.galerie'),
|
||||
),
|
||||
]
|
|
@ -10,11 +10,9 @@ from soustredeni.models import Soustredeni
|
|||
VZDY=0
|
||||
ORG=1
|
||||
NIKDY=2
|
||||
UCASTNIK=3
|
||||
VIDITELNOST = (
|
||||
(VZDY, 'Vždy'),
|
||||
(ORG, 'Organizátorům'),
|
||||
(UCASTNIK, 'Účastníkům a orgům'),
|
||||
(NIKDY, 'Nikdy'),
|
||||
)
|
||||
|
||||
|
@ -56,7 +54,7 @@ class Obrazek(models.Model):
|
|||
nazev = models.CharField('Název', max_length=50, blank=True, null=True)
|
||||
popis = models.TextField('Popis', blank=True, null=True)
|
||||
datum_vlozeni = models.DateTimeField('Datum vložení', auto_now_add=True)
|
||||
galerie = models.ForeignKey('Galerie', blank=True, null=True, on_delete=models.CASCADE)
|
||||
galerie = models.ForeignKey('Galerie', blank=True, null=True, on_delete=models.SET_NULL)
|
||||
poradi = models.IntegerField('Pořadí', blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -90,7 +88,7 @@ class Galerie(models.Model):
|
|||
titulni_obrazek = models.ForeignKey(Obrazek, blank = True, null = True, related_name = "+", on_delete = models.SET_NULL)
|
||||
zobrazit = models.IntegerField('Zobrazit?', default = ORG, choices = VIDITELNOST)
|
||||
galerie_up = models.ForeignKey('Galerie', blank = True, null = True,
|
||||
on_delete=models.PROTECT)
|
||||
on_delete=models.SET_NULL)
|
||||
soustredeni = models.ForeignKey(Soustredeni, blank = True, null = True,
|
||||
on_delete=models.PROTECT)
|
||||
poradi = models.IntegerField('Pořadí', blank = True, null = False, default = 0)
|
||||
|
@ -100,3 +98,25 @@ class Galerie(models.Model):
|
|||
class Meta:
|
||||
verbose_name = 'Galerie'
|
||||
verbose_name_plural = 'Galerie'
|
||||
|
||||
#def link_na_preview(self):
|
||||
#"""Odkaz na galerii, používá se v admin rozhranní. """
|
||||
#return '<a href="/fotogalerie/galerie/%s/">Preview</a>' % self.id
|
||||
#link_na_preview.allow_tags = True
|
||||
#link_na_preview.short_description = 'Zobrazit galerii'
|
||||
#
|
||||
#def je_publikovano(self):
|
||||
#"""Vraci True, pokud je tato galerie publikovana. """
|
||||
#if self.zobrazit == VZDY:
|
||||
#return True
|
||||
#if self.zobrazit == PODLE_CLANKU:
|
||||
#for clanek in self.clanek_set.all():
|
||||
#if clanek.je_publikovano():
|
||||
#return True
|
||||
#return False
|
||||
#
|
||||
#@staticmethod
|
||||
#def publikovane_galerie():
|
||||
#"""Vraci galerie, ktere uz maji byt publikovane."""
|
||||
#clanky = Blog.models.Clanek.publikovane_clanky()
|
||||
#return Galerie.objects.filter(Q(zobrazit=VZDY) | (Q(clanek__in=clanky) & Q(zobrazit=PODLE_CLANKU))).distinct()
|
||||
|
|
|
@ -136,11 +136,6 @@
|
|||
top: 160px;
|
||||
}
|
||||
|
||||
.podgalerie_nahled.mam-org-only, .podgalerie_nahled.mam-resitel-only {
|
||||
margin: 10px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
|
||||
/* Odkazy na předchozí a následující podgalerii */
|
||||
.galerie_predchozi_nasledujici {
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
|
||||
{% block content %}
|
||||
|
||||
<div class="{% if obrazek.galerie.zobrazit == 1 or obrazek.galerie.zobrazit == 2 %}mam-org-only{% endif %}{% if obrazek.galerie.zobrazit == 3 %}mam-resitel-only{% endif %}">
|
||||
|
||||
<h2>
|
||||
{% for g in cesta %}
|
||||
|
@ -84,7 +83,7 @@
|
|||
|
||||
{# Popisek fotky #}
|
||||
<div class="popis">
|
||||
{% if upravy_popisku %}
|
||||
{% if preview %}
|
||||
<form action=".#nahoru" method="post" id="komentarform">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
|
@ -134,6 +133,4 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -6,11 +6,8 @@ Galerie {{galerie.nazev}}
|
|||
|
||||
{% block content %}
|
||||
|
||||
{# FIXME: použít konstanty… #}
|
||||
{% if galerie.zobrazit == 1 or galerie.zobrazit == 2 %}
|
||||
{% if galerie.zobrazit > 0 %}
|
||||
<div class="mam-org-only">
|
||||
{% elif galerie.zobrazit == 3 %}
|
||||
<div class="mam-resitel-only">
|
||||
{% endif %}
|
||||
|
||||
<h2>
|
||||
|
@ -48,43 +45,37 @@ Galerie {{galerie.nazev}}
|
|||
{% if podgalerie %}
|
||||
{% with 22 as max_delka_nazvu %}
|
||||
<div class="galerie_nahledy">
|
||||
{% for pgalerie in podgalerie %}
|
||||
<a href="../{{pgalerie.pk}}"
|
||||
{% if pgalerie.nazev|length > max_delka_nazvu %}
|
||||
title="{{ pgalerie.nazev }}"
|
||||
{% for galerie in podgalerie %}
|
||||
<a href="../{{galerie.pk}}"
|
||||
{% if galerie.nazev|length > max_delka_nazvu %}
|
||||
title="{{ galerie.nazev }}"
|
||||
{% endif %}
|
||||
class="podgalerie_nahled {% if pgalerie.zobrazit == 1 or pgalerie.zobrazit == 2 %}mam-org-only{% endif %}{% if pgalerie.zobrazit == 3 %}mam-resitel-only{% endif %}">
|
||||
{% if pgalerie.titulni_obrazek %}
|
||||
{% with pgalerie.titulni_obrazek.obrazek_maly as obrazek %}
|
||||
class="podgalerie_nahled">
|
||||
{% if galerie.titulni_obrazek %}
|
||||
{% with galerie.titulni_obrazek.obrazek_maly as obrazek %}
|
||||
<img src="{{ obrazek.url }}"
|
||||
/>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
<div class="nazev_galerie">
|
||||
{{ pgalerie|truncatechars:max_delka_nazvu }}
|
||||
{{ galerie|truncatechars:max_delka_nazvu }}
|
||||
</div>
|
||||
</a>
|
||||
{% if galerie.zobrazit == 1 or galerie.zobrazit == 2 %}
|
||||
{% if user.je_org %}
|
||||
{% if user.je_org and galerie.zobrazit > 0 %}
|
||||
<div class="mam-org-only-galerie">
|
||||
({{pgalerie.poradi}})
|
||||
<span class="plus"><a href="plus/{{pgalerie.pk}}/">+</a></span>
|
||||
<span class="minus"><a href="minus/{{pgalerie.pk}}/">-</a></span>
|
||||
({{galerie.poradi}})
|
||||
<span class="plus"><a href="plus/{{galerie.pk}}/">+</a></span>
|
||||
<span class="minus"><a href="minus/{{galerie.pk}}/">-</a></span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if user.je_org %}
|
||||
{% if user.je_org and galerie.zobrazit > 0 %}
|
||||
<div class="mam-org-only">
|
||||
{% if galerie.zobrazit == 1 or galerie.zobrazit == 2 %}
|
||||
<a href="./new">Vytvořit novou podgalerii</a>, <a href="{% url 'admin:galerie_galerie_change' galerie.pk %}">upravit galerii v adminu</a>
|
||||
{% else %}
|
||||
Jestli chceš změnit pořadí podgalerií nebo přidat novou, nastav zobrazení jen pro orgy v <a href="{% url 'admin:galerie_galerie_change' galerie.pk %}">adminu</a>.
|
||||
{% endif %}
|
||||
<a href="./new">Vytvořit novou podgalerii </a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
@ -129,10 +120,8 @@ Galerie {{galerie.nazev}}
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if galerie.zobrazit == 1 or galerie.zobrazit == 2 %}
|
||||
{% if galerie.zobrazit > 0 %}
|
||||
</div> {# mam-org-only #}
|
||||
{% elif galerie.zobrazit == 2 %}
|
||||
</div> {# mam-resitel-only #}
|
||||
{% endif %}
|
||||
|
||||
{% endblock content %}
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
{% load static %}
|
||||
|
||||
{% block custom_css %}
|
||||
<link href="{% static 'css/galerie.css' %}?version=2" rel="stylesheet">
|
||||
<link href="{% static 'css/galerie.css' %}?version=1" rel="stylesheet">
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
from galerie.models import Galerie
|
||||
|
||||
def top_galerie(g: Galerie) -> Galerie:
|
||||
while g.galerie_up is not None:
|
||||
g = g.galerie_up
|
||||
return g
|
137
galerie/views.py
137
galerie/views.py
|
@ -1,41 +1,22 @@
|
|||
import random
|
||||
|
||||
from django.http import HttpResponse, Http404, HttpRequest
|
||||
from django.http import HttpResponse, Http404
|
||||
from django.shortcuts import render, HttpResponseRedirect, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
from datetime import datetime
|
||||
|
||||
from galerie.utils import top_galerie
|
||||
from personalni.utils import resitel_uzivatele
|
||||
|
||||
from galerie.models import Obrazek, Galerie, VZDY, ORG, UCASTNIK, NIKDY
|
||||
from galerie.models import Obrazek, Galerie
|
||||
from soustredeni.models import Soustredeni
|
||||
from galerie.forms import KomentarForm, NewGalerieForm
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def galerie_ke_zobrazeni(soustredeni: Soustredeni | None, request: HttpRequest) -> tuple[int]:
|
||||
if request.user.is_superuser: return (VZDY, ORG, UCASTNIK, NIKDY)
|
||||
if request.user.je_org: return (VZDY, ORG, UCASTNIK)
|
||||
if request.user.is_anonymous: return (VZDY,)
|
||||
if soustredeni is None: return (VZDY,)
|
||||
if (resitel := resitel_uzivatele(request.user)) is not None:
|
||||
if resitel.soustredeni_set.contains(soustredeni):
|
||||
return (VZDY, UCASTNIK)
|
||||
def zobrazit(galerie, request):
|
||||
preview = False
|
||||
if galerie.zobrazit >= 1:
|
||||
if request.user.je_org:
|
||||
preview = True;
|
||||
else:
|
||||
return (VZDY,)
|
||||
logger.warning("Nepodařilo se zjistit, jaké galerie se mají zobrazit!")
|
||||
return (VZDY,)
|
||||
|
||||
|
||||
def zobrazit(galerie: Galerie, request: HttpRequest) -> bool:
|
||||
soustredeni = top_galerie(galerie).soustredeni
|
||||
return galerie.zobrazit in galerie_ke_zobrazeni(soustredeni, request)
|
||||
|
||||
def dovolit_upravy_popisku(galerie: Galerie, request: HttpRequest) -> bool:
|
||||
# FIXME: Dočasné: úpravy jen když je to v org-only stavu. (Odpovídá předchozímu chování)
|
||||
return request.user.je_org and galerie.zobrazit in (ORG, NIKDY)
|
||||
raise Http404
|
||||
return preview
|
||||
|
||||
|
||||
def cesta_od_korene(g):
|
||||
|
@ -50,19 +31,19 @@ def cesta_od_korene(g):
|
|||
def nahled(request, pk, soustredeni):
|
||||
"""Zobrazeni nahledu vsech fotek ve skupine."""
|
||||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
soustredeni = top_galerie(galerie).soustredeni
|
||||
|
||||
# FIXME: přepsat model a použít přímo dolů…
|
||||
podgalerie = Galerie.objects.filter(galerie_up = galerie).order_by('poradi')
|
||||
podgalerie = podgalerie.filter(zobrazit__in=galerie_ke_zobrazeni(soustredeni, request))
|
||||
if not request.user.je_org:
|
||||
podgalerie = podgalerie.filter(zobrazit__lt=1)
|
||||
|
||||
obrazky = galerie.obrazek_set.all().order_by('poradi', 'nazev')
|
||||
ma_se_zobrazit = zobrazit(galerie, request)
|
||||
if not ma_se_zobrazit: raise Http404("Galerie sice existuje, ale my se tváříme, že ne :-D")
|
||||
obrazky = Obrazek.objects.filter(galerie = galerie).order_by('poradi', 'nazev')
|
||||
preview = zobrazit(galerie, request)
|
||||
|
||||
sourozenci = []
|
||||
if galerie.galerie_up:
|
||||
sourozenci = galerie.galerie_up.galerie_set.filter(zobrazit__in=galerie_ke_zobrazeni(soustredeni, request)).order_by('poradi')
|
||||
sourozenci = galerie.galerie_up.galerie_set.all().order_by('poradi')
|
||||
if not request.user.je_org:
|
||||
sourozenci = sourozenci.filter(zobrazit__lt=1)
|
||||
|
||||
predchozi = None
|
||||
nasledujici = None
|
||||
|
@ -81,6 +62,7 @@ def nahled(request, pk, soustredeni):
|
|||
{'galerie' : galerie,
|
||||
'podgalerie' : podgalerie,
|
||||
'obrazky' : obrazky,
|
||||
'preview' : preview,
|
||||
'cesta': cesta,
|
||||
'sourozenci': sourozenci,
|
||||
'predchozi': predchozi,
|
||||
|
@ -96,41 +78,9 @@ def detail(request, pk, fotka, soustredeni):
|
|||
NAHLEDU = 1
|
||||
|
||||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
soustredeni = top_galerie(galerie).soustredeni
|
||||
ma_se_zobrazit = zobrazit(galerie, request)
|
||||
if not ma_se_zobrazit: raise Http404("Obrázek neukážu!")
|
||||
preview = zobrazit(galerie, request)
|
||||
obrazek = get_object_or_404(Obrazek, pk=fotka)
|
||||
|
||||
# Pořadí není povinné. FIXME: `nazev` je zavádějící… Ale tohle je kanonické pořadí obrázků v galerii…
|
||||
obrazky = galerie.obrazek_set.all().order_by('poradi', 'nazev')
|
||||
obrazky = list(obrazky)
|
||||
index_obrazku = obrazky.index(obrazek)
|
||||
# Podle mě se nemůže stát, že by volání výš selhalo, kdyžtak shodí web. (původně to byl explicitně ošetřený stav dávající 404)
|
||||
predchozi_obrazky = list(reversed(obrazky[:index_obrazku]))
|
||||
nasledujici_obrazky = obrazky[index_obrazku+1:]
|
||||
# Může jich být hodně…
|
||||
predchozi_obrazky = predchozi_obrazky[:NAHLEDU]
|
||||
nasledujici_obrazky = nasledujici_obrazky[:NAHLEDU]
|
||||
# Předchozí obrázky chceme v normálním pořadí
|
||||
predchozi_obrazky = list(reversed(predchozi_obrazky))
|
||||
|
||||
if galerie.galerie_up is not None:
|
||||
sousedni_galerie = Galerie.objects.filter(galerie_up=galerie.galerie_up, zobrazit__in=galerie_ke_zobrazeni(soustredeni, request)).order_by('poradi')
|
||||
sousedni_galerie = list(sousedni_galerie)
|
||||
# Teoreticky se můžeme dívat na galerie.poradi, ale jednak už tenhle pattern stejně je výš a druhak je galerií málo, takže pomalost nevadí.
|
||||
index_galerie = sousedni_galerie.index(galerie)
|
||||
predchozi_galerie = sousedni_galerie[index_galerie-1] if index_galerie > 0 else None
|
||||
nasledujici_galerie = sousedni_galerie[index_galerie+1] if index_galerie < len(sousedni_galerie) - 1 else None
|
||||
else:
|
||||
predchozi_galerie = None
|
||||
nasledujici_galerie = None
|
||||
|
||||
# Pokud je obrázků dost, tak další galerii nepotřebujeme
|
||||
# (jo, mohli jsme si ušetřit práci, ale takhle je kód imho přehlednější a za pár ušetřených dotazů do DB to nestojí)
|
||||
if len(predchozi_obrazky) >= NAHLEDU:
|
||||
predchozi_galerie = None
|
||||
if len(nasledujici_obrazky) >= NAHLEDU:
|
||||
nasledujici_galerie = None
|
||||
|
||||
# vytvoreni a obslouzeni formulare
|
||||
if request.method == 'POST':
|
||||
|
@ -141,6 +91,49 @@ def detail(request, pk, fotka, soustredeni):
|
|||
else:
|
||||
form = KomentarForm({'komentar': obrazek.popis})
|
||||
|
||||
# Poradi aktualniho obrazku v galerii/stitku.
|
||||
for i in range(len(obrazky)):
|
||||
if obrazky[i] == obrazek:
|
||||
poradi = i
|
||||
break
|
||||
else:
|
||||
# Obrazek neni v galerii/stitku.
|
||||
raise Http404
|
||||
|
||||
|
||||
# Nacteni okolnich obrazku a galerii
|
||||
# TODO vyjmout zjisteni predchozich a nasledujicich galerii
|
||||
# a udelat z toho funkci, ktera se pouzije u nahledu
|
||||
predchozi_galerie = None
|
||||
nasledujici_galerie = None
|
||||
obrazky_dalsi = obrazky[poradi+1:poradi+NAHLEDU+1]
|
||||
if (poradi+1) > NAHLEDU:
|
||||
obrazky_predchozi = obrazky[poradi-NAHLEDU:poradi]
|
||||
else:
|
||||
obrazky_predchozi = obrazky[0:poradi]
|
||||
if galerie.poradi > 1:
|
||||
predchozi_galerie = Galerie.objects.\
|
||||
filter(galerie_up=galerie.galerie_up).\
|
||||
filter(poradi=(galerie.poradi-1))
|
||||
if predchozi_galerie:
|
||||
predchozi_galerie = predchozi_galerie[0]
|
||||
else:
|
||||
predchozi_galerie = None
|
||||
if (poradi+1) == len(obrazky): # Tohle je poslední obrázek
|
||||
if (galerie.poradi is not None
|
||||
and galerie.galerie_up is not None):
|
||||
nasledujici_galerie = Galerie.objects.\
|
||||
filter(galerie_up=galerie.galerie_up).\
|
||||
filter(poradi=(galerie.poradi+1))
|
||||
else:
|
||||
nasledujici_galerie = None
|
||||
if nasledujici_galerie:
|
||||
nasledujici_galerie = nasledujici_galerie[0]
|
||||
else:
|
||||
nasledujici_galerie = None
|
||||
|
||||
|
||||
|
||||
# Preskalovani obrazku do vybraneho prostoru.
|
||||
vyska = obrazek.obrazek_stredni.height
|
||||
sirka = obrazek.obrazek_stredni.width
|
||||
|
@ -158,9 +151,9 @@ def detail(request, pk, fotka, soustredeni):
|
|||
'obrazek' : obrazek,
|
||||
'vyska' : vyska,
|
||||
'sirka' : sirka,
|
||||
'obrazky_predchozi' : predchozi_obrazky,
|
||||
'obrazky_dalsi' : nasledujici_obrazky,
|
||||
'upravy_popisku' : dovolit_upravy_popisku(galerie, request),
|
||||
'obrazky_predchozi' : obrazky_predchozi,
|
||||
'obrazky_dalsi' : obrazky_dalsi,
|
||||
'preview' : preview,
|
||||
'form' : form,
|
||||
'cesta': cesta_od_korene(galerie),
|
||||
})
|
||||
|
@ -186,7 +179,7 @@ def new_galerie(request, galerie, soustredeni):
|
|||
gal = Galerie()
|
||||
gal.nazev = form.cleaned_data['nazev']
|
||||
#gal.popis = form.cleaned_data['popis'] # popis nepouzivame
|
||||
gal.zobrazit = ORG # galerie je v procesu vytvareni
|
||||
gal.zobrazit = 1 # galerie je v procesu vytvareni
|
||||
''' pokud je to podgalerie pridej nadrazenou galerii
|
||||
a nadrazene soustredeni nechej volne,
|
||||
pokud je to hlavni galerie, tak nadrazena galerie neexistuje,
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
# Generated by Django 4.2.16 on 2025-03-19 18:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('korektury', '0027_korekturatag_oprava_tagy'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='korekturovanepdf',
|
||||
options={'ordering': ['-cas'], 'verbose_name': 'PDF ke korekturování', 'verbose_name_plural': 'PDFka ke korekturování'},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='korekturovanepdf',
|
||||
name='nazev',
|
||||
field=models.CharField(help_text='Název (např. „42.6 | analýza v4“ nebo „propagace | letáček v0“) korekturovaného PDF, v seznamu se seskupují podle textu do první mezery, tedy zde „42.6“ respektive „propagace“.', max_length=50, verbose_name='název PDF'),
|
||||
),
|
||||
]
|
|
@ -35,15 +35,15 @@ class KorekturovanePDF(models.Model):
|
|||
class Meta:
|
||||
ordering = ['-cas']
|
||||
db_table = 'korekturovane_cislo'
|
||||
verbose_name = 'PDF ke korekturování'
|
||||
verbose_name_plural = 'PDFka ke korekturování'
|
||||
verbose_name = u'PDF k opravám'
|
||||
verbose_name_plural = u'PDF k opravám'
|
||||
|
||||
#Interní ID
|
||||
id = models.AutoField(primary_key = True)
|
||||
|
||||
cas = models.DateTimeField(u'čas vložení PDF',default=timezone.now,help_text = 'Čas vložení PDF')
|
||||
|
||||
nazev = models.CharField(u'název PDF',blank = False,max_length=50, help_text='Název (např. „42.6 | analýza v4“ nebo „propagace | letáček v0“) korekturovaného PDF, v seznamu se seskupují podle textu do první mezery, tedy zde „42.6“ respektive „propagace“.')
|
||||
nazev = models.CharField(u'název PDF',blank = False,max_length=50, help_text='Název (např. `22.1 | analyza v4` nebo `propagace | letacek v0`) korekturovaného PDF')
|
||||
|
||||
komentar = models.TextField(u'komentář k PDF',blank = True, help_text='Komentář ke korekturovanému PDF (např. na co se zaměřit)')
|
||||
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
.textzanaseni { display:none; }
|
||||
.textzastarale { display:none; }
|
||||
#prekomentar, #prekorektura, #prepointer { display: none; }
|
||||
#prekomentar, #preoprava, #prepointer { display: none; }
|
||||
|
||||
body {
|
||||
&[data-stav_pdf="pridavani"] {
|
||||
&[data-status="pridavani"] {
|
||||
background: #f3f3f3;
|
||||
}
|
||||
|
||||
&[data-stav_pdf="zanaseni"] {
|
||||
&[data-status="zanaseni"] {
|
||||
background: yellow;
|
||||
|
||||
.textzanaseni { display: unset; }
|
||||
}
|
||||
|
||||
&[data-stav_pdf="zastarale"] {
|
||||
&[data-status="zastarale"] {
|
||||
background: red;
|
||||
|
||||
.textzastarale { display: unset; }
|
||||
|
@ -28,25 +28,25 @@ body {
|
|||
img{background:white;}
|
||||
|
||||
/* Barvy korektur */
|
||||
[data-stav_korektury="k_oprave"] {
|
||||
[data-opravastatus="k_oprave"] {
|
||||
--rgb: 255, 0, 0;
|
||||
|
||||
[value="k_oprave"] { display: none }
|
||||
.komentovat_disabled { display: none }
|
||||
}
|
||||
[data-stav_korektury="opraveno"] {
|
||||
[data-opravastatus="opraveno"] {
|
||||
--rgb: 0, 0, 255;
|
||||
|
||||
[value="opraveno"] { display: none }
|
||||
.komentovat { display: none }
|
||||
}
|
||||
[data-stav_korektury="neni_chyba"] {
|
||||
[data-opravastatus="neni_chyba"] {
|
||||
--rgb: 128, 128, 128;
|
||||
|
||||
[value="neni_chyba"] { display: none }
|
||||
.komentovat { display: none }
|
||||
}
|
||||
[data-stav_korektury="k_zaneseni"] {
|
||||
[data-opravastatus="k_zaneseni"] {
|
||||
--rgb: 0, 255, 0;
|
||||
|
||||
[value="k_zaneseni"] { display: none }
|
||||
|
@ -54,16 +54,10 @@ img{background:white;}
|
|||
}
|
||||
|
||||
/* Skrývání korektur */
|
||||
[data-korektura_sbalena="true"] {
|
||||
.korektura-telo { display: none; }
|
||||
.korektura-tlacitka { display: none; }
|
||||
.sbal-rozbal-img { transform: rotate(180deg); }
|
||||
}
|
||||
/* Skrývání komentářů */
|
||||
[data-komentar_sbalen="true"] {
|
||||
.sbal-rozbal-img { transform: rotate(180deg); }
|
||||
.uprav-komentar { display: none; }
|
||||
.komtext { display: none; }
|
||||
[data-opravazobrazit="false"] {
|
||||
.corr-body { display: none; }
|
||||
.corr-buttons { display: none; }
|
||||
.toggle-button { transform: rotate(180deg); }
|
||||
}
|
||||
|
||||
|
||||
|
@ -78,14 +72,14 @@ img{background:white;}
|
|||
--alpha: 0.35;
|
||||
|
||||
/* Zvýraznění čáry při najetí na korekturu */
|
||||
&[data-hover="true"] {
|
||||
&[data-highlight="true"] {
|
||||
border-width: 3px;
|
||||
--alpha: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Korektura samotná */
|
||||
.korektura {
|
||||
.oprava {
|
||||
margin: 1px;
|
||||
background-color: white;
|
||||
width: 300px;
|
||||
|
@ -112,11 +106,11 @@ img{background:white;}
|
|||
|
||||
button img { pointer-events: none; }
|
||||
|
||||
.hlavicka-komentare {
|
||||
.corr-header {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.autor {
|
||||
.author {
|
||||
font-weight: bold;
|
||||
float: left;
|
||||
margin-top: 3px;
|
||||
|
@ -139,7 +133,7 @@ form {
|
|||
}
|
||||
|
||||
/* Přidávání korektury / úprava komentáře */
|
||||
#korekturovaci-formular-div {
|
||||
#commform-div {
|
||||
position: absolute;
|
||||
background-color: white;
|
||||
padding: 3px;
|
||||
|
@ -154,8 +148,8 @@ form {
|
|||
margin: 2px;
|
||||
padding: 2px;
|
||||
|
||||
&[data-vybran="false"] { background: unset !important; }
|
||||
/*&[data-vybran="true"] { border-color: unset !important; }*/
|
||||
&[data-selected="false"] { background: unset !important; }
|
||||
/*&[data-selected="true"] { border-color: unset !important; }*/
|
||||
}
|
||||
|
||||
/* Šipky na posouvání korektur */
|
||||
|
|
46
korektury/static/korektury/opraf.js
Normal file
46
korektury/static/korektury/opraf.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const W_SKIP = 10;
|
||||
const H_SKIP = 5;
|
||||
const POINTER_MIN_H = 30;
|
||||
|
||||
function place_comments_one_div(img_id, comments)
|
||||
{
|
||||
const img = document.getElementById("img-"+img_id);
|
||||
if( img == null ) return;
|
||||
const comments_sorted = comments.sort((a, b) => a.y - b.y);
|
||||
|
||||
const par = img.parentNode;
|
||||
const w = img.clientWidth;
|
||||
|
||||
let bott_max = 0;
|
||||
for (const oprava of comments_sorted) {
|
||||
const x = oprava.x;
|
||||
const y = oprava.y;
|
||||
const htmlElement = oprava.htmlElement;
|
||||
const pointer = oprava.pointer;
|
||||
|
||||
par.appendChild(pointer);
|
||||
par.appendChild(htmlElement);
|
||||
|
||||
const delta_y = (y > bott_max) ? 0: bott_max - y + H_SKIP;
|
||||
|
||||
pointer.style.left = x;
|
||||
pointer.style.top = y;
|
||||
pointer.style.width = w - x + W_SKIP;
|
||||
pointer.style.height = POINTER_MIN_H + delta_y;
|
||||
|
||||
htmlElement.style.left = w + W_SKIP;
|
||||
htmlElement.style.top = y + delta_y;
|
||||
|
||||
bott_max = Math.max(bott_max, htmlElement.offsetTop + htmlElement.offsetHeight + H_SKIP); // FIXME nemám páru, proč +H_SKIP funguje, ale opravuje to bug, že nově vytvořené korektury za sebou neměly mezeru
|
||||
}
|
||||
|
||||
if (par.offsetHeight < bott_max) par.style.height = bott_max;
|
||||
}
|
||||
|
||||
function place_comments() {
|
||||
for (let [img_id, opravy] of Object.entries(comments)) {
|
||||
place_comments_one_div(img_id, opravy)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
{% load static %}
|
||||
|
||||
<div id="korektury-sipky">
|
||||
<button type='button' id="predchozi-korektura" title='Předchozí korektura'>
|
||||
<img class='toggle-button' src='{% static "korektury/imgs/hide.png" %}' alt='⬆'/>
|
||||
</button>
|
||||
<button type='button' id="predchozi-korektura-k-oprave" title='Předchozí korektura k opravě'>
|
||||
<img class='toggle-button' src='{% static "korektury/imgs/hide.png" %}' alt='⬆'/>
|
||||
</button>
|
||||
<button type='button' id="predchozi-korektura-k-zaneseni" title='Předchozí korektura k zaneseni'>
|
||||
<img class='toggle-button' src='{% static "korektury/imgs/hide.png" %}' alt='⬆'/>
|
||||
</button>
|
||||
<br>
|
||||
<button type='button' id="dalsi-korektura" title='Další korektura'>
|
||||
<img class='toggle-button' src='{% static "korektury/imgs/hide.png" %}' alt='⬇' style="transform: rotate(180deg);"/>
|
||||
</button>
|
||||
<button type='button' id="dalsi-korektura-k-oprave" title='Další korektura k opravě'>
|
||||
<img class='toggle-button' src='{% static "korektury/imgs/hide.png" %}' alt='⬇' style="transform: rotate(180deg);"/>
|
||||
</button>
|
||||
<button type='button' id="dalsi-korektura-k-zaneseni" title='Další korektura k zaneseni'>
|
||||
<img class='toggle-button' src='{% static "korektury/imgs/hide.png" %}' alt='⬇' style="transform: rotate(180deg);"/>
|
||||
</button>
|
||||
<button type='button' id='korektury-aktualizace'
|
||||
title='Aktualizuj korektury
|
||||
Nemusíš mačkat, pokud ti stačí, že se korektury aktualizují samy každé 2 minuty a při každém přidání korektury/komentáře.'
|
||||
>
|
||||
<img class='toggle-button' src='{% static "korektury/imgs/reload.svg" %}' alt='↻' style="width: 15px"/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const predchozi_k = document.getElementById('predchozi-korektura');
|
||||
const dalsi_k = document.getElementById('dalsi-korektura');
|
||||
const predchozi_k_o = document.getElementById('predchozi-korektura-k-oprave');
|
||||
const dalsi_k_o = document.getElementById('dalsi-korektura-k-oprave');
|
||||
const predchozi_k_z = document.getElementById('predchozi-korektura-k-zaneseni');
|
||||
const dalsi_k_z = document.getElementById('dalsi-korektura-k-zaneseni');
|
||||
|
||||
function dalsi_nebo_predchozi_korektura(dalsi=true, stav=null) {
|
||||
let predchozi = null;
|
||||
for (let [_, opravy] of Object.entries(comments)) {
|
||||
for (const oprava of opravy) {
|
||||
if (stav == null || oprava.status === stav) {
|
||||
const y = oprava.htmlElement.getBoundingClientRect().y;
|
||||
if (y >= -1) {
|
||||
if (dalsi) {
|
||||
if (y > 1) {
|
||||
oprava.htmlElement.scrollIntoView();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (predchozi !== null) predchozi.htmlElement.scrollIntoView(); else alert("Výše už není žádná taková korektura.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
predchozi = oprava;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dalsi && predchozi !== null) {
|
||||
predchozi.htmlElement.scrollIntoView();
|
||||
return;
|
||||
}
|
||||
alert("Žádná další korektura.");
|
||||
}
|
||||
|
||||
predchozi_k.addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(false) });
|
||||
dalsi_k.addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(true) });
|
||||
predchozi_k_o.addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(false, "k_oprave") });
|
||||
dalsi_k_o.addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(true, "k_oprave") });
|
||||
predchozi_k_z.addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(false, "k_zaneseni") });
|
||||
dalsi_k_z.addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(true, "k_zaneseni") });
|
||||
|
||||
// FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET.
|
||||
document.getElementById("korektury-aktualizace").addEventListener("click", _ => update_all({}, false));
|
||||
</script>
|
|
@ -0,0 +1,111 @@
|
|||
<div id="commform-div" style="display: none">
|
||||
<input size="24" name="au" value="{{user.first_name}} {{user.last_name}}" readonly/>
|
||||
<button type="button" id="commform-submit">Oprav!</button>
|
||||
<button type="button" id="commform-close">Zavřít</button>
|
||||
<br/>
|
||||
<textarea id="commform-text" cols=40 rows=10 name="txt"></textarea>
|
||||
<br/>
|
||||
<div id="commform-tagy-info">Úprava tagů celé korektury:</div>
|
||||
<div id="commform-tagy">
|
||||
{% for tag in tagy %}
|
||||
<button type="button" class="korektury-tag" value="{{tag.id}}" data-selected="false" style="background: {{ tag.barva }}; border-color: {{ tag.barva }};">{{tag.nazev}}</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
class _CommForm {
|
||||
constructor() {
|
||||
this.div = document.getElementById('commform-div');
|
||||
this.text = document.getElementById('commform-text');
|
||||
this.submit_button = document.getElementById('commform-submit');
|
||||
const close_button = document.getElementById('commform-close');
|
||||
this.tagy = document.getElementById('commform-tagy');
|
||||
this.tagy_info = document.getElementById('commform-tagy-info');
|
||||
|
||||
|
||||
// ctrl-enter submits form
|
||||
this.text.addEventListener("keydown", ev => {
|
||||
if (ev.code === "Enter" && ev.ctrlKey) this.submit();
|
||||
});
|
||||
|
||||
close_button.addEventListener("click", _ => { this.close(); });
|
||||
this.submit_button.addEventListener("click", _ => { this.submit(); });
|
||||
for (const tag of this.tagy.getElementsByTagName("button")) tag.addEventListener("click", event => { this.toggle_tag(event); });
|
||||
|
||||
this.reset_tags_every_open = true;
|
||||
}
|
||||
|
||||
toggle_tag(event) {
|
||||
const button = event.target;
|
||||
button.dataset.selected = String(button.dataset.selected === "false");
|
||||
}
|
||||
|
||||
reset_tags() { for (const tag of this.tagy.getElementsByTagName("button")) tag.dataset.selected = "false"; }
|
||||
|
||||
|
||||
// schová commform
|
||||
close() { this.div.style.display = 'none'; }
|
||||
|
||||
// zobrazí commform (bez vyplňování)
|
||||
_show(img_id, x, y) {
|
||||
this.submit_button.disabled = false;
|
||||
this.div.style.display = 'block';
|
||||
this.div.style.left = x;
|
||||
this.div.style.top = y;
|
||||
|
||||
const img = document.getElementById("img-" + img_id);
|
||||
img.parentNode.appendChild(commform.div);
|
||||
|
||||
this.text.focus();
|
||||
}
|
||||
|
||||
// fill up comment form and show him
|
||||
show(img_id, x, y, text, oprava_id=-1, komentar_id=-1) {
|
||||
if (this.div.style.display !== 'none' && this.text.value !== "" && !confirm("Zavřít předchozí okénko přidávání korektury / editace komentáře?")) return;
|
||||
|
||||
// set hidden values
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.imgID = img_id;
|
||||
this.oprava_id = oprava_id;
|
||||
this.komentar_id = komentar_id;
|
||||
this.text.value = text;
|
||||
|
||||
// show form
|
||||
if (oprava_id === -1 && komentar_id === -1) {
|
||||
if (this.reset_tags_every_open) this.reset_tags();
|
||||
this.tagy_info.style.display = 'none';
|
||||
} else {
|
||||
const oprava = opravy[oprava_id];
|
||||
this.tagy_info.style.display = 'unset';
|
||||
for (const tag of this.tagy.getElementsByTagName("button"))
|
||||
tag.dataset.selected = String(oprava.tagy.has(parseInt(tag.value)));
|
||||
}
|
||||
|
||||
this._show(img_id, x, y);
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.submit_button.disabled = true;
|
||||
const data = new FormData(CSRF_FORM);
|
||||
data.append('x', this.x);
|
||||
data.append('y', this.y);
|
||||
data.append('img_id', this.imgID);
|
||||
data.append('oprava_id', this.oprava_id);
|
||||
data.append('komentar_id', this.komentar_id);
|
||||
|
||||
const tagy = [];
|
||||
for (const tag of this.tagy.getElementsByTagName("button")) {
|
||||
if (tag.dataset.selected !== "false") tagy.push(tag.value);
|
||||
}
|
||||
data.append('tagy', String(tagy));
|
||||
|
||||
data.append('text', this.text.value);
|
||||
|
||||
update_all({method: 'POST', body: data}, true, () => {this.close(); this.submit_button.disabled = false;});
|
||||
}
|
||||
}
|
||||
|
||||
const commform = new _CommForm();
|
||||
</script>
|
106
korektury/templates/korektury/korekturovatko/__komentar.html
Normal file
106
korektury/templates/korektury/korekturovatko/__komentar.html
Normal file
|
@ -0,0 +1,106 @@
|
|||
{% load static %}
|
||||
|
||||
<div class='comment' id='prekomentar' {# id='k{{k.id}}' #}>
|
||||
<div class='corr-header'>
|
||||
<div class='author'>{# {{k.autor}} #}</div>
|
||||
|
||||
<div class='float-right'>
|
||||
<button type='button' style='display: none' class='del-comment' title='Smaž komentář'>
|
||||
<img src='{% static "korektury/imgs/delete.png" %}' alt='del'/>
|
||||
</button>
|
||||
|
||||
<button type='button' class='update-comment' title='Uprav komentář'>
|
||||
<img src='{% static "korektury/imgs/edit.png"%}' alt='edit'/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class='komtext'>{# {{k.text|linebreaks}} #}</div>
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
const prekomentar = document.getElementById('prekomentar');
|
||||
const komentare = {};
|
||||
|
||||
class Komentar {
|
||||
static update_or_create(komentar_data, oprava) {
|
||||
const id = komentar_data['id'];
|
||||
if (id in komentare) komentare[id].update(komentar_data);
|
||||
else new Komentar(komentar_data, oprava);
|
||||
}
|
||||
|
||||
#autor; #text;
|
||||
htmlElement;
|
||||
id; oprava; {# komentar_data; #}
|
||||
autor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param komentar_data
|
||||
* @param {Oprava} oprava
|
||||
*/
|
||||
constructor(komentar_data, oprava) {
|
||||
this.htmlElement = prekomentar.cloneNode(true);
|
||||
this.#autor = this.htmlElement.getElementsByClassName('author')[0];
|
||||
this.#text = this.htmlElement.getElementsByClassName('komtext')[0];
|
||||
|
||||
this.id = komentar_data['id'];
|
||||
this.htmlElement.id = 'k' + this.id;
|
||||
|
||||
this.oprava = oprava;
|
||||
this.oprava.add_komentar_htmlElement(this.htmlElement);
|
||||
|
||||
this.update(komentar_data);
|
||||
|
||||
this.htmlElement.getElementsByClassName('update-comment')[0].addEventListener('click', _ => this.#update_comment());
|
||||
this.htmlElement.getElementsByClassName('del-comment')[0].addEventListener('click', _ => this.#delete_comment());
|
||||
|
||||
komentare[this.id] = this;
|
||||
}
|
||||
|
||||
update(komentar_data) {
|
||||
{# this.komentar_data = komentar_data; #}
|
||||
this.set_autor(komentar_data['autor']);
|
||||
this.set_text(komentar_data['text']);
|
||||
};
|
||||
|
||||
set_autor(autor) {
|
||||
this.#autor.textContent=autor;
|
||||
this.autor = autor;
|
||||
};
|
||||
|
||||
set_text(text) {
|
||||
this.#text.innerHTML=text;
|
||||
};
|
||||
|
||||
|
||||
// show comment form when 'update-comment' button pressed
|
||||
#update_comment() {
|
||||
return commform.show(this.oprava.img_id, this.oprava.x, this.oprava.y, this.#text.textContent, this.oprava.id, this.id);
|
||||
}
|
||||
|
||||
#delete_comment() {
|
||||
if (confirm('Opravdu smazat komentář?')) {
|
||||
const data = new FormData(CSRF_FORM);
|
||||
data.append('komentar_id', this.id);
|
||||
fetch('{% url "korektury_api_komentar_smaz" %}', {method: 'POST', body: data})
|
||||
.then(response => {
|
||||
if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);}
|
||||
this.smaz_pouze_na_strance();
|
||||
place_comments();
|
||||
})
|
||||
.catch(error => {alert('Něco se nepovedlo:' + error);});
|
||||
}
|
||||
}
|
||||
|
||||
smaz_pouze_na_strance() {
|
||||
delete komentare[this.id];
|
||||
this.htmlElement.remove();
|
||||
}
|
||||
}
|
||||
</script>
|
189
korektury/templates/korektury/korekturovatko/__oprava.html
Normal file
189
korektury/templates/korektury/korekturovatko/__oprava.html
Normal file
|
@ -0,0 +1,189 @@
|
|||
{% load static %}
|
||||
|
||||
<div id='prepointer' {# id='op{{o.id}}-pointer' #}
|
||||
class='pointer'
|
||||
data-highlight='false'
|
||||
{# data-opravastatus='{{o.status}}' #}
|
||||
></div>
|
||||
|
||||
<div id='preoprava' {# name='op{{o.id}}' id='op{{o.id}}' #}
|
||||
class='oprava'
|
||||
{# data-opravastatus='{{o.status}}' #}
|
||||
data-opravazobrazit='true'
|
||||
>
|
||||
<div class='corr-tagy'>
|
||||
{# {% for tag in o.tagy %} <span style="background:{{ tag.barva }}>{{ tag.text }}<span/> #}
|
||||
</div>
|
||||
|
||||
<div class='corr-body'>
|
||||
{# {% for k in o.komentare %} {% include "korektury/korekturovatko/__komentar.html" %} {% endfor %} #}
|
||||
</div>
|
||||
|
||||
<div class='corr-header'>
|
||||
<span class='float-right'>
|
||||
<span class='corr-buttons'>
|
||||
<button type='button' style='display: none' class='del' title='Smaž opravu'>
|
||||
<img src='{% static "korektury/imgs/delete.png"%}' alt='🗑️'/>
|
||||
</button>
|
||||
<button type='button' class='action' value='k_oprave' title='Označ jako neopravené'>
|
||||
<img src='{% static "korektury/imgs/undo.png"%}' alt='↪'/>
|
||||
</button>
|
||||
<button type='button' class='action' value='opraveno' title='Označ jako opravené'>
|
||||
<img src='{% static "korektury/imgs/check.png"%}' alt='✔️'/>
|
||||
</button>
|
||||
<button type='button' class='action' value='neni_chyba' title='Označ, že se nebude měnit'>
|
||||
<img src='{% static "korektury/imgs/cross.png" %}' alt='❌'/>
|
||||
</button>
|
||||
<button type='button' class='action' value='k_zaneseni' title='Označ jako připraveno k zanesení'>
|
||||
<img src='{% static "korektury/imgs/tex.png" %}' alt='TeX'/>
|
||||
</button>
|
||||
|
||||
<a href='{% url "admin:korektury_oprava_change" -1 %}' class='edit' title='Uprav korekturu jako takovou.' style="text-decoration: none;"> {# FIXME Udělat z toho tlačítko? #}
|
||||
<img src='{% static "korektury/imgs/edit.png"%}' alt='✏️' style="opacity: 0.5;"/> {# FIXME Odlišit jinak než pomocí opacity? #}
|
||||
</a>
|
||||
<button type='button' class='komentovat_disabled' title='Korekturu nelze komentovat, protože už je uzavřená' disabled=''>
|
||||
<img src='{% static "korektury/imgs/comment-gr.png" %}' alt='💭'/>
|
||||
</button>
|
||||
<button type='button' class='komentovat' title='Komentovat'>
|
||||
<img src='{% static "korektury/imgs/comment.png" %}' alt='💭'/>
|
||||
</button>
|
||||
</span>
|
||||
|
||||
<button type='button' class='toggle-vis' title='Skrýt/Zobrazit'>
|
||||
<img class='toggle-button' src='{% static "korektury/imgs/hide.png" %}' alt='⬆'/>
|
||||
</button>
|
||||
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const preoprava = document.getElementById('preoprava');
|
||||
const prepointer = document.getElementById('prepointer');
|
||||
const opravy = {};
|
||||
|
||||
class Oprava {
|
||||
static update_or_create(oprava_data) {
|
||||
const id = oprava_data['id'];
|
||||
if (id in opravy) return opravy[id].update(oprava_data);
|
||||
else return new Oprava(oprava_data);
|
||||
}
|
||||
|
||||
#komentare; #tagy;
|
||||
htmlElement; pointer;
|
||||
id; x; y; img_id; status; zobrazit = true; {# oprava_data; #}
|
||||
tagy;
|
||||
|
||||
constructor(oprava_data) {
|
||||
this.htmlElement = preoprava.cloneNode(true);
|
||||
this.pointer = prepointer.cloneNode(true);
|
||||
this.#komentare = this.htmlElement.getElementsByClassName('corr-body')[0];
|
||||
this.#tagy = this.htmlElement.getElementsByClassName('corr-tagy')[0];
|
||||
|
||||
this.id = oprava_data['id'];
|
||||
this.htmlElement.id = 'op' + this.id;
|
||||
this.pointer.id = 'op' + this.id + '-pointer';
|
||||
|
||||
this.x = oprava_data['x'];
|
||||
this.y = oprava_data['y'];
|
||||
this.img_id = oprava_data['strana'];
|
||||
|
||||
this.update(oprava_data);
|
||||
|
||||
this.htmlElement.getElementsByClassName('toggle-vis')[0].addEventListener('click', _ => this.#toggle_visibility());
|
||||
for (const button of this.htmlElement.getElementsByClassName('action'))
|
||||
button.addEventListener('click', async event => this.#zmenStavKorektury(event));
|
||||
this.htmlElement.getElementsByClassName('komentovat')[0].addEventListener('click', _ => this.#comment())
|
||||
this.htmlElement.getElementsByClassName('del')[0].addEventListener('click', _ => this.#delete());
|
||||
const odkaz_editace = this.htmlElement.getElementsByClassName('edit')[0];
|
||||
odkaz_editace.href = odkaz_editace.href.replace("-1", this.id);
|
||||
odkaz_editace.onclick = ev => { if (!confirm("Editace korektury je velmi pokročilá featura umožňující přesouvat korekturu nebo přidávat informované orgy, opravdu chceš pokračovat do adminu?")) ev.preventDefault(); };
|
||||
|
||||
this.htmlElement.addEventListener('mouseover', _ => this.pointer.dataset.highlight = 'true');
|
||||
this.htmlElement.addEventListener('mouseout', _ => this.pointer.dataset.highlight = 'false');
|
||||
|
||||
opravy[this.id] = this;
|
||||
if (this.img_id in comments) comments[this.img_id].push(this); else alert("Někdo korekturoval stranu, která neexistuje. Dejte vědět webařům :)");
|
||||
}
|
||||
|
||||
update(oprava_data) {
|
||||
{# this.oprava_data = oprava_data; #}
|
||||
this.set_status(oprava_data['status']);
|
||||
this.#tagy.innerHTML = "";
|
||||
this.tagy = new Set();
|
||||
for (const tag of oprava_data["tagy"]) {
|
||||
this.tagy.add(tag["id"]);
|
||||
const span = document.createElement("span");
|
||||
span.innerHTML = tag["nazev"];
|
||||
span.classList.add("korektury-tag");
|
||||
span.style.backgroundColor = tag["barva"];
|
||||
this.#tagy.appendChild(span);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
set_status(status) {
|
||||
this.status = status;
|
||||
this.htmlElement.dataset.opravastatus=status;
|
||||
this.pointer.dataset.opravastatus=status;
|
||||
};
|
||||
|
||||
add_komentar_htmlElement(htmlElement) { this.#komentare.appendChild(htmlElement); }
|
||||
|
||||
|
||||
|
||||
|
||||
// hide or show text of correction
|
||||
toggle_visibility() {
|
||||
this.zobrazit = !this.zobrazit;
|
||||
this.htmlElement.dataset.opravazobrazit = String(this.zobrazit);
|
||||
}
|
||||
#toggle_visibility(){
|
||||
this.toggle_visibility();
|
||||
place_comments()
|
||||
}
|
||||
|
||||
// show comment form, when 'comment' button pressed
|
||||
#comment() { commform.show(this.img_id, this.x, this.y, "", this.id); }
|
||||
|
||||
#zmenStavKorektury(event) {
|
||||
const data = new FormData(CSRF_FORM);
|
||||
data.append('id', this.id);
|
||||
data.append('action', event.target.value);
|
||||
|
||||
fetch('{% url "korektury_api_oprava_stav" %}', {method: 'POST', body: data})
|
||||
.then(response => {
|
||||
if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);}
|
||||
else response.json().then(data => {
|
||||
this.set_status(data['status']);
|
||||
updatuj_pocty_stavu();
|
||||
});
|
||||
})
|
||||
.catch(error => {alert('Něco se nepovedlo:' + error);});
|
||||
}
|
||||
|
||||
#delete() {
|
||||
if (confirm('Opravdu smazat korekturu?')) {
|
||||
const data = new FormData(CSRF_FORM);
|
||||
data.append('oprava_id', this.id);
|
||||
fetch('{% url "korektury_api_oprava_smaz" %}', {method: 'POST', body: data})
|
||||
.then(response => {
|
||||
if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);}
|
||||
this.#smaz_pouze_na_strance()
|
||||
updatuj_pocty_stavu();
|
||||
updatuj_pocty_zasluh();
|
||||
place_comments();
|
||||
})
|
||||
.catch(error => {alert('Něco se nepovedlo:' + error);});
|
||||
}
|
||||
}
|
||||
|
||||
#smaz_pouze_na_strance() {
|
||||
comments[this.img_id].splice(comments[this.img_id].indexOf(this), 1);
|
||||
delete opravy[this.id];
|
||||
for (const komentar of Object.values(komentare)) if (komentar.oprava === this) komentar.smaz_pouze_na_strance();
|
||||
this.htmlElement.remove();
|
||||
this.pointer.remove();
|
||||
}
|
||||
}
|
||||
</script>
|
54
korektury/templates/korektury/korekturovatko/__stranky.html
Normal file
54
korektury/templates/korektury/korekturovatko/__stranky.html
Normal file
|
@ -0,0 +1,54 @@
|
|||
{% for i in img_indexes %}
|
||||
<div class='imgdiv'>
|
||||
<img
|
||||
id='img-{{i}}'
|
||||
width='1021' height='1448'
|
||||
src='/media/korektury/img/{{korekturovanepdf.get_prefix}}-{{i}}.png'
|
||||
alt='Strana {{ i|add:1 }}'
|
||||
class="strana"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
{% endfor %}
|
||||
|
||||
<script>
|
||||
// Mapování stránka -> korektury
|
||||
/**
|
||||
* @type {Object.<number, Array<Oprava>>}
|
||||
*/
|
||||
const comments = {
|
||||
{% for s in img_indexes %}
|
||||
{{s}}: []{% if not forloop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
};
|
||||
|
||||
// show comment form, when clicked to image
|
||||
for (const image of document.getElementsByClassName('strana')) {
|
||||
image.addEventListener('click', ev => {
|
||||
switch (document.body.dataset.status) {
|
||||
case 'zanaseni':
|
||||
if (!confirm('Právě jsou zanášeny korektury, opravdu chcete přidat novou?'))
|
||||
return;
|
||||
break;
|
||||
case 'zastarale':
|
||||
if (!confirm('Toto PDF je již zastaralé, opravdu chcete vytvořit korekturu?'))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
let dx, dy;
|
||||
const par = image.parentNode;
|
||||
if (ev.pageX != null) {
|
||||
dx = ev.pageX - par.offsetLeft;
|
||||
dy = ev.pageY - par.offsetTop;
|
||||
} else { //IE a další
|
||||
dx = ev.offsetX;
|
||||
dy = ev.offsetY;
|
||||
}
|
||||
const img_id = image.id.substring(4);
|
||||
commform.show(img_id, dx, dy, '');
|
||||
console.log("Pro přesun korektur: strana = " + img_id + ", x = " + dx + ", y = " + dy);
|
||||
});
|
||||
}
|
||||
</script>
|
53
korektury/templates/korektury/korekturovatko/_main.html
Normal file
53
korektury/templates/korektury/korekturovatko/_main.html
Normal file
|
@ -0,0 +1,53 @@
|
|||
{% include "korektury/korekturovatko/__edit_komentar.html" %}
|
||||
|
||||
{% include "korektury/korekturovatko/__stranky.html" %}
|
||||
|
||||
{# {% for o in opravy %} {% include "korektury/korekturovatko/__oprava.html" %} {% endfor %} #}
|
||||
{% include "korektury/korekturovatko/__oprava.html" %}
|
||||
{% include "korektury/korekturovatko/__komentar.html" %}
|
||||
|
||||
{% include "korektury/korekturovatko/__dalsi_korektura.html" %}
|
||||
|
||||
<script>
|
||||
/**
|
||||
*
|
||||
* @param {RequestInit} data
|
||||
* @param {Boolean} catchError
|
||||
* @param pri_uspechu Akce, která se má provést při úspěchu (speciálně zavřít formulář)
|
||||
*/
|
||||
function update_all(data={}, catchError=true, pri_uspechu=null) { // FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET.
|
||||
fetch('{% url "korektury_api_opravy_a_komentare" korekturovanepdf.id %}', data)
|
||||
.then(response => {
|
||||
if (!response.ok && catchError) {alert('Něco se nepovedlo:' + response.statusText);}
|
||||
else response.json().then(data => {
|
||||
for (const oprava_data of data["context"]) {
|
||||
const oprava = Oprava.update_or_create(oprava_data);
|
||||
for (const komentar_data of oprava_data["komentare"]) {
|
||||
Komentar.update_or_create(komentar_data, oprava);
|
||||
}
|
||||
}
|
||||
|
||||
updatuj_pocty_stavu();
|
||||
updatuj_pocty_zasluh();
|
||||
place_comments();
|
||||
if (pri_uspechu) pri_uspechu();
|
||||
});
|
||||
})
|
||||
.catch(error => {if (catchError) alert('Něco se nepovedlo:' + error);});
|
||||
}
|
||||
|
||||
window.addEventListener("load", _ => {
|
||||
update_all({}, true, _ => {
|
||||
if (location.hash !== "") location.hash = location.hash; // Po rozházení korektur sescrollujeme na kotvu v URL
|
||||
});
|
||||
});
|
||||
|
||||
// FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET.
|
||||
setInterval(() => update_all({}, false), 120000); // Každý dvě minuty fetchni korektury
|
||||
</script>
|
||||
|
||||
<form id='CSRF_form' style='display: none'>{% csrf_token %}</form>
|
||||
|
||||
<script>
|
||||
const CSRF_FORM = document.getElementById('CSRF_form');
|
||||
</script>
|
|
@ -0,0 +1,83 @@
|
|||
Zobrazit:
|
||||
<input type="checkbox"
|
||||
id="k_oprave_checkbox"
|
||||
name="k_oprave_checkbox"
|
||||
onchange="toggle_corrections('k_oprave')" checked>
|
||||
<label for="k_oprave_checkbox">K opravě (<span id="k_oprave_pocet">↺</span>)</label>
|
||||
<input type="checkbox"
|
||||
id="opraveno_checkbox"
|
||||
name="opraveno_checkbox"
|
||||
onchange="toggle_corrections('opraveno')" checked>
|
||||
<label for="opraveno_checkbox">Opraveno (<span id="opraveno_pocet">↺</span>)</label>
|
||||
<input type="checkbox"
|
||||
id="neni_chyba_checkbox"
|
||||
name="neni_chyba_checkbox"
|
||||
onchange="toggle_corrections('neni_chyba')" checked>
|
||||
<label for="neni_chyba_checkbox">Není chyba (<span id="neni_chyba_pocet">↺</span>)</label>
|
||||
<input type="checkbox"
|
||||
id="k_zaneseni_checkbox"
|
||||
name="k_zaneseni_checkbox"
|
||||
onchange="toggle_corrections('k_zaneseni')" checked>
|
||||
<label for="k_zaneseni_checkbox">K zanesení (<span id="k_zaneseni_pocet">↺</span>)</label>
|
||||
|
||||
|
||||
<button type="button" id="sbal-korektury">Sbal korektury</button>
|
||||
<button type="button" id="rozbal-korektury">Rozbal korektury</button>
|
||||
|
||||
<hr/>
|
||||
|
||||
<script>
|
||||
const spany_s_pocty_stavu = {
|
||||
'k_oprave': document.getElementById('k_oprave_pocet'),
|
||||
'opraveno': document.getElementById('opraveno_pocet'),
|
||||
'neni_chyba': document.getElementById('neni_chyba_pocet'),
|
||||
'k_zaneseni': document.getElementById('k_zaneseni_pocet'),
|
||||
}
|
||||
|
||||
function toggle_corrections(aclass)
|
||||
{
|
||||
const stylesheets = document.styleSheets;
|
||||
let ssheet = null;
|
||||
for (let i=0; i<stylesheets.length; i++){
|
||||
if (stylesheets[i].title === "opraf-css"){
|
||||
ssheet = stylesheets[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! ssheet){
|
||||
return;
|
||||
}
|
||||
for (let i=0; i<ssheet.cssRules.length; i++){
|
||||
const rule = ssheet.cssRules[i];
|
||||
if (rule.selectorText === '[data-opravastatus="'+aclass+'"]'){
|
||||
if (rule.style.display === ""){
|
||||
rule.style.display = "none";
|
||||
} else {
|
||||
rule.style.display = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
place_comments();
|
||||
}
|
||||
|
||||
function updatuj_pocty_stavu() {
|
||||
const pocty_stavu = {};
|
||||
for (const stav of Object.keys(spany_s_pocty_stavu)) pocty_stavu[stav] = 0;
|
||||
for (const oprava of Object.values(opravy)) {
|
||||
if (!(oprava.status in pocty_stavu)) pocty_stavu[oprava.status] = 0;
|
||||
pocty_stavu[oprava.status] += 1;
|
||||
}
|
||||
for (let [stav, pocet] of Object.entries(pocty_stavu)) spany_s_pocty_stavu[stav].innerText = pocet;
|
||||
}
|
||||
|
||||
document.getElementById("sbal-korektury").addEventListener("click", () => {
|
||||
for (const oprava of Object.values(opravy))
|
||||
if (oprava.zobrazit) oprava.toggle_visibility();
|
||||
place_comments();
|
||||
})
|
||||
document.getElementById("rozbal-korektury").addEventListener("click", () => {
|
||||
for (const oprava of Object.values(opravy))
|
||||
if (!oprava.zobrazit) oprava.toggle_visibility();
|
||||
place_comments();
|
||||
})
|
||||
</script>
|
|
@ -1,5 +1,5 @@
|
|||
{# Template starající se o formulář na změnu stavu PDF (včetně jeho odeslání) #}
|
||||
<b>Změnit stav PDF:</b>
|
||||
<h4>Změnit stav PDF:</h4>
|
||||
<i>Aktuální: {{korekturovanepdf.status}}</i>
|
||||
<br>
|
||||
<form method="post" id="PDFSTAV_FORM">
|
||||
{% csrf_token %}
|
||||
|
@ -13,24 +13,19 @@
|
|||
</form>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* Formulář měnící stav korekturovaného PDF
|
||||
* @type {HTMLFormElement}
|
||||
*/
|
||||
const pdfstav_form = document.getElementById('PDFSTAV_FORM');
|
||||
|
||||
/**
|
||||
* Fetchne stav korekturovaného PDF a změní ho na dané stránce.
|
||||
* FIXME: nemění, který radio-button je vybrán.
|
||||
* @param {RequestInit} data FormData a jiné náležitosti (method: POST) posílané při změně stavu korekturovaného PDF
|
||||
* @param {Boolean} catchError jestli padat hlasitě (pokud se aktualizuje automaticky a spadne to např. na nepřítomnost sítě, pak není třeba informovat uživatele)
|
||||
*
|
||||
* @param {RequestInit} data
|
||||
* @param {Boolean} catchError
|
||||
*/
|
||||
function fetchStav(data, catchError=true) {
|
||||
fetch("{% url 'korektury_api_pdf_stav' korekturovanepdf.id %}", data
|
||||
)
|
||||
.then(response => {
|
||||
if (!response.ok) { if (catchError) alert("Něco se nepovedlo:" + response.statusText);}
|
||||
else response.json().then(data => document.body.dataset.stav_pdf = data["status"]);
|
||||
else response.json().then(data => document.body.dataset.status = data["status"]);
|
||||
})
|
||||
.catch(error => {if (catchError) alert("Něco se nepovedlo:" + error);});
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
{# Část korekturovátka, která obsahuje všechno okolo korektur #}
|
||||
{% include "korektury/korekturovatko/moduly/schovani_korektur.html" %}
|
||||
|
||||
{% include "korektury/korekturovatko/moduly/edit_komentar.html" %}
|
||||
|
||||
{% include "korektury/korekturovatko/moduly/stranky_pdfka.html" %}
|
||||
|
||||
{# {% for k in korektury %} {% include "korektury/korekturovatko/korektura.html" %} {% endfor %} #}
|
||||
{% include "korektury/korekturovatko/moduly/korektura.html" %}
|
||||
{% include "korektury/korekturovatko/moduly/komentar.html" %}
|
||||
|
||||
{% include "korektury/korekturovatko/moduly/dalsi_korektura.html" %}
|
||||
|
||||
<script>
|
||||
/**
|
||||
* Fetchne korektury a komentáře a na základě toho aktualizuje všechno
|
||||
* (korektury, komentáře, zásluhy, počty korektur v daných stavech, umístění korektur)
|
||||
* @param {RequestInit} data FormData a jiné náležitosti (method: POST) posílané při přidání/úpravě korektury/komentáře
|
||||
* @param {Boolean} catchError jestli padat hlasitě (pokud se aktualizuje automaticky a spadne to např. na nepřítomnost sítě, pak není třeba informovat uživatele)
|
||||
* @param {(() => *)?} pri_uspechu akce, která se má provést při úspěchu (speciálně zavřít formulář)
|
||||
*/
|
||||
function aktualizuj_vse(data={}, catchError=true, pri_uspechu=null) { // FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET.
|
||||
fetch('{% url "korektury_api_opravy_a_komentare" korekturovanepdf.id %}', data)
|
||||
.then(response => {
|
||||
if (!response.ok && catchError) {alert('Něco se nepovedlo:' + response.statusText);}
|
||||
else response.json().then(data => {
|
||||
for (const korektura_data of data["context"]) {
|
||||
const korektura = Korektura.aktualizuj_nebo_vytvor(korektura_data);
|
||||
for (const komentar_data of korektura_data["komentare"]) {
|
||||
Komentar.aktualizuj_nebo_vytvor(komentar_data, korektura);
|
||||
}
|
||||
}
|
||||
|
||||
aktualizuj_pocty_stavu();
|
||||
aktualizuj_pocty_zasluh();
|
||||
umisti_korektury();
|
||||
if (pri_uspechu) pri_uspechu();
|
||||
});
|
||||
})
|
||||
.catch(error => {if (catchError) alert('Něco se nepovedlo:' + error);});
|
||||
}
|
||||
|
||||
window.addEventListener("load", _ => {
|
||||
aktualizuj_vse({}, true, () => {
|
||||
if (location.hash !== "") { // Po rozházení korektur sescrollujeme na kotvu v URL
|
||||
const h = location.hash.substring(1);
|
||||
location.hash = "HACK";
|
||||
location.hash = h;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET.
|
||||
setInterval(() => aktualizuj_vse({}, false), 120000); // Každý dvě minuty fetchni korektury
|
||||
</script>
|
||||
|
||||
{# Formulář, který mouhou použít tlačítka bez svého formuláře k vytvoření POST requestu, viz CSRF_FORM níže #}
|
||||
<form id='CSRF_form' style='display: none'>{% csrf_token %}</form>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* Formulář, který mouhou použít tlačítka bez svého formuláře k vytvoření POST requestu
|
||||
* @type {HTMLFormElement}
|
||||
*/
|
||||
const CSRF_FORM = document.getElementById('CSRF_form');
|
||||
</script>
|
|
@ -1,14 +1,14 @@
|
|||
{# Okolí samotného hlavni_cast_korekturovatka.html, tedy „povinné HTML věci“, informace o korekturovaném PDF a starání se o stav PDF #}
|
||||
{% load static %}
|
||||
|
||||
<html lang='cs'>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="stylesheet" title="opraf-css" type="text/css" media="screen, projection" href="{% static "korektury/opraf.css"%}?version=3" />
|
||||
<link href="{% static 'css/rozliseni.css' %}?version=3" rel="stylesheet">
|
||||
<link rel="stylesheet" title="opraf-css" type="text/css" media="screen, projection" href="{% static "korektury/opraf.css"%}?version=2" />
|
||||
<link href="{% static 'css/rozliseni.css' %}?version=2" rel="stylesheet">
|
||||
<script src="{% static "korektury/opraf.js"%}?version=2"></script>
|
||||
<title>Korektury {{korekturovanepdf.nazev}}</title>
|
||||
</head>
|
||||
<body class="{{ LOCAL_TEST_PROD }}web" data-stav_pdf="{{ korekturovanepdf.status }}">
|
||||
<body class="{{ LOCAL_TEST_PROD }}web" data-status="{{ korekturovanepdf.status }}">
|
||||
|
||||
<h1>Korektury {{korekturovanepdf.nazev}}</h1>
|
||||
|
||||
|
@ -27,9 +27,11 @@
|
|||
<a href="https://mam.mff.cuni.cz/wiki">wiki</a> |
|
||||
<hr />
|
||||
|
||||
{% include "korektury/korekturovatko/hlavni_cast_korekturovatka.html" %}
|
||||
{% include "korektury/korekturovatko/_schovani_korektur.html" %}
|
||||
|
||||
{% include "korektury/korekturovatko/zmena_stavu_pdf.html" %}
|
||||
{% include "korektury/korekturovatko/_main.html" %}
|
||||
|
||||
{% include "korektury/korekturovatko/_zmena_stavu.html" %}
|
||||
|
||||
<hr/>
|
||||
<p>
|
||||
|
@ -37,14 +39,9 @@
|
|||
<hr>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* HTML prvek, kam se zapíší (pomocí .innerHTML) počty korektur jednotlivých autorů
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
const span_s_pocty_autoru = document.getElementById("pocty_autoru")
|
||||
|
||||
/** Aktualizuje, kolik který autor má komentářů u daného korekturovaného PDF. */
|
||||
function aktualizuj_pocty_zasluh() {
|
||||
function updatuj_pocty_zasluh() {
|
||||
const pocty_autoru = {};
|
||||
for (let komentar of Object.values(komentare)) {
|
||||
if (!(komentar.autor in pocty_autoru)) pocty_autoru[komentar.autor] = 0;
|
|
@ -1,77 +0,0 @@
|
|||
{# Template starající se o tlačítka v levém dolním rohu, především skákající na další/předchozí korekturu. #}
|
||||
{% load static %}
|
||||
|
||||
<div id="korektury-sipky">
|
||||
<button type='button' id="predchozi-korektura" title='Předchozí korektura'>
|
||||
<img src='{% static "korektury/imgs/hide.png" %}' alt='⬆'/>
|
||||
</button>
|
||||
<button type='button' id="predchozi-korektura-k-oprave" title='Předchozí korektura k opravě'>
|
||||
<img src='{% static "korektury/imgs/hide.png" %}' alt='⬆'/>
|
||||
</button>
|
||||
<button type='button' id="predchozi-korektura-k-zaneseni" title='Předchozí korektura k zaneseni'>
|
||||
<img src='{% static "korektury/imgs/hide.png" %}' alt='⬆'/>
|
||||
</button>
|
||||
<br>
|
||||
<button type='button' id="dalsi-korektura" title='Další korektura'>
|
||||
<img src='{% static "korektury/imgs/hide.png" %}' alt='⬇' style="transform: rotate(180deg);"/>
|
||||
</button>
|
||||
<button type='button' id="dalsi-korektura-k-oprave" title='Další korektura k opravě'>
|
||||
<img src='{% static "korektury/imgs/hide.png" %}' alt='⬇' style="transform: rotate(180deg);"/>
|
||||
</button>
|
||||
<button type='button' id="dalsi-korektura-k-zaneseni" title='Další korektura k zaneseni'>
|
||||
<img src='{% static "korektury/imgs/hide.png" %}' alt='⬇' style="transform: rotate(180deg);"/>
|
||||
</button>
|
||||
<button type='button' id='korektury-aktualizace'
|
||||
title='Aktualizuj korektury
|
||||
Nemusíš mačkat, pokud ti stačí, že se korektury aktualizují samy každé 2 minuty a při každém přidání korektury/komentáře.'
|
||||
>
|
||||
<img src='{% static "korektury/imgs/reload.svg" %}' alt='↻' style="width: 15px"/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('predchozi-korektura').addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(false) });
|
||||
document.getElementById('dalsi-korektura').addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(true) });
|
||||
document.getElementById('predchozi-korektura-k-oprave').addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(false, "k_oprave") });
|
||||
document.getElementById('dalsi-korektura-k-oprave').addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(true, "k_oprave") });
|
||||
document.getElementById('predchozi-korektura-k-zaneseni').addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(false, "k_zaneseni") });
|
||||
document.getElementById('dalsi-korektura-k-zaneseni').addEventListener('click', _ => { dalsi_nebo_predchozi_korektura(true, "k_zaneseni") });
|
||||
|
||||
// FIXME není mi jasné, zda v {} nemá být `cache: "no-store"`, aby prohlížeč necachoval GET.
|
||||
document.getElementById("korektury-aktualizace").addEventListener("click", _ => aktualizuj_vse({}, false));
|
||||
|
||||
/**
|
||||
* Sescrolluje na další nebo předchozí (vůči hornímu okraji okna) korekturu (v daném stavu).
|
||||
* V případě neexistence takové korektury vyhodí alert.
|
||||
* @param {boolean} dalsi reprezentuje, zda chceme další nebo předchozí korekturu
|
||||
* @param {?string} stav pokud je nenullový, tak ignoruje korektury v jiném stavu
|
||||
*/
|
||||
function dalsi_nebo_predchozi_korektura(dalsi=true, stav=null) {
|
||||
let predchozi = null;
|
||||
for (const strana of setrizene_strany) {
|
||||
// strana.setrid_korektury(); // Nemělo by být potřeba, protože se volá vždy, když se renderují korektury.
|
||||
for (const korektura of strana.korektury) {
|
||||
if (stav == null || korektura.stav === stav) {
|
||||
const y = korektura.htmlElement.getBoundingClientRect().y;
|
||||
if (y >= -1) {
|
||||
if (dalsi) {
|
||||
if (y > 1) {
|
||||
korektura.htmlElement.scrollIntoView();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (predchozi !== null) predchozi.htmlElement.scrollIntoView(); else alert("Výše už není žádná taková korektura.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
predchozi = korektura;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dalsi && predchozi !== null) {
|
||||
predchozi.htmlElement.scrollIntoView();
|
||||
return;
|
||||
}
|
||||
alert("Žádná další korektura.");
|
||||
}
|
||||
</script>
|
|
@ -1,166 +0,0 @@
|
|||
{# Template starající se o editační/přidávací formulář. #}
|
||||
<div id="korekturovaci-formular-div" style="display: none">
|
||||
<input size="24" name="au" value="{{user.osoba}}" readonly/>
|
||||
<button type="button" id="korekturovaci-formular-odesli">Oprav!</button>
|
||||
<button type="button" id="korekturovaci-formular-zavri">Zavřít</button>
|
||||
<br/>
|
||||
<textarea id="korekturovaci-formular-text" cols=40 rows=10 name="txt"></textarea>
|
||||
<br/>
|
||||
<div id="korekturovaci-formular-tagy-info">Úprava tagů celé korektury:</div>
|
||||
<div id="korekturovaci-formular-tagy">
|
||||
{% for tag in tagy %}
|
||||
<button type="button" class="korektury-tag" value="{{tag.id}}" data-vybran="false" style="background: {{ tag.barva }}; border-color: {{ tag.barva }};">{{tag.nazev}}</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
/** V podstatě singleton (viz korekturovaci_formular) starající se o editační/přidávací formulář. */
|
||||
class _KorekturovaciFormular {
|
||||
/**
|
||||
* <div> obsahující celý formulář.
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
div;
|
||||
/**
|
||||
* Políčko, kam uživatel vyplňuje text.
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
text;
|
||||
/**
|
||||
* Tlačítko odeslat. Často ho chceme disablenout.
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
odesilaci_button;
|
||||
/**
|
||||
* <div> obsahující všechny tagy, pomocí tagy.getElementsByTagName("button") umíme dělat operace nad všemi tagy.
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
tagy;
|
||||
/**
|
||||
* Text upozorňující na to, že tagy nepřidáváme, ale editujeme. (Tj. chceme ho schovat, když vytváříme novou korekturu.)
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
tagy_info;
|
||||
/**
|
||||
* zda při přidávání nové korektury mají být všechny tagy odvybrané, nebo mají kopírovat předchozí nastavení
|
||||
* @type {boolean}
|
||||
*/
|
||||
pri_otevreni_odvyber_tagy;
|
||||
|
||||
constructor() {
|
||||
this.div = document.getElementById('korekturovaci-formular-div');
|
||||
this.text = document.getElementById('korekturovaci-formular-text');
|
||||
this.odesilaci_button = document.getElementById('korekturovaci-formular-odesli');
|
||||
const zaviraci_button = document.getElementById('korekturovaci-formular-zavri');
|
||||
this.tagy = document.getElementById('korekturovaci-formular-tagy');
|
||||
this.tagy_info = document.getElementById('korekturovaci-formular-tagy-info');
|
||||
|
||||
|
||||
// ctrl-enter odešle formulář
|
||||
this.text.addEventListener("keydown", ev => {
|
||||
if (ev.code === "Enter" && ev.ctrlKey) this.odesli_formular();
|
||||
});
|
||||
|
||||
zaviraci_button.addEventListener("click", _ => { this.schovej(); });
|
||||
this.odesilaci_button.addEventListener("click", _ => { this.odesli_formular(); });
|
||||
for (const tag of this.tagy.getElementsByTagName("button")) tag.addEventListener("click", event => { this.vyber_nebo_odvyber_tag(event); });
|
||||
|
||||
this.pri_otevreni_odvyber_tagy = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Přepne tag na vybraný/nevybraný (v závislosti na tom, zda byl nevybrán/vybrán)
|
||||
* @param {MouseEvent} event vyvolaný kliknutím na daný tag (musí mít za event.target daný tag)
|
||||
*/
|
||||
vyber_nebo_odvyber_tag(event) {
|
||||
const button = event.target;
|
||||
button.dataset.vybran = String(button.dataset.vybran === "false");
|
||||
}
|
||||
|
||||
/** Nastaví všechny tagy na nevybrané. */
|
||||
odvyber_tagy() { for (const tag of this.tagy.getElementsByTagName("button")) tag.dataset.vybran = "false"; }
|
||||
|
||||
|
||||
/** Schová (zavře) korekturovací formulář */
|
||||
schovej() { this.div.style.display = 'none'; }
|
||||
|
||||
/**
|
||||
* Zobrazí/otevře korekturovací formulář (bez toho, aby v něm cokoliv měnil).
|
||||
* @param {Strana} strana (na které straně se má zobrazit)
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
*/
|
||||
_zobraz(strana, x, y) {
|
||||
this.odesilaci_button.disabled = false;
|
||||
this.div.style.display = 'block';
|
||||
this.div.style.left = x;
|
||||
this.div.style.top = y;
|
||||
|
||||
strana.htmlElement_div.appendChild(korekturovaci_formular.div);
|
||||
|
||||
this.text.focus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Předvyplní správně korekturovací formulář a zobrazí/otevře ho
|
||||
* @param {Strana} strana (na které straně se má zobrazit)
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @param {string} text (text k předvyplněný, místo null chceš psáť "")
|
||||
* @param {Number} komentar_id (!= -1 znamená úprava komentáře, -1 znamená přidávání korektury/komentáře)
|
||||
* @param {Number} korektura_id (v případě komentar_id != -1 znamená: -1 je nová korektura, ne-1 je nový komentář)
|
||||
*/
|
||||
zobraz(strana, x, y, text, korektura_id=-1, komentar_id=-1) {
|
||||
if (this.div.style.display !== 'none' && this.text.value !== "" && !confirm("Zavřít předchozí okénko přidávání korektury / editace komentáře?")) return;
|
||||
|
||||
// set hidden values
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.strana = strana;
|
||||
this.korektura_id = korektura_id;
|
||||
this.komentar_id = komentar_id;
|
||||
this.text.value = text;
|
||||
|
||||
// show form
|
||||
if (korektura_id === -1 && komentar_id === -1) {
|
||||
if (this.pri_otevreni_odvyber_tagy) this.odvyber_tagy();
|
||||
this.tagy_info.style.display = 'none';
|
||||
} else {
|
||||
const korektura = korektury[korektura_id];
|
||||
this.tagy_info.style.display = 'unset';
|
||||
for (const tag of this.tagy.getElementsByTagName("button"))
|
||||
tag.dataset.vybran = String(korektura.tagy.has(parseInt(tag.value)));
|
||||
}
|
||||
|
||||
this._zobraz(strana, x, y);
|
||||
}
|
||||
|
||||
/** Shrábne data a pošle daný požadavek, čímž kromě vyřízení dané věci aktualizuje korektury+komentáře. */
|
||||
odesli_formular() {
|
||||
this.odesilaci_button.disabled = true;
|
||||
const data = new FormData(CSRF_FORM);
|
||||
data.append('x', this.x);
|
||||
data.append('y', this.y);
|
||||
data.append('img_id', this.strana.id);
|
||||
data.append('oprava_id', this.korektura_id);
|
||||
data.append('komentar_id', this.komentar_id);
|
||||
|
||||
const tagy = [];
|
||||
for (const tag of this.tagy.getElementsByTagName("button")) {
|
||||
if (tag.dataset.vybran !== "false") tagy.push(tag.value);
|
||||
}
|
||||
data.append('tagy', String(tagy));
|
||||
|
||||
data.append('text', this.text.value);
|
||||
|
||||
aktualizuj_vse({method: 'POST', body: data}, true, () => {this.schovej(); this.odesilaci_button.disabled = false;});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Objekt starající se o editační/přidávací formulář (jeho předvyplňování, zobrazování a posílání).
|
||||
* @type {_KorekturovaciFormular}
|
||||
*/
|
||||
const korekturovaci_formular = new _KorekturovaciFormular();
|
||||
</script>
|
|
@ -1,168 +0,0 @@
|
|||
{# Template starající se o jeden každý komentář u korektury. #}
|
||||
{% load static %}
|
||||
|
||||
<div class='comment' id='prekomentar' {# id='k{{k.id}}' #}>
|
||||
<div class='hlavicka-komentare'>
|
||||
<div class='autor'>{# {{k.autor}} #}</div>
|
||||
|
||||
<div class='float-right'>
|
||||
<button type='button' style='display: none' class="smaz-komentar" title='Smaž komentář'>
|
||||
<img src='{% static "korektury/imgs/delete.png" %}' alt='del'/>
|
||||
</button>
|
||||
|
||||
<button type='button' class="uprav-komentar" title='Uprav komentář'>
|
||||
<img src='{% static "korektury/imgs/edit.png" %}' alt='edit'/>
|
||||
</button>
|
||||
|
||||
<button type='button' class='sbal-rozbal' title='Skrýt/Zobrazit'>
|
||||
<img class='sbal-rozbal-img' src='{% static "korektury/imgs/hide.png" %}' alt='⬆'/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class='komtext'>{# {{k.text|linebreaks}} #}</div>
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
/**
|
||||
* Prototyp komentáře, ze kterého se vygeneruje každý komentář (resp. jeho HTML reprezentace) v dokumentu
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
const prekomentar = document.getElementById('prekomentar');
|
||||
/**
|
||||
* Mapování ID |-> komentář
|
||||
* @type {Object.<Number, Komentar>}
|
||||
*/
|
||||
const komentare = {};
|
||||
|
||||
/** Třída reprezentující jeden komentář (a starající se o vytvoření a updatování jeho HTML reprezentace) */
|
||||
class Komentar {
|
||||
/**
|
||||
* Z dat aktualizuje (v případě, že korektura s daným ID existuje) nebo vytvoří Komentar
|
||||
* @param {Object.<string, ?>} komentar_data „Slovník“ obsahující data daného komentáře
|
||||
* @param {Korektura} korektura ke které se komentář má připojit
|
||||
*/
|
||||
static aktualizuj_nebo_vytvor(komentar_data, korektura) {
|
||||
const id = komentar_data['id'];
|
||||
if (id in komentare) komentare[id].aktualizuj(komentar_data);
|
||||
else new Komentar(komentar_data, korektura);
|
||||
}
|
||||
|
||||
/**
|
||||
* <div> se jménem autora komentáře
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
#autor;
|
||||
/**
|
||||
* <div> obsahující text komentáře
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
#text;
|
||||
/**
|
||||
* <div> reprezentující celý komentář
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
htmlElement;
|
||||
|
||||
/** @type {Number} */
|
||||
id;
|
||||
/** @type{Korektura} */
|
||||
korektura;
|
||||
/** @type{string} */
|
||||
autor;
|
||||
/** @type {boolean} */
|
||||
sbalen = false;
|
||||
|
||||
/**
|
||||
* Vytvoří HTML reprezentaci, připojí komentář pod korekturu, nastaví event-listenery, uloží si data
|
||||
* @param {Object.<string, ?>} komentar_data „Slovník“ obsahující data daného komentáře
|
||||
* @param {Korektura} korektura korektura ke které se komentář má připojit
|
||||
*/
|
||||
constructor(komentar_data, korektura) {
|
||||
this.htmlElement = prekomentar.cloneNode(true);
|
||||
this.#autor = this.htmlElement.getElementsByClassName('autor')[0];
|
||||
this.#text = this.htmlElement.getElementsByClassName('komtext')[0];
|
||||
|
||||
this.id = komentar_data['id'];
|
||||
this.htmlElement.id = 'k' + this.id;
|
||||
|
||||
this.korektura = korektura;
|
||||
this.korektura.pridej_htmlElement_komentare(this.htmlElement);
|
||||
|
||||
this.aktualizuj(komentar_data);
|
||||
|
||||
this.htmlElement.getElementsByClassName('sbal-rozbal')[0].addEventListener('click', _ => this.#sbal_nebo_rozbal());
|
||||
this.htmlElement.getElementsByClassName('uprav-komentar')[0].addEventListener('click', _ => this.#uprav_komentar());
|
||||
this.htmlElement.getElementsByClassName('smaz-komentar')[0].addEventListener('click', _ => this.#smaz_komentar());
|
||||
|
||||
komentare[this.id] = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualizuje/nastaví JS data i HTML reprezentaci komentáře
|
||||
* @param {Object.<string, ?>} komentar_data „Slovník“ obsahující data daného komentáře
|
||||
*/
|
||||
aktualizuj(komentar_data) {
|
||||
this.set_autor(komentar_data['autor']);
|
||||
this.set_text(komentar_data['text']);
|
||||
};
|
||||
|
||||
/**
|
||||
* Aktualizuje/nastaví JS data i HTML reprezentaci autora komentáře
|
||||
* @param {String} autor
|
||||
*/
|
||||
set_autor(autor) {
|
||||
this.#autor.textContent=autor;
|
||||
this.autor = autor;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {String} text
|
||||
*/
|
||||
set_text(text) {
|
||||
this.#text.innerHTML=text;
|
||||
};
|
||||
|
||||
/** Sbalí/rozbalí (podle toho, zda byl rozbalený/sbalený) komentář, ale nezmění pozice korektur (je třeba později zavolat umisti_korektury()) */
|
||||
sbal_nebo_rozbal() {
|
||||
this.sbalen = !this.sbalen;
|
||||
this.htmlElement.dataset.komentar_sbalen = String(this.sbalen);
|
||||
}
|
||||
/** Doplněk sbal_nebo_rozbal, který i přeskládá korektury. */
|
||||
#sbal_nebo_rozbal(){
|
||||
this.sbal_nebo_rozbal();
|
||||
umisti_korektury();
|
||||
}
|
||||
|
||||
/** Ukáže formulář na editaci komentáře (když je zmáčknuto „uprav-komentar“) */
|
||||
#uprav_komentar() {
|
||||
return korekturovaci_formular.zobraz(this.korektura.strana, this.korektura.x, this.korektura.y, this.#text.textContent, this.korektura.id, this.id);
|
||||
}
|
||||
|
||||
/** Smaže komentář (když je zmáčknuto „smaz-komentar“) */
|
||||
#smaz_komentar() {
|
||||
if (confirm('Opravdu smazat komentář?')) {
|
||||
const data = new FormData(CSRF_FORM);
|
||||
data.append('komentar_id', this.id);
|
||||
fetch('{% url "korektury_api_komentar_smaz" %}', {method: 'POST', body: data})
|
||||
.then(response => {
|
||||
if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);}
|
||||
this.smaz_pouze_na_strance();
|
||||
umisti_korektury();
|
||||
})
|
||||
.catch(error => {alert('Něco se nepovedlo:' + error);});
|
||||
}
|
||||
}
|
||||
|
||||
/** Smaže div komentáře (ne databázový záznam!), používá se, když je smazán komentář nebo jeho nadřazená korektura */
|
||||
smaz_pouze_na_strance() {
|
||||
delete komentare[this.id];
|
||||
this.htmlElement.remove();
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -1,271 +0,0 @@
|
|||
{% load static %}
|
||||
|
||||
<div id='prepointer' {# id='kor{{k.id}}-pointer' #}
|
||||
class='pointer'
|
||||
data-hover='false'
|
||||
{# data-stav_korektury='{{k.status}}' #}
|
||||
></div>
|
||||
|
||||
<div id='prekorektura' {# name='kor{{k.id}}' id='kor{{k.id}}' #}
|
||||
class='korektura'
|
||||
{# data-stav_korektury='{{k.status}}' #}
|
||||
data-korektura_sbalena='false'
|
||||
>
|
||||
<div class="korektura-tagy">
|
||||
{# {% for tag in k.tagy %} <span style="background:{{ tag.barva }}>{{ tag.text }}<span/> #}
|
||||
</div>
|
||||
|
||||
<div class='korektura-telo'>
|
||||
{# {% for k in k.komentare %} {% include "korektury/korekturovatko/komentar.html" %} {% endfor %} #}
|
||||
</div>
|
||||
|
||||
<div class='hlavicka-komentare'>
|
||||
<span class='float-right'>
|
||||
<span class='korektura-tlacitka'>
|
||||
<button type='button' style='display: none' class="smaz-korekturu" title='Smaž korekturu'>
|
||||
<img src='{% static "korektury/imgs/delete.png" %}' alt='🗑️'/>
|
||||
</button>
|
||||
<button type='button' class='action' value='k_oprave' title='Označ jako neopravené'>
|
||||
<img src='{% static "korektury/imgs/undo.png" %}' alt='↪'/>
|
||||
</button>
|
||||
<button type='button' class='action' value='opraveno' title='Označ jako opravené'>
|
||||
<img src='{% static "korektury/imgs/check.png" %}' alt='✔️'/>
|
||||
</button>
|
||||
<button type='button' class='action' value='neni_chyba' title='Označ, že se nebude měnit'>
|
||||
<img src='{% static "korektury/imgs/cross.png" %}' alt='❌'/>
|
||||
</button>
|
||||
<button type='button' class='action' value='k_zaneseni' title='Označ jako připraveno k zanesení'>
|
||||
<img src='{% static "korektury/imgs/tex.png" %}' alt='TeX'/>
|
||||
</button>
|
||||
|
||||
<a href='{% url "admin:korektury_oprava_change" -1 %}' class='edit' title='Uprav korekturu jako takovou.' style="text-decoration: none;"> {# FIXME Udělat z toho tlačítko? #}
|
||||
<img src='{% static "korektury/imgs/edit.png" %}' alt='✏️' style="opacity: 0.5;"/> {# FIXME Odlišit jinak než pomocí opacity? #}
|
||||
</a>
|
||||
<button type='button' class='komentovat_disabled' title='Korekturu nelze komentovat, protože už je uzavřená' disabled=''>
|
||||
<img src='{% static "korektury/imgs/comment-gr.png" %}' alt='💭'/>
|
||||
</button>
|
||||
<button type='button' class='komentovat' title='Komentovat'>
|
||||
<img src='{% static "korektury/imgs/comment.png" %}' alt='💭'/>
|
||||
</button>
|
||||
</span>
|
||||
|
||||
<button type='button' class='sbal-rozbal' title='Skrýt/Zobrazit'>
|
||||
<img class='sbal-rozbal-img' src='{% static "korektury/imgs/hide.png" %}' alt='⬆'/>
|
||||
</button>
|
||||
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* Prototyp korektury, ze kterého se vygeneruje každý komentář (resp. jeho HTML reprezentace) v dokumentu
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
const prekorektura = document.getElementById('prekorektura');
|
||||
/**
|
||||
* Prototyp pointeru (té lomené čáry od korektury)
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
const prepointer = document.getElementById('prepointer');
|
||||
/**
|
||||
* Mapování ID |-> korektura
|
||||
* @type {Object.<Number, Korektura>}
|
||||
*/
|
||||
const korektury = {};
|
||||
|
||||
/** Třída reprezentující jednu korekturu (a starající se o vytvoření a updatování její HTML reprezentace) */
|
||||
class Korektura {
|
||||
/**
|
||||
* Z dat aktualizuje (v případě, že korektura s daným ID existuje) nebo vytvoří Korekturu
|
||||
* @param {Object.<string, ?>} korektura_data „Slovník“ obsahující data dané korektury
|
||||
* @returns {Korektura} vytvořená/aktualizovaná Korektura (pro použití při vytváření/aktualizaci komentářů)
|
||||
*/
|
||||
static aktualizuj_nebo_vytvor(korektura_data) {
|
||||
const id = korektura_data['id'];
|
||||
if (id in korektury) return korektury[id].aktualizuj(korektura_data);
|
||||
else return new Korektura(korektura_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* <div> obsahující <div>y komentářů
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
#komentare;
|
||||
/**
|
||||
* <div> obsahující tagy
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
#tagy;
|
||||
/**
|
||||
* <div> reprezentující celý korekturu
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
htmlElement;
|
||||
/**
|
||||
* <div> reprezentující pointer (tu lomenou čáru od korektury)
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
pointer;
|
||||
|
||||
/** @type {Number} */
|
||||
id;
|
||||
/** @type {Number} */
|
||||
x;
|
||||
/** @type {Number} */
|
||||
y;
|
||||
/** @type {Strana} */
|
||||
strana;
|
||||
/** @type {string} */
|
||||
stav;
|
||||
/** @type {boolean} */
|
||||
sbalena = false;
|
||||
/** @type Set<Number> */
|
||||
tagy;
|
||||
|
||||
/**
|
||||
* Vytvoří HTML reprezentaci, připojí korekturu pod stranu (ale neumístí ji), nastaví event-listenery, uloží si data
|
||||
* @param {Object.<string, ?>} korektura_data „Slovník“ obsahující data dané korektury
|
||||
*/
|
||||
constructor(korektura_data) {
|
||||
this.htmlElement = prekorektura.cloneNode(true);
|
||||
this.pointer = prepointer.cloneNode(true);
|
||||
this.#komentare = this.htmlElement.getElementsByClassName('korektura-telo')[0];
|
||||
this.#tagy = this.htmlElement.getElementsByClassName('korektura-tagy')[0];
|
||||
|
||||
this.id = korektura_data['id'];
|
||||
this.htmlElement.id = 'kor' + this.id;
|
||||
this.pointer.id = 'kor' + this.id + '-pointer';
|
||||
|
||||
this.x = korektura_data['x'];
|
||||
this.y = korektura_data['y'];
|
||||
|
||||
this.aktualizuj(korektura_data);
|
||||
|
||||
this.htmlElement.getElementsByClassName('sbal-rozbal')[0].addEventListener('click', _ => this.#sbal_nebo_rozbal());
|
||||
for (const button of this.htmlElement.getElementsByClassName('action'))
|
||||
button.addEventListener('click', async event => this.#zmen_stav_korektury(event));
|
||||
this.htmlElement.getElementsByClassName('komentovat')[0].addEventListener('click', _ => this.#komentuj())
|
||||
this.htmlElement.getElementsByClassName('smaz-korekturu')[0].addEventListener('click', _ => this.#smaz_korekturu());
|
||||
const odkaz_editace = this.htmlElement.getElementsByClassName('edit')[0];
|
||||
odkaz_editace.href = odkaz_editace.href.replace("-1", this.id);
|
||||
odkaz_editace.onclick = ev => { if (!confirm("Editace korektury je velmi pokročilá featura umožňující přesouvat korekturu nebo přidávat informované orgy, opravdu chceš pokračovat do adminu?")) ev.preventDefault(); };
|
||||
|
||||
this.htmlElement.addEventListener('mouseover', _ => this.pointer.dataset.hover = 'true');
|
||||
this.htmlElement.addEventListener('mouseout', _ => this.pointer.dataset.hover = 'false');
|
||||
|
||||
const cislo_strany = korektura_data['strana'];
|
||||
if (cislo_strany in strany) {
|
||||
this.strana = strany[cislo_strany];
|
||||
this.strana.korektury.push(this);
|
||||
} else alert("Někdo korekturoval stranu, která neexistuje. Dejte vědět webařům :)");
|
||||
korektury[this.id] = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualizuje/nastaví JS data i HTML reprezentaci korektury
|
||||
* @param {Object.<string, ?>} korektura_data „Slovník“ obsahující data dané korektury
|
||||
* @returns {Korektura} pro jednodušší implementaci aktualizuj_nebo_vytvor vracíme this
|
||||
*/
|
||||
aktualizuj(korektura_data) {
|
||||
this.set_stav(korektura_data['status']);
|
||||
this.set_tagy(korektura_data["tagy"]);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Aktualizuje/nastaví JS data i HTML reprezentaci tagů korektury
|
||||
* @param {Object.<string, ?>[]} tagy
|
||||
*/
|
||||
set_tagy(tagy) {
|
||||
this.#tagy.innerHTML = "";
|
||||
this.tagy = new Set();
|
||||
for (const tag of tagy) {
|
||||
this.tagy.add(tag["id"]);
|
||||
const span = document.createElement("span");
|
||||
span.innerHTML = tag["nazev"];
|
||||
span.classList.add("korektury-tag");
|
||||
span.style.backgroundColor = tag["barva"];
|
||||
this.#tagy.appendChild(span);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualizuje/nastaví JS data i HTML reprezentaci stavu korektury
|
||||
* @param {String} stav
|
||||
*/
|
||||
set_stav(stav) {
|
||||
this.stav = stav;
|
||||
this.htmlElement.dataset.stav_korektury=stav;
|
||||
this.pointer.dataset.stav_korektury=stav;
|
||||
};
|
||||
|
||||
/**
|
||||
* Přidá HTML reprezentaci komentáře pod tuto korekturu
|
||||
* @param {HTMLElement} htmlElement přidávaný komentář (jako HTML prvek)
|
||||
*/
|
||||
pridej_htmlElement_komentare(htmlElement) { this.#komentare.appendChild(htmlElement); }
|
||||
|
||||
|
||||
|
||||
/** Sbalí/rozbalí (podle toho, zda byla rozbalená/sbalená) korekturu, ale nezmění pozice korektur (je třeba později zavolat umisti_korektury()) */
|
||||
sbal_nebo_rozbal() {
|
||||
this.sbalena = !this.sbalena;
|
||||
this.htmlElement.dataset.korektura_sbalena = String(this.sbalena);
|
||||
}
|
||||
/** Doplněk sbal_nebo_rozbal, který i přeskládá korektury. */
|
||||
#sbal_nebo_rozbal(){
|
||||
this.sbal_nebo_rozbal();
|
||||
umisti_korektury();
|
||||
}
|
||||
|
||||
/** Ukaž komentovací formulář (když je zmáčknuto komentovat) */
|
||||
#komentuj() { korekturovaci_formular.zobraz(this.strana, this.x, this.y, "", this.id); }
|
||||
|
||||
/**
|
||||
* Změní stav (když je zmáčknuto tlačítko daného stavu)
|
||||
* @param {MouseEvent} event který vyvolal danou změnu (event.target.value musí být chtěný stav)
|
||||
*/
|
||||
#zmen_stav_korektury(event) {
|
||||
const data = new FormData(CSRF_FORM);
|
||||
data.append('id', this.id);
|
||||
data.append('action', event.target.value);
|
||||
|
||||
fetch('{% url "korektury_api_oprava_stav" %}', {method: 'POST', body: data})
|
||||
.then(response => {
|
||||
if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);}
|
||||
else response.json().then(data => {
|
||||
this.set_stav(data['status']);
|
||||
aktualizuj_pocty_stavu();
|
||||
});
|
||||
})
|
||||
.catch(error => {alert('Něco se nepovedlo:' + error);});
|
||||
}
|
||||
|
||||
/** Smaže korekturu (když je zmáčknuto „smaz-korekturu“) */
|
||||
#smaz_korekturu() {
|
||||
if (confirm('Opravdu smazat korekturu?')) {
|
||||
const data = new FormData(CSRF_FORM);
|
||||
data.append('oprava_id', this.id);
|
||||
fetch('{% url "korektury_api_oprava_smaz" %}', {method: 'POST', body: data})
|
||||
.then(response => {
|
||||
if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);}
|
||||
this.#smaz_pouze_na_strance()
|
||||
aktualizuj_pocty_stavu();
|
||||
aktualizuj_pocty_zasluh();
|
||||
umisti_korektury();
|
||||
})
|
||||
.catch(error => {alert('Něco se nepovedlo:' + error);});
|
||||
}
|
||||
}
|
||||
|
||||
/** Smaže div korektury (včetně všech komentářů; ne databázový záznam!) */
|
||||
#smaz_pouze_na_strance() {
|
||||
this.strana.korektury.splice(this.strana.korektury.indexOf(this), 1);
|
||||
delete korektury[this.id];
|
||||
for (const komentar of Object.values(komentare)) if (komentar.korektura === this) komentar.smaz_pouze_na_strance();
|
||||
this.htmlElement.remove();
|
||||
this.pointer.remove();
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -1,86 +0,0 @@
|
|||
{# Template starající se o tlačítkovou lištu nahoře, tj. hlavně o hromadné schovávání korektur. #}
|
||||
Zobrazit:
|
||||
<input type="checkbox" id="k_oprave_checkbox" checked>
|
||||
<label for="k_oprave_checkbox">K opravě (<span id="k_oprave_pocet">↺</span>)</label>
|
||||
<input type="checkbox" id="opraveno_checkbox" checked>
|
||||
<label for="opraveno_checkbox">Opraveno (<span id="opraveno_pocet">↺</span>)</label>
|
||||
<input type="checkbox" id="neni_chyba_checkbox" checked>
|
||||
<label for="neni_chyba_checkbox">Není chyba (<span id="neni_chyba_pocet">↺</span>)</label>
|
||||
<input type="checkbox" id="k_zaneseni_checkbox" checked>
|
||||
<label for="k_zaneseni_checkbox">K zanesení (<span id="k_zaneseni_pocet">↺</span>)</label>
|
||||
|
||||
<button type="button" id="sbal-korektury">Sbal korektury</button>
|
||||
<button type="button" id="rozbal-korektury">Rozbal korektury</button>
|
||||
|
||||
<hr/>
|
||||
|
||||
<script>
|
||||
document.getElementById('k_oprave_checkbox').addEventListener('change', () => skryj_nebo_zobraz_korektury('k_oprave'));
|
||||
document.getElementById('opraveno_checkbox').addEventListener('change', () => skryj_nebo_zobraz_korektury('opraveno'));
|
||||
document.getElementById('neni_chyba_checkbox').addEventListener('change', () => skryj_nebo_zobraz_korektury('neni_chyba'));
|
||||
document.getElementById('k_zaneseni_checkbox').addEventListener('change', () => skryj_nebo_zobraz_korektury('k_zaneseni'));
|
||||
|
||||
document.getElementById("sbal-korektury").addEventListener("click", () => {
|
||||
for (const korektura of Object.values(korektury))
|
||||
if (!korektura.sbalena) korektura.sbal_nebo_rozbal();
|
||||
umisti_korektury();
|
||||
})
|
||||
document.getElementById("rozbal-korektury").addEventListener("click", () => {
|
||||
for (const korektura of Object.values(korektury))
|
||||
if (korektura.sbalena) korektura.sbal_nebo_rozbal();
|
||||
umisti_korektury();
|
||||
})
|
||||
|
||||
/**
|
||||
* Změní CSS tak, aby se korektury příslušného stavu nezobrazovali/zobrazovali (v závislosti na tom, jestli byly zobrazené/nezobrazené)
|
||||
* @param {string} aclass stav korektur, které mají být skryty/zobrazeny
|
||||
*/
|
||||
function skryj_nebo_zobraz_korektury(aclass)
|
||||
{
|
||||
const stylesheets = document.styleSheets;
|
||||
let ssheet = null;
|
||||
for (let i=0; i<stylesheets.length; i++){
|
||||
if (stylesheets[i].title === "opraf-css"){
|
||||
ssheet = stylesheets[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! ssheet){
|
||||
return;
|
||||
}
|
||||
for (let i=0; i<ssheet.cssRules.length; i++){
|
||||
const rule = ssheet.cssRules[i];
|
||||
if (rule.selectorText === '[data-stav_korektury="'+aclass+'"]'){
|
||||
if (rule.style.display === ""){
|
||||
rule.style.display = "none";
|
||||
} else {
|
||||
rule.style.display = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
umisti_korektury();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapování stav korektur |-> span, kde se píše, kolik je korektur toho stavu.
|
||||
* Používané v následující funcki
|
||||
* @type {Object.<string, HTMLElement>}
|
||||
*/
|
||||
const spany_s_pocty_stavu_korektur = {
|
||||
'k_oprave': document.getElementById('k_oprave_pocet'),
|
||||
'opraveno': document.getElementById('opraveno_pocet'),
|
||||
'neni_chyba': document.getElementById('neni_chyba_pocet'),
|
||||
'k_zaneseni': document.getElementById('k_zaneseni_pocet'),
|
||||
}
|
||||
|
||||
/** Aktualizuje počty korektur jednotlivých stavů */
|
||||
function aktualizuj_pocty_stavu() {
|
||||
const pocty_stavu_korektur = {};
|
||||
for (const stav_korektury of Object.keys(spany_s_pocty_stavu_korektur)) pocty_stavu_korektur[stav_korektury] = 0;
|
||||
for (const korektura of Object.values(korektury)) {
|
||||
if (!(korektura.stav in pocty_stavu_korektur)) pocty_stavu_korektur[korektura.stav] = 0;
|
||||
pocty_stavu_korektur[korektura.stav] += 1;
|
||||
}
|
||||
for (let [stav, pocet] of Object.entries(pocty_stavu_korektur)) spany_s_pocty_stavu_korektur[stav].innerText = pocet;
|
||||
}
|
||||
</script>
|
|
@ -1,148 +0,0 @@
|
|||
{# Template starající se o zobrazení PDF stran a o umístění korektur na ně. (O samotné korektury se stará `./korektura.html`.) #}
|
||||
{% for i in indexy_stran %}
|
||||
<div class='imgdiv'>
|
||||
<img
|
||||
id='img-{{i}}'
|
||||
width='1021' height='1448'
|
||||
src='/media/korektury/img/{{korekturovanepdf.get_prefix}}-{{i}}.png'
|
||||
alt='Strana {{ i|add:1 }}'
|
||||
class="strana"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
{% endfor %}
|
||||
|
||||
<script>
|
||||
// Pro umisťování korektur
|
||||
const HORIZONTALNI_MEZERA = 10;
|
||||
const VERTIKALNI_MEZERA = 5;
|
||||
const MINIMALNI_VYSKA_POINTERU = 30;
|
||||
|
||||
/**
|
||||
* Mapování index_strany |-> strana
|
||||
* @type {Object.<int, Strana>}
|
||||
*/
|
||||
const strany = {};
|
||||
|
||||
/** Třída spravující jednu stranu PDF a umisťující na ni příslušné korektury. */
|
||||
class Strana {
|
||||
/**
|
||||
* <img> příslušící straně
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
htmlElement_img;
|
||||
/**
|
||||
* <div> obalující stranu, do něj se umisťují korektury
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
htmlElement_div;
|
||||
|
||||
/**
|
||||
* Index strany (používá se při ukládání korektury (a načítání <img>))
|
||||
* @type {Number}
|
||||
*/
|
||||
id;
|
||||
/**
|
||||
* Korektury na příslušné straně (BÚNO setříděné podle vertikálního umístění)
|
||||
* @type {Korektura[]}
|
||||
*/
|
||||
korektury;
|
||||
|
||||
|
||||
/**
|
||||
* Uloží si data (včetně pointrů na správné části HTML DOMu) a nastaví event-listener
|
||||
* @param {HTMLElement} htmlElement_img
|
||||
*/
|
||||
constructor(htmlElement_img) {
|
||||
this.htmlElement_img = htmlElement_img;
|
||||
this.htmlElement_div = this.htmlElement_img.parentNode;
|
||||
|
||||
this.id = parseInt(this.htmlElement_img.id.substring(4));
|
||||
this.korektury = []
|
||||
|
||||
this.htmlElement_img.addEventListener('click', event => this.#korekturuj(event));
|
||||
|
||||
strany[this.id] = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Otevře korekturovací formulář pro přidání korektury v daném místě
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
#korekturuj(event) {
|
||||
switch (document.body.dataset.stav_pdf) {
|
||||
case 'zanaseni':
|
||||
if (!confirm('Právě jsou zanášeny korektury, opravdu chcete přidat novou?')) return;
|
||||
break;
|
||||
case 'zastarale':
|
||||
if (!confirm('Toto PDF je již zastaralé, opravdu chcete vytvořit korekturu?')) return;
|
||||
break;
|
||||
}
|
||||
|
||||
let dx, dy;
|
||||
if (event.pageX != null) {
|
||||
dx = event.pageX - this.htmlElement_div.offsetLeft;
|
||||
dy = event.pageY - this.htmlElement_div.offsetTop;
|
||||
} else { //IE a další
|
||||
dx = event.offsetX;
|
||||
dy = event.offsetY;
|
||||
}
|
||||
korekturovaci_formular.zobraz(this, dx, dy, '');
|
||||
console.log("Pro přesun korektur: strana = " + this.id + ", x = " + dx + ", y = " + dy);
|
||||
}
|
||||
|
||||
/** Setřídí seznam korektur příslušný dané straně */
|
||||
setrid_korektury() { this.korektury.sort((a, b) => a.y - b.y); }
|
||||
|
||||
/** Zobrazí korektury a jejich pointry (a umístí je správně pod sebe) na dané straně */
|
||||
umisti_korektury() {
|
||||
this.setrid_korektury()
|
||||
|
||||
const w = this.htmlElement_img.clientWidth;
|
||||
|
||||
let spodek_posledni_korektury = 0;
|
||||
for (const korektura of this.korektury) {
|
||||
const x = korektura.x;
|
||||
const y = korektura.y;
|
||||
const pointer = korektura.pointer;
|
||||
|
||||
this.htmlElement_div.appendChild(pointer);
|
||||
this.htmlElement_div.appendChild(korektura.htmlElement);
|
||||
|
||||
const delta_y = (y > spodek_posledni_korektury) ? 0: spodek_posledni_korektury - y + VERTIKALNI_MEZERA;
|
||||
|
||||
pointer.style.left = x;
|
||||
pointer.style.top = y;
|
||||
pointer.style.width = w - x + HORIZONTALNI_MEZERA;
|
||||
pointer.style.height = MINIMALNI_VYSKA_POINTERU + delta_y;
|
||||
|
||||
korektura.htmlElement.style.left = w + HORIZONTALNI_MEZERA;
|
||||
korektura.htmlElement.style.top = y + delta_y;
|
||||
|
||||
spodek_posledni_korektury = Math.max(
|
||||
spodek_posledni_korektury,
|
||||
korektura.htmlElement.offsetTop + korektura.htmlElement.offsetHeight + VERTIKALNI_MEZERA
|
||||
); // FIXME nemám páru, proč +VERTIKALNI_MEZERA funguje, ale opravuje to bug, že nově vytvořené korektury za sebou neměly mezeru
|
||||
}
|
||||
|
||||
this.htmlElement_div.style.height = "unset";
|
||||
if (this.htmlElement_div.offsetHeight < spodek_posledni_korektury)
|
||||
this.htmlElement_div.style.height = spodek_posledni_korektury;
|
||||
}
|
||||
}
|
||||
|
||||
// Vytvoření objektu Strana pro každou stranu
|
||||
for (const strana_img of document.getElementsByClassName('strana'))
|
||||
new Strana(strana_img);
|
||||
|
||||
/**
|
||||
* Seznam stran setřízený podle toho, jak jdou po sobě (aby se dali korektury prohledávat od první na HTML stránce po poslední)
|
||||
* @type {Strana[]}
|
||||
*/
|
||||
const setrizene_strany = Object.values(strany);
|
||||
setrizene_strany.sort((a, b) => a.htmlElement_img.offsetTop - b.htmlElement_img.offsetTop);
|
||||
|
||||
/** Zobrazí korektury a jejich pointry (a umístí je správně pod sebe) na všech stranách */
|
||||
function umisti_korektury() { for (const strana of Object.values(strany)) strana.umisti_korektury(); }
|
||||
</script>
|
|
@ -14,7 +14,7 @@ def send_email_notification_komentar(oprava: Oprava, autor: Organizator, request
|
|||
# parametry e-mailu
|
||||
#odkaz = "https://mam.mff.cuni.cz/korektury/{}/".format(oprava.pdf.pk)
|
||||
odkaz = request.build_absolute_uri(reverse('korektury', kwargs={'pdf': oprava.pdf.pk}))
|
||||
odkaz = f"{odkaz}#kor{oprava.id}-pointer"
|
||||
odkaz = f"{odkaz}#op{oprava.id}-pointer"
|
||||
from_email = 'korekturovatko@mam.mff.cuni.cz'
|
||||
subject = 'Nová korektura od {} v {}'.format(autor, oprava.pdf.nazev)
|
||||
texty = []
|
||||
|
|
|
@ -49,11 +49,11 @@ class KorekturySeskupeneListView(KorekturyAktualniListView):
|
|||
class KorekturyView(generic.DetailView):
|
||||
model = KorekturovanePDF
|
||||
pk_url_kwarg = "pdf"
|
||||
template_name = 'korektury/korekturovatko/html_obal.html'
|
||||
template_name = 'korektury/korekturovatko/htmlstrana.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['indexy_stran'] = range(self.object.stran)
|
||||
context['img_indexes'] = range(self.object.stran)
|
||||
context['tagy'] = KorekturaTag.objects.all()
|
||||
return context
|
||||
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
.odevzdavatko-role {
|
||||
font-size: 0.8em;
|
||||
|
||||
.vyrazne {
|
||||
color: var(--hlavni-oranzova);
|
||||
}
|
||||
.nevyrazne {
|
||||
color: #aaa;
|
||||
}
|
||||
}
|
||||
|
||||
.hodnoceni.zvyraznene {
|
||||
background-color: var(--svetla-oranzova);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block custom_css %}
|
||||
<link href="{% static 'css/odevzdavatko.css' %}?version=1" rel="stylesheet">
|
||||
{% endblock %}
|
|
@ -1,13 +1,11 @@
|
|||
{% extends "odevzdavatko/base.html" %}
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% load deadliny %}
|
||||
{% load mail %}
|
||||
{% load jmena %}
|
||||
{% load orgove %}
|
||||
|
||||
{# Přišlo mi to hezčí, než psát všude if. #}
|
||||
{% block custom_css %}
|
||||
{{ block.super }}
|
||||
{% if object.resitele.count == 1 %}
|
||||
<style>.teamovaCast {display: none}</style>
|
||||
{% endif %}
|
||||
|
@ -113,7 +111,7 @@
|
|||
<tr><th>Problém</th><th>{# 📖 #}🧍</th><th>{# 🔵 #}🧍∑</th><th class="teamovaCast">{# 💪 #}🧑🤝🧑</th><th class="teamovaCast">{# ❤ #}🧑🤝🧑∑</th><th>Deadline pro body</th><th>Zpětná vazba pro řešitele</th></tr>
|
||||
{% for subform in form %}
|
||||
<tbody>
|
||||
<tr class="hodnoceni{% if subform.problem.initial|ma_opravovatele:user %} zvyraznene{% endif %}">
|
||||
<tr class="hodnoceni">
|
||||
<td>{{ subform.problem }}</td>
|
||||
<td class="bodovani">{{ subform.body }}</td>
|
||||
<td class="bodovani">{{ subform.body_celkem }}</td>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{% extends "odevzdavatko/base.html" %}
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% load barvy_reseni %}
|
||||
{% load orgove %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
|
@ -28,15 +27,7 @@ Do data (včetně): {{ filtr.reseni_do }}
|
|||
{% for p in problemy %}
|
||||
<th>
|
||||
{# TODO: Přehled řešení k problému, odkázaný odsud? #}
|
||||
<span title="Autor: {{ p.autor }}, Garant: {{ p.garant }}, Opravovatelé: {{ p.opravovatele.all | join:", " }}">{{ p }}
|
||||
<span class="odevzdavatko-role">
|
||||
{% spaceless %}
|
||||
<span class="{{ p|ma_autora:user|yesno:"vyrazne,nevyrazne" }}">A</span>
|
||||
<span class="{{ p|ma_garanta:user|yesno:"vyrazne,nevyrazne" }}">G</span>
|
||||
<span class="{{ p|ma_opravovatele:user|yesno:"vyrazne,nevyrazne" }}">O</span>
|
||||
{% endspaceless %}
|
||||
</span>
|
||||
</span>
|
||||
{{ p }}
|
||||
</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
from django import template
|
||||
register = template.Library()
|
||||
|
||||
from personalni.utils import organizator_cehokoliv
|
||||
|
||||
# Jen typová anotace
|
||||
from tvorba.models import Problem
|
||||
from personalni.models import Osoba, Organizator, Resitel, Prijemce
|
||||
from django.contrib.auth.models import AnonymousUser, User
|
||||
|
||||
@register.filter
|
||||
def ma_autora(p: Problem, o: Osoba | Organizator | User | AnonymousUser | Resitel | Prijemce) -> bool | None:
|
||||
o = organizator_cehokoliv(o)
|
||||
if o is None: return None
|
||||
return p.autor == o
|
||||
|
||||
@register.filter
|
||||
def ma_garanta(p: Problem, o: Osoba | Organizator | User | AnonymousUser | Resitel | Prijemce) -> bool | None:
|
||||
o = organizator_cehokoliv(o)
|
||||
if o is None: return None
|
||||
return p.garant == o
|
||||
|
||||
@register.filter
|
||||
def ma_opravovatele(p: Problem, o: Osoba | Organizator | User | AnonymousUser | Resitel | Prijemce) -> bool | None:
|
||||
o = organizator_cehokoliv(o)
|
||||
if o is None: return None
|
||||
return p.opravovatele.contains(o)
|
|
@ -3,7 +3,7 @@ import re
|
|||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.decorators import permission_required, user_passes_test
|
||||
from django.contrib.auth.models import AnonymousUser, User
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.db import transaction
|
||||
|
||||
import soustredeni.models
|
||||
|
@ -182,46 +182,3 @@ def merge_osoby(cilova, zdrojova):
|
|||
cilova.save()
|
||||
|
||||
input("Potvrdit transakci osob (^C pro zrušení) ")
|
||||
|
||||
def osoba_uzivatele(u: User | AnonymousUser) -> Osoba | None:
|
||||
if u.is_anonymous: return None
|
||||
try:
|
||||
return u.osoba
|
||||
except User.osoba.RelatedObjectDoesNotExist:
|
||||
return None
|
||||
|
||||
def resitel_osoby(o: Osoba) -> Resitel | None:
|
||||
try:
|
||||
return o.resitel
|
||||
except Osoba.resitel.RelatedObjectDoesNotExist:
|
||||
return None
|
||||
|
||||
def resitel_uzivatele(u: User | AnonymousUser) -> Resitel | None:
|
||||
o = osoba_uzivatele(u)
|
||||
if o is None: return None
|
||||
return resitel_osoby(o)
|
||||
|
||||
def resitel_cehokoliv(r: User | AnonymousUser | Osoba | Organizator | Resitel | Prijemce) -> Organizator | None:
|
||||
if isinstance(r, User): r = resitel_uzivatele(r)
|
||||
if isinstance(r, Osoba): r = resitel_osoby(r)
|
||||
if isinstance(r, Resitel) or isinstance(r, Prijemce): r = resitel_osoby(r.osoba)
|
||||
assert isinstance(r, Resitel) or r is None
|
||||
return r
|
||||
|
||||
def organizator_osoby(o: Osoba) -> Organizator | None:
|
||||
try:
|
||||
return o.org
|
||||
except Osoba.org.RelatedObjectDoesNotExist:
|
||||
return None
|
||||
|
||||
def organizator_uzivatele(u: User | AnonymousUser) -> Organizator | None:
|
||||
o = osoba_uzivatele(u)
|
||||
if o is None: return None
|
||||
return organizator_osoby(o)
|
||||
|
||||
def organizator_cehokoliv(o: User | AnonymousUser | Osoba | Organizator | Resitel | Prijemce) -> Organizator | None:
|
||||
if isinstance(o, User): o = organizator_uzivatele(o)
|
||||
if isinstance(o, Osoba): o = organizator_osoby(o)
|
||||
if isinstance(o, Resitel) or isinstance(o, Prijemce): o = organizator_osoby(o.osoba)
|
||||
assert isinstance(o, Organizator) or o is None
|
||||
return o
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import OdpovedUcastnika, SpravnaOdpoved, NapovezenoUcastnikovi, Napoveda, SeznamSifer
|
||||
from .models import OdpovedUcastnika, SpravnaOdpoved, NapovezenoUcastnikovi, Napoveda
|
||||
|
||||
admin.site.register(OdpovedUcastnika)
|
||||
admin.site.register(SpravnaOdpoved)
|
||||
admin.site.register(Napoveda)
|
||||
admin.site.register(NapovezenoUcastnikovi)
|
||||
admin.site.register(SeznamSifer)
|
||||
|
|
|
@ -13,8 +13,8 @@ class SifrovackaForm(ModelForm):
|
|||
|
||||
def clean_sifra(self):
|
||||
sifra = self.cleaned_data.get('sifra')
|
||||
if SpravnaOdpoved.objects.filter(sifra__iexact=sifra).count() == 0:
|
||||
raise ValidationError("Tuhle šifru v databázi nemáme. Zkontrolujte si, že jste zadali název správně.")
|
||||
if SpravnaOdpoved.objects.filter(sifra=sifra).count() == 0:
|
||||
raise ValidationError("Tohle číslo šifry v databázi nemáme. Zkontrolujte si ho prosím.")
|
||||
return sifra
|
||||
|
||||
|
||||
|
@ -25,6 +25,6 @@ class NapovedaForm(ModelForm):
|
|||
|
||||
def clean_sifra(self):
|
||||
sifra = self.cleaned_data.get('sifra')
|
||||
if Napoveda.objects.filter(sifra__iexact=sifra).count() == 0:
|
||||
raise ValidationError("K této šifře nemáme nápovědu. Zkontrolujte si, že jste zadali název správně.")
|
||||
if Napoveda.objects.filter(sifra=sifra).count() == 0:
|
||||
raise ValidationError("K tomuto číslu šifry nemáme nápovědu. Zkontrolujte si ho prosím.")
|
||||
return sifra
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
# Generated by Django 4.2.18 on 2025-03-19 20:12
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sifrovacka', '0006_personalni_post_migrate'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='napoveda',
|
||||
name='sifra',
|
||||
field=models.CharField(max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='napovezenoucastnikovi',
|
||||
name='sifra',
|
||||
field=models.CharField(max_length=255, verbose_name='Šifra'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='odpoveducastnika',
|
||||
name='sifra',
|
||||
field=models.CharField(max_length=255, verbose_name='Šifra'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='spravnaodpoved',
|
||||
name='sifra',
|
||||
field=models.CharField(max_length=255),
|
||||
),
|
||||
]
|
|
@ -1,21 +0,0 @@
|
|||
# Generated by Django 4.2.20 on 2025-03-19 21:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sifrovacka', '0007_alter_napoveda_sifra_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SeznamSifer',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('jmeno', models.CharField(help_text='něco co jde zadat do adresy', max_length=255, verbose_name='Jméno seznamu')),
|
||||
('sifry', models.ManyToManyField(to='sifrovacka.spravnaodpoved')),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -10,14 +10,14 @@ class OdpovedUcastnika(models.Model):
|
|||
|
||||
resitel = models.ForeignKey(Resitel, blank=False, null=False, on_delete=models.CASCADE)
|
||||
odpoved = models.TextField("Tajenka bez diakritiky", blank=False, null=False,)
|
||||
sifra = models.CharField("Šifra", max_length=255, blank=False, null=False,)
|
||||
sifra = models.IntegerField("Číslo šifry", blank=False, null=False,)
|
||||
timestamp = models.DateTimeField("Timestamp", blank=False, null=False, default=timezone.now)
|
||||
uspech = models.BooleanField("Úspěch", blank=False, null=False, default=False)
|
||||
|
||||
|
||||
class SpravnaOdpoved(models.Model):
|
||||
odpoved = models.TextField(blank=False, null=False,)
|
||||
sifra = models.CharField(max_length=255, blank=False, null=False,)
|
||||
sifra = models.IntegerField(blank=False, null=False,)
|
||||
skryty_text = models.TextField(blank=False, null=False,)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -29,20 +29,13 @@ class NapovezenoUcastnikovi(models.Model):
|
|||
ordering = ["-timestamp"]
|
||||
|
||||
resitel = models.ForeignKey(Resitel, blank=False, null=False, on_delete=models.CASCADE)
|
||||
sifra = models.CharField("Šifra", max_length=255, blank=False, null=False,)
|
||||
sifra = models.IntegerField("Číslo šifry", blank=False, null=False,)
|
||||
timestamp = models.DateTimeField("Timestamp", blank=False, null=False, default=timezone.now)
|
||||
|
||||
|
||||
class Napoveda(models.Model):
|
||||
text = models.TextField(blank=False, null=False,)
|
||||
sifra = models.CharField(max_length=255, blank=False, null=False,)
|
||||
sifra = models.IntegerField(blank=False, null=False,)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.sifra}: {self.text}"
|
||||
|
||||
class SeznamSifer(models.Model):
|
||||
jmeno = models.CharField("Jméno seznamu", max_length=255, blank=False, null=False, help_text="něco co jde zadat do adresy")
|
||||
sifry = models.ManyToManyField(SpravnaOdpoved)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.jmeno}"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from django.urls import path
|
||||
|
||||
from personalni.utils import org_required, resitel_or_org_required
|
||||
from .views import SifrovackaView, SifrovackaListView, SifrovackaNektereListView, NapovedaView, NapovedaListView, PreskoceniView
|
||||
from .views import SifrovackaView, SifrovackaListView, NapovedaView, NapovedaListView, PreskoceniView
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
|
@ -14,11 +14,6 @@ urlpatterns = [
|
|||
org_required(SifrovackaListView.as_view()),
|
||||
name='sifrovacka_odpovedi'
|
||||
),
|
||||
path(
|
||||
'odpovedi/<str:seznam>/',
|
||||
org_required(SifrovackaNektereListView.as_view()),
|
||||
name='sifrovacka_odpovedi_nektere'
|
||||
),
|
||||
path(
|
||||
'napoveda/',
|
||||
resitel_or_org_required(NapovedaView.as_view()),
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.views.generic import FormView, ListView
|
||||
|
||||
from various.views.pomocne import formularOKView
|
||||
from .forms import SifrovackaForm, NapovedaForm
|
||||
from .models import OdpovedUcastnika, SpravnaOdpoved, Napoveda, NapovezenoUcastnikovi, SeznamSifer
|
||||
from .models import OdpovedUcastnika, SpravnaOdpoved, Napoveda, NapovezenoUcastnikovi
|
||||
from personalni.models import Resitel
|
||||
|
||||
|
||||
|
@ -17,7 +16,7 @@ class SifrovackaView(FormView):
|
|||
resitel = Resitel.objects.get(osoba__user=self.request.user)
|
||||
instance.resitel = resitel
|
||||
instance.save()
|
||||
sifra = SpravnaOdpoved.objects.filter(sifra__iexact=instance.sifra, odpoved__iexact=instance.odpoved.strip()).first()
|
||||
sifra = SpravnaOdpoved.objects.filter(sifra=instance.sifra, odpoved__iexact=instance.odpoved.strip()).first()
|
||||
if sifra is None:
|
||||
return formularOKView(self.request, f'<h1>Bohužel vám hvězdy nebyly nakloněny. Rozumějte <i>máte to blbě</i>.</h1> <p><a href="{reverse("sifrovacka")}">Zkusit znovu.</a></p><br><br><br>')
|
||||
|
||||
|
@ -31,12 +30,6 @@ class SifrovackaListView(ListView):
|
|||
template_name = 'sifrovacka/odpovedi_list.html'
|
||||
model = OdpovedUcastnika
|
||||
|
||||
class SifrovackaNektereListView(SifrovackaListView):
|
||||
def get_queryset(self):
|
||||
seznam = get_object_or_404(SeznamSifer, jmeno=self.kwargs['seznam'])
|
||||
orig = super().get_queryset()
|
||||
return orig.filter(sifra__in=seznam.sifry.all().values('sifra')) # poslední je kvůli tomu, že máme odkaz na celý objekt a ne jen na jméno šifry.
|
||||
|
||||
|
||||
class NapovedaView(FormView):
|
||||
template_name = 'sifrovacka/napoveda.html'
|
||||
|
@ -47,10 +40,10 @@ class NapovedaView(FormView):
|
|||
resitel = Resitel.objects.get(osoba__user=self.request.user)
|
||||
instance.resitel = resitel
|
||||
|
||||
if NapovezenoUcastnikovi.objects.filter(resitel=resitel, sifra__iexact=instance.sifra).first() is None:
|
||||
if NapovezenoUcastnikovi.objects.filter(resitel=resitel, sifra=instance.sifra).first() is None:
|
||||
instance.save()
|
||||
|
||||
napoveda = Napoveda.objects.filter(sifra__iexact=instance.sifra).first()
|
||||
napoveda = Napoveda.objects.filter(sifra=instance.sifra).first()
|
||||
return formularOKView(self.request, f'<h1>Nápověda k šifře číslo {instance.sifra} je:</h1><p>{napoveda.text}</p> <p><a href="{reverse("sifrovacka")}">Odevzdat řešení.</a></p><br><br><br>')
|
||||
|
||||
|
||||
|
@ -70,6 +63,6 @@ class PreskoceniView(FormView):
|
|||
resitel = Resitel.objects.get(osoba__user=self.request.user)
|
||||
instance.resitel = resitel
|
||||
instance.save()
|
||||
sifra = SpravnaOdpoved.objects.filter(sifra__iexact=instance.sifra).first() # FIXME co když je více "správných" odpovědí?
|
||||
sifra = SpravnaOdpoved.objects.filter(sifra=instance.sifra).first() # FIXME co když je více "správných" odpovědí?
|
||||
|
||||
return formularOKView(self.request, f'<h1>{sifra.skryty_text}</h1> <p><a href="{reverse("sifrovacka")}">Zpět na odevzdávátko.</a></p><br><br><br>')
|
||||
|
|
Loading…
Reference in a new issue