Podezřelé semináře (#1465) #65
podezrele-seminare
into master
3 weeks ago
@ -1,6 +1,4 @@ |
|||
""" |
|||
Zde bývalo vše. Teď tu zbývají všechny modely a části webu jako archiv, |
|||
přehled orgů, aktuální (k aktuálnímu číslu) věci, titulka a jak řešit. |
|||
|
|||
Také je tu generování testovacích (lokálních) dat. |
|||
""" |
|||
Zde bývalo vše. Teď tu zbývají migrace. |
|||
A kód pro `import seminar.models as m` pro ./manage.py shell. |
|||
""" |
|||
|
@ -0,0 +1,15 @@ |
|||
# Tento soubor slouží pouze pro shell a podobné. Nikde neimportovat v kódu! |
|||
|
|||
print("Naimportoval jsi `seminar.models`. Pevně věřím, že to nebylo nikde v kódu. Díky.") |
|||
|
|||
from galerie.models import * |
|||
from header_fotky.models import * |
|||
from korektury.models import * |
|||
from novinky.models import * |
|||
from odevzdavatko.models import * |
|||
from personalni.models import * |
|||
from prednasky.models import * |
|||
from soustredeni.models import * |
|||
from treenode.models import * |
|||
from tvorba.models import * |
|||
from various.models import * |
@ -1,21 +0,0 @@ |
|||
from .tvorba import * |
|||
from .base import * |
|||
|
|||
from various.models import Nastaveni |
|||
from personalni.models import Organizator, Resitel, Skola, Prijemce, Osoba |
|||
from soustredeni.models import Soustredeni, Soustredeni_Ucastnici, Soustredeni_Organizatori, Konfera, Konfery_Ucastnici |
|||
from novinky.models import Novinky |
|||
from odevzdavatko.models import Reseni, PrilohaReseni, Reseni_Resitele, Hodnoceni |
|||
from tvorba.models import ZmrazenaVysledkovka, Deadline, Cislo, Rocnik, Pohadka, Tema, Problem, Problemy_Opravovatele, Uloha, Clanek |
|||
from treenode.models import UlohaVzorakNode, UlohaZadaniNode, CisloNode, TemaVCisleNode, OrgTextNode, Obrazek, RocnikNode, PohadkaNode, TextNode, MezicisloNode, ReseniNode, CastNode, Text, TreeNode |
|||
|
|||
# Kvůli migr. 0041 |
|||
from soustredeni.models import generate_filename_konfera |
|||
# migr. 0001 |
|||
from odevzdavatko.models import generate_filename |
|||
# migr. 0031, 0032, 0081 |
|||
from tvorba.models import cislo_pdf_filename |
|||
# migr. 0082 |
|||
from tvorba.models import cislo_png_filename |
|||
# migr 0100 (hack) |
|||
import tvorba.models as tvorba |
@ -1,23 +0,0 @@ |
|||
from django.urls import reverse |
|||
from django.db import models |
|||
|
|||
|
|||
class SeminarModelBase(models.Model): |
|||
|
|||
class Meta: |
|||
abstract = True |
|||
|
|||
def verejne(self): |
|||
return False |
|||
|
|||
# def get_absolute_url(self): |
|||
# return "https://" + str(get_current_site(None)) + self.verejne_url() |
|||
|
|||
def admin_url(self): |
|||
app_name = self._meta.app_label |
|||
model_name = self._meta.model_name |
|||
return reverse('admin:{}_{}_change'.format(app_name, model_name), args=(self.id, )) |
|||
|
|||
# def verejne_url(self): |
|||
# return None |
|||
|
@ -1,14 +0,0 @@ |
|||
import os |
|||
import logging |
|||
|
|||
from django.core.files.storage import FileSystemStorage |
|||
|
|||
logger = logging.getLogger(__name__) |
|||
|
|||
class OverwriteStorage(FileSystemStorage): |
|||
""" Varianta FileSystemStorage, která v případě, že soubor cílového |
|||
jména již existuje, ho smaže a místo něj uloží soubor nový""" |
|||
def get_available_name(self,name, max_length=None): |
|||
if self.exists(name): |
|||
os.remove(os.path.join(self.location,name)) |
|||
return super().get_available_name(name,max_length) |
@ -1,6 +1,6 @@ |
|||
from django import template |
|||
from enum import Enum |
|||
import seminar.models as m |
|||
from .models import RocnikNode, CisloNode, CastNode, TextNode, TemaVCisleNode, UlohaVzorakNode, UlohaZadaniNode, PohadkaNode |
|||
ledoian
commented 3 weeks ago
Review
(Těchto TreeNodů je tu málo, ale nechce se mi teď zjišťovat, které tři chybí…) |
|||
|
|||
register = template.Library() |
|||
|
|||
@ -11,8 +11,8 @@ def nodeType(value): |
|||
if isinstance(value,CastNode): return "Část" |
|||
if isinstance(value,TextNode): return "Text" |
|||
if isinstance(value,TemaVCisleNode): return "Téma v čísle" |
|||
if isinstance(value,KonferaNode): return "Konfera" |
|||
if isinstance(value,ClanekNode): return "Článek" |
|||
# if isinstance(value,KonferaNode): return "Konfera" # FIXME neexistuje |
|||
# if isinstance(value,ClanekNode): return "Článek" # FIXME neexistuje |
|||
ledoian
commented 3 weeks ago
Review
Tyhle komentáře způsobí tiché spadnutí. Byl by to
zelvuska
commented 3 weeks ago
Review
To je asi otázka spíš na to, proč KonferaNode a ClanekNode přestalo existovat a proč s tím nepřestal existovat i tento kód… |
|||
if isinstance(value,UlohaVzorakNode): return "Vzorák" |
|||
if isinstance(value,UlohaZadaniNode): return "Zadání úlohy" |
|||
if isinstance(value,PohadkaNode): return "Pohádka" |
|||
@ -22,53 +22,57 @@ def nodeType(value): |
|||
|
|||
@register.filter |
|||
def isRocnik(value): |
|||
return isinstance(value, m.RocnikNode) |
|||
return isinstance(value, RocnikNode) |
|||
|
|||
@register.filter |
|||
def isCislo(value): |
|||
return isinstance(value, m.CisloNode) |
|||
return isinstance(value, CisloNode) |
|||
|
|||
@register.filter |
|||
def isCast(value): |
|||
return isinstance(value, m.CastNode) |
|||
return isinstance(value, CastNode) |
|||
|
|||
@register.filter |
|||
def isText(value): |
|||
return isinstance(value, m.TextNode) |
|||
return isinstance(value, TextNode) |
|||
|
|||
@register.filter |
|||
def isTemaVCisle(value): |
|||
return isinstance(value, m.TemaVCisleNode) |
|||
return isinstance(value, TemaVCisleNode) |
|||
|
|||
@register.filter |
|||
def isKonfera(value): |
|||
return isinstance(value, m.KonferaNode) |
|||
# FIXME neexistuje |
|||
# return isinstance(value, KonferaNode) |
|||
ledoian
commented 3 weeks ago
Review
Prosím aspoň zalogovat, neumřít tiše.
zelvuska
commented 3 weeks ago
Review
Stejně jako výše. KonferaNode prostě neexistuje. (Přestala existovat v migraci 0080, které jsi autor…) |
|||
return False |
|||
|
|||
@register.filter |
|||
def isClanek(value): |
|||
return isinstance(value, m.ClanekNode) |
|||
# FIXME neexistuje |
|||
# return isinstance(value, ClanekNode) |
|||
return False |
|||
|
|||
@register.filter |
|||
def isUlohaVzorak(value): |
|||
return isinstance(value, m.UlohaVzorakNode) |
|||
return isinstance(value, UlohaVzorakNode) |
|||
|
|||
@register.filter |
|||
def isUlohaZadani(value): |
|||
return isinstance(value, m.UlohaZadaniNode) |
|||
return isinstance(value, UlohaZadaniNode) |
|||
|
|||
@register.filter |
|||
def isPohadka(value): |
|||
return isinstance(value, m.PohadkaNode) |
|||
return isinstance(value, PohadkaNode) |
|||
|
|||
@register.filter |
|||
def isReseni(value): |
|||
return False |
|||
# return isinstance(value, m.OtisteneReseniNode) |
|||
# return isinstance(value, OtisteneReseniNode) |
|||
|
|||
@register.filter |
|||
def isOrgText(value): |
|||
return False |
|||
# return isinstance(value, m.OrgTextNode) |
|||
# return isinstance(value, OrgTextNode) |
|||
|
|||
|
|||
### |
|||
|
@ -1,16 +1,16 @@ |
|||
from django.test import TestCase |
|||
import treenode.treelib as tl |
|||
import seminar.models as m |
|||
from .models import CastNode |
|||
ledoian
commented 3 weeks ago
Review
V principu myslím, že tady je lepší řešení spíš
zelvuska
commented 3 weeks ago
Review
Proč si myslíš, že je lepší náhodná zkratka, než importování přímo věcí (když je to lokální věc). A celkově nad tímhle (jak má vypadat importování toho všeho, co předtím bylo |
|||
|
|||
class SimpleTreeLibTests(TestCase): |
|||
def setUp(self): |
|||
# Vyrobíme pár nějakých Nodů |
|||
self.root = m.CastNode(root=None, first_child=None, succ=None, nadpis="Root") |
|||
self.root = CastNode(root=None, first_child=None, succ=None, nadpis="Root") |
|||
self.root.save() |
|||
self.some_node = m.CastNode(root=self.root, first_child=None, succ=None, nadpis="Přetržené") |
|||
self.other_node = m.CastNode(root=self.root, first_child=None, succ=None, nadpis="Dítě") |
|||
self.some_orphan = m.CastNode(root=None, first_child=None, succ=None, nadpis="Ošklivé") |
|||
self.other_orphan = m.CastNode(root=None, first_child=None, succ=None, nadpis="Káčátko") |
|||
self.some_node = CastNode(root=self.root, first_child=None, succ=None, nadpis="Přetržené") |
|||
self.other_node = CastNode(root=self.root, first_child=None, succ=None, nadpis="Dítě") |
|||
self.some_orphan = CastNode(root=None, first_child=None, succ=None, nadpis="Ošklivé") |
|||
self.other_orphan = CastNode(root=None, first_child=None, succ=None, nadpis="Káčátko") |
|||
|
|||
# Trochu je pospojujeme |
|||
self.root.first_child = self.some_node |
|||
|
@ -6,8 +6,8 @@ from django.views.generic.edit import CreateView |
|||
from django.contrib.auth.mixins import LoginRequiredMixin |
|||
from django.core.exceptions import PermissionDenied |
|||
|
|||
import seminar.models as s |
|||
import seminar.models as m |
|||
from .models import TemaVCisleNode, RocnikNode, CisloNode, UlohaVzorakNode, UlohaZadaniNode, TreeNode, CastNode, TextNode, ReseniNode, PohadkaNode, OrgTextNode |
|||
ledoian
commented 3 weeks ago
Review
(Tu chybí
zelvuska
commented 3 weeks ago
Review
Asi nejsem schopen opravit (aniž bych se snažil pochopit treenode). |
|||
from .models import Text, Obrazek |
|||
from treenode import treelib |
|||
import treenode.forms as f |
|||
import treenode.templatetags as tnltt |
|||
@ -29,7 +29,7 @@ class TNLData(object): |
|||
|
|||
if parent: |
|||
self.tema_in_path = parent.tema_in_path |
|||
if isinstance(anode, m.TemaVCisleNode): |
|||
if isinstance(anode, TemaVCisleNode): |
|||
self.tema_in_path = True |
|||
|
|||
def add_edit_options(self): |
|||
@ -51,11 +51,11 @@ class TNLData(object): |
|||
(All of them have method verejne.)""" |
|||
parent = anode # chceme začít už od konkrétního node včetně |
|||
while True: |
|||
rocnik = isinstance(parent, s.RocnikNode) |
|||
cislo = isinstance(parent, s.CisloNode) |
|||
uloha = (isinstance(parent, s.UlohaVzorakNode) or |
|||
isinstance(parent, s.UlohaZadaniNode)) |
|||
tema = isinstance(parent, s.TemaVCisleNode) |
|||
rocnik = isinstance(parent, RocnikNode) |
|||
cislo = isinstance(parent, CisloNode) |
|||
uloha = (isinstance(parent, UlohaVzorakNode) or |
|||
isinstance(parent, UlohaZadaniNode)) |
|||
tema = isinstance(parent, TemaVCisleNode) |
|||
|
|||
if (rocnik or cislo or uloha or tema) or parent==None: |
|||
break |
|||
@ -158,7 +158,7 @@ class TNLData(object): |
|||
|
|||
|
|||
class TreeNodeView(generic.DetailView): |
|||
model = s.TreeNode |
|||
model = TreeNode |
|||
template_name = 'treenode/treenode.html' |
|||
|
|||
def get_context_data(self,**kwargs): |
|||
@ -168,7 +168,7 @@ class TreeNodeView(generic.DetailView): |
|||
|
|||
|
|||
class TreeNodeJSONView(generic.DetailView): |
|||
model = s.TreeNode |
|||
model = TreeNode |
|||
|
|||
def get(self,request,*args, **kwargs): |
|||
self.object = self.get_object() |
|||
@ -178,21 +178,21 @@ class TreeNodeJSONView(generic.DetailView): |
|||
|
|||
class TreeNodePridatView(generic.View): |
|||
type_from_str = { |
|||
'rocnikNode': m.RocnikNode, |
|||
'cisloNode': m.CisloNode, |
|||
'castNode': m.CastNode, |
|||
'textNode': m.TextNode, |
|||
'temaVCisleNode': m.TemaVCisleNode, |
|||
'reseniNode': m.ReseniNode, |
|||
'ulohaZadaniNode': m.UlohaZadaniNode, |
|||
'ulohaVzorakNode': m.UlohaVzorakNode, |
|||
'pohadkaNode': m.PohadkaNode, |
|||
'orgText': m.OrgTextNode, |
|||
'rocnikNode': RocnikNode, |
|||
'cisloNode': CisloNode, |
|||
'castNode': CastNode, |
|||
'textNode': TextNode, |
|||
'temaVCisleNode': TemaVCisleNode, |
|||
'reseniNode': ReseniNode, |
|||
'ulohaZadaniNode': UlohaZadaniNode, |
|||
'ulohaVzorakNode': UlohaVzorakNode, |
|||
'pohadkaNode': PohadkaNode, |
|||
'orgText': OrgTextNode, |
|||
} |
|||
|
|||
def post(self, request, *args, **kwargs): |
|||
######## FIXME: ROZEPSANE, NEFUNGUJE, DOPSAT !!!!!! ########### |
|||
node = s.TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
node = TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
kam = self.kwargs['kam'] |
|||
co = self.kwargs['co'] |
|||
typ = self.type_from_str[co] |
|||
@ -202,19 +202,19 @@ class TreeNodePridatView(generic.View): |
|||
if kam not in ('pred','syn','za'): |
|||
raise ValidationError('Přidat lze pouze před nebo za node nebo jako syna') |
|||
|
|||
if co == m.TextNode: |
|||
new_obj = m.Text() |
|||
if co == TextNode: |
|||
new_obj = Text() |
|||
new_obj.save() |
|||
elif co == m.CastNode: |
|||
new_obj = m.CastNode() |
|||
elif co == CastNode: |
|||
new_obj = CastNode() |
|||
new_obj.nadpis = request.POST.get('pridat-castNode-{}-{}'.format(node.id,kam)) |
|||
new_obj.save() |
|||
elif co == m.ReseniNode: |
|||
elif co == ReseniNode: |
|||
new_obj = m |
|||
pass |
|||
elif co == m.UlohaZadaniNode: |
|||
elif co == UlohaZadaniNode: |
|||
pass |
|||
elif co == m.UlohaReseniNode: |
|||
elif co == UlohaReseniNode: |
|||
pass |
|||
else: |
|||
new_obj = None |
|||
@ -225,15 +225,15 @@ class TreeNodePridatView(generic.View): |
|||
|
|||
|
|||
if kam == 'syn': |
|||
if typ == m.TextNode: |
|||
text_obj = m.Text() |
|||
if typ == TextNode: |
|||
text_obj = Text() |
|||
text_obj.save() |
|||
node = treelib.create_child(node, typ, text=text_obj) |
|||
else: |
|||
node = treelib.create_child(node, typ) |
|||
if kam == 'za': |
|||
if typ == m.TextNode: |
|||
text_obj = m.Text() |
|||
if typ == TextNode: |
|||
text_obj = Text() |
|||
text_obj.save() |
|||
node = treelib.create_node_after(node, typ, text=text_obj) |
|||
else: |
|||
@ -244,7 +244,7 @@ class TreeNodePridatView(generic.View): |
|||
|
|||
class TreeNodeSmazatView(generic.base.View): |
|||
def post(self, request, *args, **kwargs): |
|||
node = s.TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
node = TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
if node.first_child: |
|||
raise NotImplementedError('Mazání TreeNode se syny není zatím podporováno!') |
|||
treelib.disconnect_node(node) |
|||
@ -254,7 +254,7 @@ class TreeNodeSmazatView(generic.base.View): |
|||
|
|||
class TreeNodeOdvesitPrycView(generic.base.View): |
|||
def post(self, request, *args, **kwargs): |
|||
node = s.TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
node = TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
treelib.disconnect_node(node) |
|||
node.root = None |
|||
node.save() |
|||
@ -263,7 +263,7 @@ class TreeNodeOdvesitPrycView(generic.base.View): |
|||
|
|||
class TreeNodePodvesitView(generic.base.View): |
|||
def post(self, request, *args, **kwargs): |
|||
node = s.TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
node = TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
kam = self.kwargs['kam'] |
|||
if kam == 'pred': |
|||
treelib.lower_node(node) |
|||
@ -274,21 +274,21 @@ class TreeNodePodvesitView(generic.base.View): |
|||
|
|||
class TreeNodeProhoditView(generic.base.View): |
|||
def post(self, request, *args, **kwargs): |
|||
node = s.TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
node = TreeNode.objects.get(pk=self.kwargs['pk']) |
|||
treelib.swap_succ(node) |
|||
return redirect(request.headers.get('referer')) |
|||
#FIXME ve formulari predat puvodni url a vratit redirect na ni |
|||
|
|||
class SirotcinecView(generic.ListView): |
|||
model = s.TreeNode |
|||
model = TreeNode |
|||
template_name = 'treenode/orphanage.html' |
|||
|
|||
def get_queryset(self): |
|||
return s.TreeNode.objects.not_instance_of(s.RocnikNode).filter(root=None,prev=None,succ=None,father_of_first=None) |
|||
return TreeNode.objects.not_instance_of(RocnikNode).filter(root=None,prev=None,succ=None,father_of_first=None) |
|||
|
|||
# FIXME pouzit Django REST Framework |
|||
class TextWebView(generic.DetailView): |
|||
model = s.Text |
|||
model = Text |
|||
|
|||
def get(self,request,*args, **kwargs): |
|||
self.object = self.get_object() |
|||
@ -300,7 +300,7 @@ class VueTestView(generic.TemplateView): |
|||
|
|||
|
|||
class NahrajObrazekKTreeNoduView(LoginRequiredMixin, CreateView): |
|||
model = s.Obrazek |
|||
model = Obrazek |
|||
form_class = f.NahrajObrazekKTreeNoduForm |
|||
|
|||
def get_initial(self): |
|||
@ -316,7 +316,7 @@ class NahrajObrazekKTreeNoduView(LoginRequiredMixin, CreateView): |
|||
print(form) |
|||
self.object = form.save(commit=False) |
|||
print(self.object.na_web) |
|||
self.object.text = m.Text.objects.get(pk=int(self.request.headers['Textid'])) |
|||
self.object.text = Text.objects.get(pk=int(self.request.headers['Textid'])) |
|||
self.object.save() |
|||
|
|||
return JsonResponse({"url":self.object.na_web.url}) |
|||
|
@ -1,11 +1,11 @@ |
|||
from django.core.management.base import BaseCommand |
|||
import seminar.models as m |
|||
from tvorba.models import Deadline |
|||
|
|||
|
|||
class Command(BaseCommand): |
|||
help = "Všem deadlinům se zveřejněnou výsledkovkou vygeneruj výsledkovku" |
|||
|
|||
def handle(self, *args, **options): |
|||
for deadline in m.Deadline.objects.filter(verejna_vysledkovka=True): |
|||
for deadline in Deadline.objects.filter(verejna_vysledkovka=True): |
|||
deadline.vygeneruj_vysledkovku() |
|||
|
|||
|