|
@ -1,44 +1,32 @@ |
|
|
from django import template |
|
|
from django import template |
|
|
from django.utils.safestring import mark_safe |
|
|
from django.utils.safestring import mark_safe |
|
|
from seminar.utils import TypDeadline, deadline |
|
|
|
|
|
register = template.Library() |
|
|
register = template.Library() |
|
|
|
|
|
import seminar.models as m |
|
|
@register.filter(name='deadline') |
|
|
|
|
|
def deadline_text(datum): |
|
|
|
|
|
if deadline(datum) is None: |
|
|
|
|
|
return 'Neznámý deadline' |
|
|
|
|
|
typ, cislo, dl = deadline(datum) |
|
|
|
|
|
strings = { |
|
|
|
|
|
TypDeadline.PredDeadline: f"1. deadline čísla {cislo} ({dl})", |
|
|
|
|
|
TypDeadline.SousDeadline: f"Soustřeďkový deadline čísla {cislo} ({dl})", |
|
|
|
|
|
TypDeadline.FinalDeadline: f"Finální deadline čísla {cislo} ({dl})", |
|
|
|
|
|
} |
|
|
|
|
|
return strings[typ] |
|
|
|
|
|
|
|
|
|
|
|
@register.filter(name='deadline_kratseji') |
|
|
@register.filter(name='deadline_kratseji') |
|
|
def deadline_kratsi_text(datum): |
|
|
def deadline_kratsi_text(deadline: m.Deadline): |
|
|
if deadline(datum) is None: |
|
|
if deadline is None: |
|
|
return 'NONE' |
|
|
return 'NONE' |
|
|
typ, cislo, dl = deadline(datum) |
|
|
|
|
|
strings = { |
|
|
strings = { |
|
|
TypDeadline.PredDeadline: f"{cislo} ♲", |
|
|
m.Deadline.TYP_PRVNI: f"{deadline.cislo} ♲", |
|
|
TypDeadline.SousDeadline: f"{cislo} Ⓢ", |
|
|
m.Deadline.TYP_SOUS: f"{deadline.cislo} Ⓢ", |
|
|
TypDeadline.FinalDeadline: f"{cislo} ✓", |
|
|
m.Deadline.TYP_PRVNI_A_SOUS: f"{deadline.cislo} ♲Ⓢ", |
|
|
|
|
|
m.Deadline.TYP_CISLA: f"{deadline.cislo} ✓", |
|
|
} |
|
|
} |
|
|
return strings[typ] |
|
|
return strings[deadline.typ] |
|
|
|
|
|
|
|
|
@register.filter(name='deadline_html') |
|
|
@register.filter(name='deadline_html') |
|
|
def deadline_html(datum): |
|
|
def deadline_html(deadline: m.Deadline): |
|
|
if deadline(datum) is None: |
|
|
if deadline is None: |
|
|
return 'Neznámý deadline' |
|
|
return 'Neznámý deadline' |
|
|
typ, _, _ = deadline(datum) |
|
|
text = deadline_kratsi_text(deadline) |
|
|
text = deadline_kratsi_text(datum) |
|
|
|
|
|
classes = { |
|
|
classes = { |
|
|
TypDeadline.PredDeadline: 'preddeadline', |
|
|
m.Deadline.TYP_PRVNI: 'preddeadline', |
|
|
TypDeadline.SousDeadline: 'sous_deadline', |
|
|
m.Deadline.TYP_SOUS: 'sous_deadline', |
|
|
TypDeadline.FinalDeadline: 'final_deadline', |
|
|
m.Deadline.TYP_PRVNI_A_SOUS: 'sous_deadline', |
|
|
|
|
|
m.Deadline.TYP_CISLA: 'final_deadline', |
|
|
} |
|
|
} |
|
|
return mark_safe(f'<span class="{classes[typ]}">{text}</span>') |
|
|
return mark_safe(f'<span class="{classes[deadline.typ]}">{text}</span>') |
|
|
|
|
|
|
|
|
@register.filter(name='zkrat_nazev_problemu') |
|
|
@register.filter(name='zkrat_nazev_problemu') |
|
|
def zkrat_nazev_problemu(nazev,width): |
|
|
def zkrat_nazev_problemu(nazev,width): |
|
|