Merge branch 'python3' of gimli.ms.mff.cuni.cz:/akce/mam/git/mamweb into python3
This commit is contained in:
commit
2c53ddcec8
28 changed files with 2347 additions and 2254 deletions
17
convert_spaces_to_tabs.sh
Executable file
17
convert_spaces_to_tabs.sh
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
if test "$#" -lt 1
|
||||
then
|
||||
echo "Usage: $0 file ..."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
for file in "$@"
|
||||
do
|
||||
# Do the sed magic: keep replacing 4 spaces at the begining of line
|
||||
sed -i -re '
|
||||
: loop
|
||||
s/^( *) /\1 /
|
||||
t loop
|
||||
' "$file"
|
||||
done
|
|
@ -10,45 +10,45 @@ from autocomplete_light import shortcuts as autocomplete_light
|
|||
# akction
|
||||
|
||||
def zverejnit_fotogalerii(modeladmin, request, queryset):
|
||||
'''zverejni vybranou fotogalerii i jeji vsechny podgalerie'''
|
||||
for galerie in queryset:
|
||||
galerie.zobrazit = 0
|
||||
galerie.save()
|
||||
zverejnit_fotogalerii(modeladmin, request,
|
||||
Galerie.objects.filter(galerie_up = galerie))
|
||||
zverejnit_fotogalerii.short_description = 'Zveřejnit fotogalerie'
|
||||
'''zverejni vybranou fotogalerii i jeji vsechny podgalerie'''
|
||||
for galerie in queryset:
|
||||
galerie.zobrazit = 0
|
||||
galerie.save()
|
||||
zverejnit_fotogalerii(modeladmin, request,
|
||||
Galerie.objects.filter(galerie_up = galerie))
|
||||
zverejnit_fotogalerii.short_description = 'Zveřejnit fotogalerie'
|
||||
|
||||
|
||||
def prepnout_fotogalerii_do_org_rezimu(modeladmin, request, queryset):
|
||||
'''zneverjni vybranou fotogalerii i jeji vsechny podgalerie'''
|
||||
for galerie in queryset:
|
||||
galerie.zobrazit = 1
|
||||
galerie.save()
|
||||
prepnout_fotogalerii_do_org_rezimu(modeladmin, request,
|
||||
Galerie.objects.filter(galerie_up = galerie))
|
||||
prepnout_fotogalerii_do_org_rezimu.short_description = \
|
||||
'Přepnout do režimu úprav (zneveřejní galerii)'
|
||||
'''zneverjni vybranou fotogalerii i jeji vsechny podgalerie'''
|
||||
for galerie in queryset:
|
||||
galerie.zobrazit = 1
|
||||
galerie.save()
|
||||
prepnout_fotogalerii_do_org_rezimu(modeladmin, request,
|
||||
Galerie.objects.filter(galerie_up = galerie))
|
||||
prepnout_fotogalerii_do_org_rezimu.short_description = \
|
||||
'Přepnout do režimu úprav (zneveřejní galerii)'
|
||||
|
||||
class GalerieInline(admin.TabularInline):
|
||||
model = Obrazek
|
||||
fields = ['obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag']
|
||||
readonly_fields = ['nazev', 'obrazek_maly_tag']
|
||||
formfield_overrides = {
|
||||
models.TextField: {'widget': forms.TextInput},
|
||||
}
|
||||
model = Obrazek
|
||||
fields = ['obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag']
|
||||
readonly_fields = ['nazev', 'obrazek_maly_tag']
|
||||
formfield_overrides = {
|
||||
models.TextField: {'widget': forms.TextInput},
|
||||
}
|
||||
|
||||
class ObrazekAdmin(admin.ModelAdmin):
|
||||
list_display = ('obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag')
|
||||
|
||||
list_display = ('obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag')
|
||||
|
||||
class GalerieAdmin(admin.ModelAdmin):
|
||||
form = autocomplete_light.modelform_factory(Galerie, autocomplete_fields=['titulni_obrazek'], fields=['titulni_obrazek'])
|
||||
model = Galerie
|
||||
fields = ('zobrazit', 'nazev', 'titulni_obrazek', 'popis', 'galerie_up', 'soustredeni', 'poradi')
|
||||
list_display = ('nazev', 'soustredeni', 'galerie_up', 'poradi', 'zobrazit', 'datum_zmeny')
|
||||
inlines = [GalerieInline]
|
||||
actions = [zverejnit_fotogalerii, prepnout_fotogalerii_do_org_rezimu]
|
||||
save_on_top = True
|
||||
ordering = ['galerie_up__nazev', 'poradi']
|
||||
form = autocomplete_light.modelform_factory(Galerie, autocomplete_fields=['titulni_obrazek'], fields=['titulni_obrazek'])
|
||||
model = Galerie
|
||||
fields = ('zobrazit', 'nazev', 'titulni_obrazek', 'popis', 'galerie_up', 'soustredeni', 'poradi')
|
||||
list_display = ('nazev', 'soustredeni', 'galerie_up', 'poradi', 'zobrazit', 'datum_zmeny')
|
||||
inlines = [GalerieInline]
|
||||
actions = [zverejnit_fotogalerii, prepnout_fotogalerii_do_org_rezimu]
|
||||
save_on_top = True
|
||||
ordering = ['galerie_up__nazev', 'poradi']
|
||||
|
||||
admin.site.register(Obrazek, ObrazekAdmin)
|
||||
admin.site.register(Galerie, GalerieAdmin)
|
||||
|
|
|
@ -4,8 +4,8 @@ from django import forms
|
|||
from seminar.models import Soustredeni
|
||||
|
||||
class KomentarForm(forms.Form):
|
||||
komentar = forms.CharField(label = "Komentář:", max_length = 300, required=False)
|
||||
komentar = forms.CharField(label = "Komentář:", max_length = 300, required=False)
|
||||
|
||||
class NewGalerieForm(forms.Form):
|
||||
nazev = forms.CharField(label = "Název galerie", max_length = 100)
|
||||
#popis = forms.CharField(label = "Popis", required = False, max_length = 2000, widget = forms.Textarea)
|
||||
nazev = forms.CharField(label = "Název galerie", max_length = 100)
|
||||
#popis = forms.CharField(label = "Popis", required = False, max_length = 2000, widget = forms.Textarea)
|
||||
|
|
|
@ -14,109 +14,108 @@ VZDY=0
|
|||
ORG=1
|
||||
NIKDY=2
|
||||
VIDITELNOST = (
|
||||
(VZDY, 'Vždy'),
|
||||
(ORG, 'Organizátorům'),
|
||||
(NIKDY, 'Nikdy'),
|
||||
(VZDY, 'Vždy'),
|
||||
(ORG, 'Organizátorům'),
|
||||
(NIKDY, 'Nikdy'),
|
||||
)
|
||||
|
||||
# tyhle funkce jsou tady jen kvůli starým migracím, které se na ně odkazují
|
||||
# až se ty migrace někdy squashnou, tak by mělo být možné funkce smazat
|
||||
def obrazek_filename_maly():
|
||||
pass
|
||||
pass
|
||||
def obrazek_filename_stredni():
|
||||
pass
|
||||
pass
|
||||
def obrazek_filename_velky():
|
||||
pass
|
||||
pass
|
||||
|
||||
def obrazek_filename(self, filename):
|
||||
gal = self.galerie
|
||||
cislo_gal = force_unicode(gal.pk)
|
||||
gal = self.galerie
|
||||
cislo_gal = force_unicode(gal.pk)
|
||||
|
||||
# najdi kořenovou galerii
|
||||
while (gal.galerie_up):
|
||||
gal = gal.galerie_up
|
||||
# najdi kořenovou galerii
|
||||
while (gal.galerie_up):
|
||||
gal = gal.galerie_up
|
||||
|
||||
# soustředění je v cestě jen pokud galerie pod nějaké patří
|
||||
cesta = (
|
||||
['Galerie'] +
|
||||
(["soustredeni_" + force_unicode(gal.soustredeni.pk)] if gal.soustredeni else []) +
|
||||
["galerie_" + cislo_gal, force_unicode(self.nazev)]
|
||||
)
|
||||
# soustředění je v cestě jen pokud galerie pod nějaké patří
|
||||
cesta = (
|
||||
['Galerie'] +
|
||||
(["soustredeni_" + force_unicode(gal.soustredeni.pk)] if gal.soustredeni else []) +
|
||||
["galerie_" + cislo_gal, force_unicode(self.nazev)]
|
||||
)
|
||||
|
||||
return os.path.join(*cesta)
|
||||
return os.path.join(*cesta)
|
||||
|
||||
class Obrazek(models.Model):
|
||||
obrazek_velky = models.ImageField(upload_to=obrazek_filename,
|
||||
help_text = "Lze vložit libovolně velký obrázek. Ideální je, aby alespoň jeden rozměr měl alespoň 500px.")
|
||||
obrazek_stredni = ImageSpecField(source='obrazek_velky',
|
||||
processors=[Transpose(Transpose.AUTO), ResizeToFit(900, 675, upscale=False)],
|
||||
options={'quality': 95})
|
||||
obrazek_maly = ImageSpecField(source='obrazek_velky',
|
||||
processors=[Transpose(Transpose.AUTO), ResizeToFit(167, 167, upscale=False)],
|
||||
options={'quality': 95})
|
||||
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)
|
||||
poradi = models.IntegerField('Pořadí', blank=True, null=True)
|
||||
obrazek_velky = models.ImageField(upload_to=obrazek_filename,
|
||||
help_text = "Lze vložit libovolně velký obrázek. Ideální je, aby alespoň jeden rozměr měl alespoň 500px.")
|
||||
obrazek_stredni = ImageSpecField(source='obrazek_velky',
|
||||
processors=[Transpose(Transpose.AUTO), ResizeToFit(900, 675, upscale=False)],
|
||||
options={'quality': 95})
|
||||
obrazek_maly = ImageSpecField(source='obrazek_velky',
|
||||
processors=[Transpose(Transpose.AUTO), ResizeToFit(167, 167, upscale=False)],
|
||||
options={'quality': 95})
|
||||
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)
|
||||
poradi = models.IntegerField('Pořadí', blank=True, null=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.obrazek_velky.name)
|
||||
def __unicode__(self):
|
||||
return unicode(self.obrazek_velky.name)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Obrázek'
|
||||
verbose_name_plural = 'Obrázky'
|
||||
ordering = ['nazev']
|
||||
class Meta:
|
||||
verbose_name = 'Obrázek'
|
||||
verbose_name_plural = 'Obrázky'
|
||||
ordering = ['nazev']
|
||||
|
||||
def obrazek_maly_tag(self):
|
||||
return u'<img src="{}">'.format(self.obrazek_maly.url)
|
||||
obrazek_maly_tag.short_description = "Náhled"
|
||||
obrazek_maly_tag.allow_tags = True
|
||||
def obrazek_maly_tag(self):
|
||||
return u'<img src="{}">'.format(self.obrazek_maly.url)
|
||||
obrazek_maly_tag.short_description = "Náhled"
|
||||
obrazek_maly_tag.allow_tags = True
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# obrázek potřebuje název, protože se z něj generuje cesta pro jeho uložení
|
||||
# (a pak se podle něj taky řadí)
|
||||
if self.nazev is None:
|
||||
self.nazev = os.path.basename(self.obrazek_velky.name)
|
||||
super(Obrazek, self).save(*args, **kwargs)
|
||||
def save(self, *args, **kwargs):
|
||||
# obrázek potřebuje název, protože se z něj generuje cesta pro jeho uložení
|
||||
# (a pak se podle něj taky řadí)
|
||||
if self.nazev is None:
|
||||
self.nazev = os.path.basename(self.obrazek_velky.name)
|
||||
super(Obrazek, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
class Galerie(models.Model):
|
||||
nazev = models.CharField('Název', max_length=100)
|
||||
datum_vytvoreni = models.DateTimeField('Datum vytvoření', auto_now_add = True)
|
||||
datum_zmeny = models.DateTimeField('Datum poslední změny', auto_now = True)
|
||||
popis = models.TextField('Popis', blank = True, null = True)
|
||||
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)
|
||||
soustredeni = models.ForeignKey(Soustredeni, blank = True, null = True)
|
||||
poradi = models.IntegerField('Pořadí', blank = True, null = True)
|
||||
nazev = models.CharField('Název', max_length=100)
|
||||
datum_vytvoreni = models.DateTimeField('Datum vytvoření', auto_now_add = True)
|
||||
datum_zmeny = models.DateTimeField('Datum poslední změny', auto_now = True)
|
||||
popis = models.TextField('Popis', blank = True, null = True)
|
||||
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)
|
||||
soustredeni = models.ForeignKey(Soustredeni, blank = True, null = True)
|
||||
poradi = models.IntegerField('Pořadí', blank = True, null = True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.nazev
|
||||
class Meta:
|
||||
verbose_name = 'Galerie'
|
||||
verbose_name_plural = 'Galerie'
|
||||
def __unicode__(self):
|
||||
return self.nazev
|
||||
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 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
|
||||
#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()
|
||||
#@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()
|
||||
|
|
|
@ -4,10 +4,10 @@ from django.conf.urls import include, url
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^(?P<pk>\d+)/$', views.nahled),
|
||||
url(r'^(?P<pk>\d+)/(?P<fotka>\d+)/$', views.detail),
|
||||
url(r'^(?P<galerie>\d+)/new/$', views.new_galerie),
|
||||
url(r'^(?P<galerie>\d+)/plus/(?P<subgalerie>\d+)/$', views.plus_galerie),
|
||||
url(r'^(?P<galerie>\d+)/minus/(?P<subgalerie>\d+)/$', views.minus_galerie),
|
||||
url(r'^(?P<pk>\d+)/$', views.nahled),
|
||||
url(r'^(?P<pk>\d+)/(?P<fotka>\d+)/$', views.detail),
|
||||
url(r'^(?P<galerie>\d+)/new/$', views.new_galerie),
|
||||
url(r'^(?P<galerie>\d+)/plus/(?P<subgalerie>\d+)/$', views.plus_galerie),
|
||||
url(r'^(?P<galerie>\d+)/minus/(?P<subgalerie>\d+)/$', views.minus_galerie),
|
||||
]
|
||||
|
||||
|
|
365
galerie/views.py
365
galerie/views.py
|
@ -12,222 +12,221 @@ from seminar.models import Soustredeni
|
|||
from galerie.forms import KomentarForm, NewGalerieForm
|
||||
|
||||
def zobrazit(galerie, request):
|
||||
preview = False
|
||||
if galerie.zobrazit >= 1:
|
||||
if request.user.is_staff:
|
||||
preview = True;
|
||||
else:
|
||||
raise Http404
|
||||
return preview
|
||||
preview = False
|
||||
if galerie.zobrazit >= 1:
|
||||
if request.user.is_staff:
|
||||
preview = True;
|
||||
else:
|
||||
raise Http404
|
||||
return preview
|
||||
|
||||
|
||||
def cesta_od_korene(g):
|
||||
"""Vrátí seznam galerií od kořene ke g"""
|
||||
cesta = []
|
||||
while g != None:
|
||||
cesta.append(g)
|
||||
g = g.galerie_up
|
||||
return reversed(cesta)
|
||||
"""Vrátí seznam galerií od kořene ke g"""
|
||||
cesta = []
|
||||
while g != None:
|
||||
cesta.append(g)
|
||||
g = g.galerie_up
|
||||
return reversed(cesta)
|
||||
|
||||
|
||||
def nahled(request, pk, soustredeni):
|
||||
"""Zobrazeni nahledu vsech fotek ve skupine."""
|
||||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
"""Zobrazeni nahledu vsech fotek ve skupine."""
|
||||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
|
||||
podgalerie = Galerie.objects.filter(galerie_up = galerie).order_by('poradi')
|
||||
if not request.user.is_staff:
|
||||
podgalerie = podgalerie.filter(zobrazit__lt=1)
|
||||
podgalerie = Galerie.objects.filter(galerie_up = galerie).order_by('poradi')
|
||||
if not request.user.is_staff:
|
||||
podgalerie = podgalerie.filter(zobrazit__lt=1)
|
||||
|
||||
obrazky = Obrazek.objects.filter(galerie = galerie)
|
||||
preview = zobrazit(galerie, request)
|
||||
obrazky = Obrazek.objects.filter(galerie = galerie)
|
||||
preview = zobrazit(galerie, request)
|
||||
|
||||
sourozenci = []
|
||||
if galerie.galerie_up:
|
||||
sourozenci = galerie.galerie_up.galerie_set.all().order_by('poradi')
|
||||
if not request.user.is_staff:
|
||||
sourozenci = sourozenci.filter(zobrazit__lt=1)
|
||||
sourozenci = []
|
||||
if galerie.galerie_up:
|
||||
sourozenci = galerie.galerie_up.galerie_set.all().order_by('poradi')
|
||||
if not request.user.is_staff:
|
||||
sourozenci = sourozenci.filter(zobrazit__lt=1)
|
||||
|
||||
predchozi = None
|
||||
nasledujici = None
|
||||
minuly = None
|
||||
for g in sourozenci:
|
||||
if g.pk == galerie.pk:
|
||||
predchozi = minuly
|
||||
if minuly != None and minuly.pk == galerie.pk:
|
||||
nasledujici = g
|
||||
break
|
||||
minuly = g
|
||||
predchozi = None
|
||||
nasledujici = None
|
||||
minuly = None
|
||||
for g in sourozenci:
|
||||
if g.pk == galerie.pk:
|
||||
predchozi = minuly
|
||||
if minuly != None and minuly.pk == galerie.pk:
|
||||
nasledujici = g
|
||||
break
|
||||
minuly = g
|
||||
|
||||
cesta = cesta_od_korene(galerie)
|
||||
cesta = cesta_od_korene(galerie)
|
||||
|
||||
return render(request, 'galerie/GalerieNahled.html',
|
||||
{'galerie' : galerie,
|
||||
'podgalerie' : podgalerie,
|
||||
'obrazky' : obrazky,
|
||||
'preview' : preview,
|
||||
'cesta': cesta,
|
||||
'sourozenci': sourozenci,
|
||||
'predchozi': predchozi,
|
||||
'nasledujici': nasledujici,
|
||||
})
|
||||
return render(request, 'galerie/GalerieNahled.html',
|
||||
{'galerie' : galerie,
|
||||
'podgalerie' : podgalerie,
|
||||
'obrazky' : obrazky,
|
||||
'preview' : preview,
|
||||
'cesta': cesta,
|
||||
'sourozenci': sourozenci,
|
||||
'predchozi': predchozi,
|
||||
'nasledujici': nasledujici,
|
||||
})
|
||||
|
||||
def detail(request, pk, fotka, soustredeni):
|
||||
"""Zobrazeni nahledu fotky s id 'fotka'."""
|
||||
MAX_VYSKA = 900
|
||||
MAX_SIRKA = 900
|
||||
MAX_VYSKA_MALA = 100
|
||||
MAX_SIRKA_MALA = 200
|
||||
NAHLEDU = 1
|
||||
"""Zobrazeni nahledu fotky s id 'fotka'."""
|
||||
MAX_VYSKA = 900
|
||||
MAX_SIRKA = 900
|
||||
MAX_VYSKA_MALA = 100
|
||||
MAX_SIRKA_MALA = 200
|
||||
NAHLEDU = 1
|
||||
|
||||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
preview = zobrazit(galerie, request)
|
||||
obrazek = get_object_or_404(Obrazek, pk=fotka)
|
||||
obrazky = galerie.obrazek_set.all()
|
||||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
preview = zobrazit(galerie, request)
|
||||
obrazek = get_object_or_404(Obrazek, pk=fotka)
|
||||
obrazky = galerie.obrazek_set.all()
|
||||
|
||||
# vytvoreni a obslouzeni formulare
|
||||
if request.method == 'POST':
|
||||
form = KomentarForm(request.POST)
|
||||
if form.is_valid():
|
||||
obrazek.popis = form.cleaned_data['komentar']
|
||||
obrazek.save()
|
||||
else:
|
||||
form = KomentarForm({'komentar': obrazek.popis})
|
||||
# vytvoreni a obslouzeni formulare
|
||||
if request.method == 'POST':
|
||||
form = KomentarForm(request.POST)
|
||||
if form.is_valid():
|
||||
obrazek.popis = form.cleaned_data['komentar']
|
||||
obrazek.save()
|
||||
else:
|
||||
form = KomentarForm({'komentar': obrazek.popis})
|
||||
|
||||
# Poradi aktualniho obrazku v galerii/stitku.
|
||||
for i in range(len(obrazky)):
|
||||
if obrazky[i] == obrazek:
|
||||
znacka = i
|
||||
break
|
||||
else:
|
||||
# Obrazek neni v galerii/stitku.
|
||||
raise Http404
|
||||
# Poradi aktualniho obrazku v galerii/stitku.
|
||||
for i in range(len(obrazky)):
|
||||
if obrazky[i] == obrazek:
|
||||
znacka = 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[znacka+1:znacka+NAHLEDU+1]
|
||||
if (znacka+1) > NAHLEDU:
|
||||
obrazky_predchozi = obrazky[znacka-NAHLEDU:znacka]
|
||||
else:
|
||||
obrazky_predchozi = obrazky[0:znacka]
|
||||
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 (znacka+1) == len(obrazky):
|
||||
nasledujici_galerie = Galerie.objects.\
|
||||
filter(galerie_up=galerie.galerie_up).\
|
||||
filter(poradi=(galerie.poradi+1))
|
||||
if nasledujici_galerie:
|
||||
nasledujici_galerie = nasledujici_galerie[0]
|
||||
else:
|
||||
nasledujici_galerie = None
|
||||
# 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[znacka+1:znacka+NAHLEDU+1]
|
||||
if (znacka+1) > NAHLEDU:
|
||||
obrazky_predchozi = obrazky[znacka-NAHLEDU:znacka]
|
||||
else:
|
||||
obrazky_predchozi = obrazky[0:znacka]
|
||||
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 (znacka+1) == len(obrazky):
|
||||
nasledujici_galerie = Galerie.objects.\
|
||||
filter(galerie_up=galerie.galerie_up).\
|
||||
filter(poradi=(galerie.poradi+1))
|
||||
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
|
||||
if vyska > MAX_VYSKA:
|
||||
sirka = sirka * MAX_VYSKA / vyska
|
||||
vyska = MAX_VYSKA
|
||||
if sirka > MAX_SIRKA:
|
||||
vyska = vyska * MAX_SIRKA / sirka
|
||||
sirka = MAX_SIRKA
|
||||
|
||||
return render(request, 'galerie/Galerie.html',
|
||||
{'galerie' : galerie,
|
||||
'predchozi_galerie' : predchozi_galerie,
|
||||
'nasledujici_galerie' : nasledujici_galerie,
|
||||
'obrazek' : obrazek,
|
||||
'vyska' : vyska,
|
||||
'sirka' : sirka,
|
||||
'obrazky_predchozi' : obrazky_predchozi,
|
||||
'obrazky_dalsi' : obrazky_dalsi,
|
||||
'preview' : preview,
|
||||
'form' : form,
|
||||
'cesta': cesta_od_korene(galerie),
|
||||
})
|
||||
# Preskalovani obrazku do vybraneho prostoru.
|
||||
vyska = obrazek.obrazek_stredni.height
|
||||
sirka = obrazek.obrazek_stredni.width
|
||||
if vyska > MAX_VYSKA:
|
||||
sirka = sirka * MAX_VYSKA / vyska
|
||||
vyska = MAX_VYSKA
|
||||
if sirka > MAX_SIRKA:
|
||||
vyska = vyska * MAX_SIRKA / sirka
|
||||
sirka = MAX_SIRKA
|
||||
|
||||
return render(request, 'galerie/Galerie.html',
|
||||
{'galerie' : galerie,
|
||||
'predchozi_galerie' : predchozi_galerie,
|
||||
'nasledujici_galerie' : nasledujici_galerie,
|
||||
'obrazek' : obrazek,
|
||||
'vyska' : vyska,
|
||||
'sirka' : sirka,
|
||||
'obrazky_predchozi' : obrazky_predchozi,
|
||||
'obrazky_dalsi' : obrazky_dalsi,
|
||||
'preview' : preview,
|
||||
'form' : form,
|
||||
'cesta': cesta_od_korene(galerie),
|
||||
})
|
||||
|
||||
|
||||
def new_galerie(request, galerie, soustredeni):
|
||||
|
||||
# zjistime k jakemu soustredeni se vaze nove vytvarena galerie
|
||||
soustredeni = get_object_or_404(Soustredeni, pk = soustredeni)
|
||||
# pokud je parametr galerie 0, pak jde o hlavni galerii
|
||||
# kdyz je nejaky jiny, pak je pk galerie pod kterou tu dalsi vytvarim
|
||||
if int(galerie) == 0:
|
||||
galerie_up = False
|
||||
galerie_text = "Hlavní fotogalerie soustředění"
|
||||
else:
|
||||
galerie_up = get_object_or_404(Galerie, pk = int(galerie))
|
||||
galerie_text = "podgalerii ke galerii " + str(galerie_up)
|
||||
# zjistime k jakemu soustredeni se vaze nove vytvarena galerie
|
||||
soustredeni = get_object_or_404(Soustredeni, pk = soustredeni)
|
||||
# pokud je parametr galerie 0, pak jde o hlavni galerii
|
||||
# kdyz je nejaky jiny, pak je pk galerie pod kterou tu dalsi vytvarim
|
||||
if int(galerie) == 0:
|
||||
galerie_up = False
|
||||
galerie_text = "Hlavní fotogalerie soustředění"
|
||||
else:
|
||||
galerie_up = get_object_or_404(Galerie, pk = int(galerie))
|
||||
galerie_text = "podgalerii ke galerii " + str(galerie_up)
|
||||
|
||||
# obsluha formulare umoznujiciho multiple nahravani fotek
|
||||
if request.method == 'POST':
|
||||
form = NewGalerieForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
# vytvoreni nove galerie
|
||||
gal = Galerie()
|
||||
gal.nazev = form.cleaned_data['nazev']
|
||||
#gal.popis = form.cleaned_data['popis'] # popis nepouzivame
|
||||
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,
|
||||
ale v takovem pripade musi byt nadrazene soustredeni a ne jinak '''
|
||||
if galerie_up:
|
||||
gal.galerie_up = galerie_up
|
||||
else:
|
||||
gal.soustredeni = soustredeni
|
||||
if gal.galerie_up:
|
||||
gal.poradi = int(len(gal.galerie_up.galerie_set.all())) + 1
|
||||
gal.save()
|
||||
# obsluha formulare umoznujiciho multiple nahravani fotek
|
||||
if request.method == 'POST':
|
||||
form = NewGalerieForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
# vytvoreni nove galerie
|
||||
gal = Galerie()
|
||||
gal.nazev = form.cleaned_data['nazev']
|
||||
#gal.popis = form.cleaned_data['popis'] # popis nepouzivame
|
||||
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,
|
||||
ale v takovem pripade musi byt nadrazene soustredeni a ne jinak '''
|
||||
if galerie_up:
|
||||
gal.galerie_up = galerie_up
|
||||
else:
|
||||
gal.soustredeni = soustredeni
|
||||
if gal.galerie_up:
|
||||
gal.poradi = int(len(gal.galerie_up.galerie_set.all())) + 1
|
||||
gal.save()
|
||||
|
||||
# zpracovani obrazku v galerii
|
||||
for obr in request.FILES.getlist('obr'):
|
||||
o = Obrazek()
|
||||
o.obrazek_velky = obr
|
||||
o.nazev = str(obr)
|
||||
o.galerie = gal
|
||||
o.save()
|
||||
# zpracovani obrazku v galerii
|
||||
for obr in request.FILES.getlist('obr'):
|
||||
o = Obrazek()
|
||||
o.obrazek_velky = obr
|
||||
o.nazev = str(obr)
|
||||
o.galerie = gal
|
||||
o.save()
|
||||
|
||||
# presmerovani na prave vzniklou galerii
|
||||
return HttpResponseRedirect('../../' + str(gal.pk))
|
||||
# presmerovani na prave vzniklou galerii
|
||||
return HttpResponseRedirect('../../' + str(gal.pk))
|
||||
|
||||
else:
|
||||
form = NewGalerieForm()
|
||||
else:
|
||||
form = NewGalerieForm()
|
||||
|
||||
|
||||
return render(request, 'galerie/GalerieNew.html',
|
||||
{
|
||||
'form' : form,
|
||||
'soustredeni' : soustredeni,
|
||||
'galerie_text' : galerie_text,
|
||||
})
|
||||
return render(request, 'galerie/GalerieNew.html',
|
||||
{
|
||||
'form' : form,
|
||||
'soustredeni' : soustredeni,
|
||||
'galerie_text' : galerie_text,
|
||||
})
|
||||
|
||||
def plus_galerie(request, galerie, soustredeni, subgalerie):
|
||||
galerie = get_object_or_404(Galerie, pk=subgalerie)
|
||||
if galerie.poradi:
|
||||
galerie.poradi += 1
|
||||
else:
|
||||
galerie.poradi = int(len(galerie.galerie_up.galerie_set.all()))
|
||||
galerie.save()
|
||||
return HttpResponseRedirect('../../')
|
||||
galerie = get_object_or_404(Galerie, pk=subgalerie)
|
||||
if galerie.poradi:
|
||||
galerie.poradi += 1
|
||||
else:
|
||||
galerie.poradi = int(len(galerie.galerie_up.galerie_set.all()))
|
||||
galerie.save()
|
||||
return HttpResponseRedirect('../../')
|
||||
|
||||
def minus_galerie(request, galerie, soustredeni, subgalerie):
|
||||
galerie = get_object_or_404(Galerie, pk=subgalerie)
|
||||
if galerie.poradi:
|
||||
galerie.poradi -= 1
|
||||
else:
|
||||
galerie.poradi = 1
|
||||
galerie.save()
|
||||
return HttpResponseRedirect('../../')
|
||||
galerie = get_object_or_404(Galerie, pk=subgalerie)
|
||||
if galerie.poradi:
|
||||
galerie.poradi -= 1
|
||||
else:
|
||||
galerie.poradi = 1
|
||||
galerie.save()
|
||||
return HttpResponseRedirect('../../')
|
||||
|
||||
|
|
|
@ -6,21 +6,21 @@ from korektury.models import KorekturovanePDF
|
|||
# Register your models here.
|
||||
class KorekturovanePDFAdmin(VersionAdmin):
|
||||
|
||||
readonly_fields = ['cas', 'stran']
|
||||
readonly_fields = ['cas', 'stran']
|
||||
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
if obj:
|
||||
return self.readonly_fields + ['pdf']
|
||||
return self.readonly_fields
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
if obj:
|
||||
return self.readonly_fields + ['pdf']
|
||||
return self.readonly_fields
|
||||
|
||||
fieldsets = [
|
||||
(None,
|
||||
{'fields':
|
||||
['pdf', 'cas', 'org', 'stran', 'nazev', 'komentar']}),
|
||||
# (u'PDF', {'fields': ['pdf']}),
|
||||
]
|
||||
list_display = ['nazev', 'cas', 'stran', 'org']
|
||||
list_filter = []
|
||||
search_fields = []
|
||||
fieldsets = [
|
||||
(None,
|
||||
{'fields':
|
||||
['pdf', 'cas', 'org', 'stran', 'nazev', 'komentar']}),
|
||||
# (u'PDF', {'fields': ['pdf']}),
|
||||
]
|
||||
list_display = ['nazev', 'cas', 'stran', 'org']
|
||||
list_filter = []
|
||||
search_fields = []
|
||||
|
||||
admin.site.register(KorekturovanePDF, KorekturovanePDFAdmin)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
from django import forms
|
||||
|
||||
class OpravaForm(forms.Form):
|
||||
text = forms.CharField(max_length=256)
|
||||
autor = forms.CharField(max_length=20)
|
||||
x = forms.IntegerField()
|
||||
y = forms.IntegerField()
|
||||
scroll = forms.CharField(max_length=256)
|
||||
pdf = forms.CharField(max_length=256)
|
||||
img_id = forms.CharField(max_length=256)
|
||||
id = forms.CharField(max_length=256)
|
||||
action = forms.CharField(max_length=256)
|
||||
text = forms.CharField(max_length=256)
|
||||
autor = forms.CharField(max_length=20)
|
||||
x = forms.IntegerField()
|
||||
y = forms.IntegerField()
|
||||
scroll = forms.CharField(max_length=256)
|
||||
pdf = forms.CharField(max_length=256)
|
||||
img_id = forms.CharField(max_length=256)
|
||||
id = forms.CharField(max_length=256)
|
||||
action = forms.CharField(max_length=256)
|
||||
|
||||
|
|
|
@ -17,171 +17,171 @@ from unidecode import unidecode
|
|||
|
||||
|
||||
def generate_filename(self, filename):
|
||||
clean = get_valid_filename(
|
||||
unidecode(
|
||||
filename.replace('/', '-').replace('\0', '').replace(":", "_")
|
||||
)
|
||||
)
|
||||
fname = "%s_%s" % (
|
||||
timezone.now().strftime('%Y-%m-%d-%H_%M'),
|
||||
clean)
|
||||
return os.path.join(settings.KOREKTURY_PDF_DIR, fname)
|
||||
clean = get_valid_filename(
|
||||
unidecode(
|
||||
filename.replace('/', '-').replace('\0', '').replace(":", "_")
|
||||
)
|
||||
)
|
||||
fname = "%s_%s" % (
|
||||
timezone.now().strftime('%Y-%m-%d-%H_%M'),
|
||||
clean)
|
||||
return os.path.join(settings.KOREKTURY_PDF_DIR, fname)
|
||||
|
||||
|
||||
#@reversion.register(ignore_duplicates=True)
|
||||
#@python_2_unicode_compatible
|
||||
class KorekturovanePDF(models.Model):
|
||||
class Meta:
|
||||
ordering = ['-cas']
|
||||
db_table = 'korekturovane_cislo'
|
||||
verbose_name = u'PDF k opravám'
|
||||
verbose_name_plural = u'PDF k opravám'
|
||||
|
||||
#Interní ID
|
||||
id = models.AutoField(primary_key = True)
|
||||
class Meta:
|
||||
ordering = ['-cas']
|
||||
db_table = 'korekturovane_cislo'
|
||||
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')
|
||||
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 = True,max_length=50, help_text='Název (např. 22.1 verze 4) korekturovaného PDF')
|
||||
nazev = models.CharField(u'název PDF',blank = True,max_length=50, help_text='Název (např. 22.1 verze 4) 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)')
|
||||
komentar = models.TextField(u'komentář k PDF',blank = True, help_text='Komentář ke korekturovanému PDF (např. na co se zaměřit)')
|
||||
|
||||
pdf = models.FileField(u'PDF', upload_to = generate_filename)
|
||||
pdf = models.FileField(u'PDF', upload_to = generate_filename)
|
||||
|
||||
org = models.ForeignKey(Organizator, blank=True,
|
||||
help_text='Zodpovědný organizátor za obsah',
|
||||
null=True,
|
||||
default=None)
|
||||
org = models.ForeignKey(Organizator, blank=True,
|
||||
help_text='Zodpovědný organizátor za obsah',
|
||||
null=True,
|
||||
default=None)
|
||||
|
||||
stran = models.IntegerField(u'počet stran', help_text='Počet stran PDF',
|
||||
default=0)
|
||||
STATUS_PRIDAVANI = 'pridavani'
|
||||
STATUS_ZANASENI = 'zanaseni'
|
||||
STATUS_ZASTARALE = 'zastarale'
|
||||
STATUS_CHOICES = (
|
||||
(STATUS_PRIDAVANI, u'Přidávání korektur'),
|
||||
(STATUS_ZANASENI, u'Korektury jsou zanášeny'),
|
||||
(STATUS_ZASTARALE, u'Stará verze, nekorigovat'),
|
||||
)
|
||||
status = models.CharField(u'stav PDF',max_length=16, choices=STATUS_CHOICES, blank=False,
|
||||
default = STATUS_PRIDAVANI)
|
||||
|
||||
|
||||
#TODO Nepovinný foreign key k číslu
|
||||
stran = models.IntegerField(u'počet stran', help_text='Počet stran PDF',
|
||||
default=0)
|
||||
STATUS_PRIDAVANI = 'pridavani'
|
||||
STATUS_ZANASENI = 'zanaseni'
|
||||
STATUS_ZASTARALE = 'zastarale'
|
||||
STATUS_CHOICES = (
|
||||
(STATUS_PRIDAVANI, u'Přidávání korektur'),
|
||||
(STATUS_ZANASENI, u'Korektury jsou zanášeny'),
|
||||
(STATUS_ZASTARALE, u'Stará verze, nekorigovat'),
|
||||
)
|
||||
status = models.CharField(u'stav PDF',max_length=16, choices=STATUS_CHOICES, blank=False,
|
||||
default = STATUS_PRIDAVANI)
|
||||
|
||||
def get_prefix(self):
|
||||
"""Vrať řetězec, ke kterému se připojí číslo a .png"""
|
||||
# vrátíme jméno souboru bez cesty
|
||||
return os.path.basename(self.pdf.file.name)
|
||||
|
||||
def convert(self):
|
||||
"""Vytvoří jedno png za každou stranu pdf a uloží se"""
|
||||
dirname = os.path.join(settings.MEDIA_ROOT, settings.KOREKTURY_IMG_DIR)
|
||||
if not os.path.exists(dirname):
|
||||
os.mkdir(dirname)
|
||||
self.stran = 0
|
||||
while True:
|
||||
res = subprocess.call([
|
||||
"convert",
|
||||
"-density", "180x180",
|
||||
"-geometry", " 1024x1448",
|
||||
"%s[%d]" % (self.pdf.path, self.stran),
|
||||
os.path.join(
|
||||
dirname,
|
||||
"%s-%d.png" % (self.get_prefix(), self.stran)
|
||||
)
|
||||
])
|
||||
if res == 1:
|
||||
break
|
||||
self.stran += 1
|
||||
# Změnil se počet stran, ukládáme
|
||||
super(KorekturovanePDF, self).save()
|
||||
#TODO Nepovinný foreign key k číslu
|
||||
|
||||
def save(self):
|
||||
# Pokud se nezmenilo PDF, tak nepregenerovavej nahledy
|
||||
try:
|
||||
original = KorekturovanePDF.objects.get(pk=self.pk)
|
||||
if original.pdf == self.pdf:
|
||||
super(KorekturovanePDF, self).save()
|
||||
return
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
# uložíme nahrávané pdf
|
||||
super(KorekturovanePDF, self).save()
|
||||
def get_prefix(self):
|
||||
"""Vrať řetězec, ke kterému se připojí číslo a .png"""
|
||||
# vrátíme jméno souboru bez cesty
|
||||
return os.path.basename(self.pdf.file.name)
|
||||
|
||||
# uložíme png a změněný počet stran
|
||||
self.convert()
|
||||
def convert(self):
|
||||
"""Vytvoří jedno png za každou stranu pdf a uloží se"""
|
||||
dirname = os.path.join(settings.MEDIA_ROOT, settings.KOREKTURY_IMG_DIR)
|
||||
if not os.path.exists(dirname):
|
||||
os.mkdir(dirname)
|
||||
self.stran = 0
|
||||
while True:
|
||||
res = subprocess.call([
|
||||
"convert",
|
||||
"-density", "180x180",
|
||||
"-geometry", " 1024x1448",
|
||||
"%s[%d]" % (self.pdf.path, self.stran),
|
||||
os.path.join(
|
||||
dirname,
|
||||
"%s-%d.png" % (self.get_prefix(), self.stran)
|
||||
)
|
||||
])
|
||||
if res == 1:
|
||||
break
|
||||
self.stran += 1
|
||||
# Změnil se počet stran, ukládáme
|
||||
super(KorekturovanePDF, self).save()
|
||||
|
||||
def save(self):
|
||||
# Pokud se nezmenilo PDF, tak nepregenerovavej nahledy
|
||||
try:
|
||||
original = KorekturovanePDF.objects.get(pk=self.pk)
|
||||
if original.pdf == self.pdf:
|
||||
super(KorekturovanePDF, self).save()
|
||||
return
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
# uložíme nahrávané pdf
|
||||
super(KorekturovanePDF, self).save()
|
||||
|
||||
# uložíme png a změněný počet stran
|
||||
self.convert()
|
||||
|
||||
@reversion.register(ignore_duplicates=True)
|
||||
@python_2_unicode_compatible
|
||||
class Oprava(models.Model):
|
||||
class Meta:
|
||||
db_table = 'opravy'
|
||||
verbose_name = u'Oprava'
|
||||
verbose_name_plural = u'Opravy'
|
||||
ordering = ['y','x']
|
||||
|
||||
#Interní ID
|
||||
id = models.AutoField(primary_key = True)
|
||||
class Meta:
|
||||
db_table = 'opravy'
|
||||
verbose_name = u'Oprava'
|
||||
verbose_name_plural = u'Opravy'
|
||||
ordering = ['y','x']
|
||||
|
||||
#Interní ID
|
||||
id = models.AutoField(primary_key = True)
|
||||
|
||||
pdf = models.ForeignKey(KorekturovanePDF, default=-1)
|
||||
pdf = models.ForeignKey(KorekturovanePDF, default=-1)
|
||||
|
||||
strana = models.IntegerField(u'strana s opravou', help_text='Strana s opravou (od 0)')
|
||||
strana = models.IntegerField(u'strana s opravou', help_text='Strana s opravou (od 0)')
|
||||
|
||||
x = models.IntegerField(u'x-ová souřadnice bugu')
|
||||
y = models.IntegerField(u'y-ová souřadnice bugu')
|
||||
x = models.IntegerField(u'x-ová souřadnice bugu')
|
||||
y = models.IntegerField(u'y-ová souřadnice bugu')
|
||||
|
||||
STATUS_K_OPRAVE = 'k_oprave'
|
||||
STATUS_OPRAVENO = 'opraveno'
|
||||
STATUS_NENI_CHYBA = 'neni_chyba'
|
||||
STATUS_K_ZANESENI = 'k_zaneseni'
|
||||
STATUS_CHOICES = (
|
||||
(STATUS_K_OPRAVE, u'K opravě'),
|
||||
(STATUS_OPRAVENO, u'Opraveno'),
|
||||
(STATUS_NENI_CHYBA, u'Není chyba'),
|
||||
(STATUS_K_ZANESENI, u'K zanesení do TeXu'),
|
||||
)
|
||||
status = models.CharField(u'stav opravy',max_length=16, choices=STATUS_CHOICES, blank=False,
|
||||
default = STATUS_K_OPRAVE)
|
||||
STATUS_K_OPRAVE = 'k_oprave'
|
||||
STATUS_OPRAVENO = 'opraveno'
|
||||
STATUS_NENI_CHYBA = 'neni_chyba'
|
||||
STATUS_K_ZANESENI = 'k_zaneseni'
|
||||
STATUS_CHOICES = (
|
||||
(STATUS_K_OPRAVE, u'K opravě'),
|
||||
(STATUS_OPRAVENO, u'Opraveno'),
|
||||
(STATUS_NENI_CHYBA, u'Není chyba'),
|
||||
(STATUS_K_ZANESENI, u'K zanesení do TeXu'),
|
||||
)
|
||||
status = models.CharField(u'stav opravy',max_length=16, choices=STATUS_CHOICES, blank=False,
|
||||
default = STATUS_K_OPRAVE)
|
||||
|
||||
autor = models.ForeignKey(Organizator, blank = True,
|
||||
help_text='Autor opravy',
|
||||
null = True)
|
||||
|
||||
text = models.TextField(u'text opravy',blank = True, help_text='Text opravy')
|
||||
autor = models.ForeignKey(Organizator, blank = True,
|
||||
help_text='Autor opravy',
|
||||
null = True)
|
||||
|
||||
text = models.TextField(u'text opravy',blank = True, help_text='Text opravy')
|
||||
|
||||
# def __init__(self,dictionary):
|
||||
# for k,v in dictionary.items():
|
||||
# setattr(self,k,v)
|
||||
# def __init__(self,dictionary):
|
||||
# for k,v in dictionary.items():
|
||||
# setattr(self,k,v)
|
||||
|
||||
def __str__(self):
|
||||
return force_unicode(u'%s od %s: %s'%(self.status,self.autor,self.text))
|
||||
def __str__(self):
|
||||
return force_unicode(u'%s od %s: %s'%(self.status,self.autor,self.text))
|
||||
|
||||
|
||||
|
||||
@reversion.register(ignore_duplicates=True)
|
||||
@python_2_unicode_compatible
|
||||
class Komentar(models.Model):
|
||||
class Meta:
|
||||
db_table = 'komentare'
|
||||
verbose_name = u'Komentář k opravě'
|
||||
verbose_name_plural = u'Komentáře k opravě'
|
||||
ordering = ['cas']
|
||||
|
||||
#Interní ID
|
||||
id = models.AutoField(primary_key = True)
|
||||
class Meta:
|
||||
db_table = 'komentare'
|
||||
verbose_name = u'Komentář k opravě'
|
||||
verbose_name_plural = u'Komentáře k opravě'
|
||||
ordering = ['cas']
|
||||
|
||||
#Interní ID
|
||||
id = models.AutoField(primary_key = True)
|
||||
|
||||
cas = models.DateTimeField(u'čas komentáře',default=timezone.now,help_text = 'Čas zadání komentáře')
|
||||
cas = models.DateTimeField(u'čas komentáře',default=timezone.now,help_text = 'Čas zadání komentáře')
|
||||
|
||||
oprava = models.ForeignKey(Oprava)
|
||||
autor = models.ForeignKey(Organizator, blank = True,
|
||||
help_text = u'Autor komentáře',
|
||||
null = True)
|
||||
|
||||
text = models.TextField(u'text komentáře',blank = True, help_text='Text komentáře')
|
||||
oprava = models.ForeignKey(Oprava)
|
||||
autor = models.ForeignKey(Organizator, blank = True,
|
||||
help_text = u'Autor komentáře',
|
||||
null = True)
|
||||
|
||||
text = models.TextField(u'text komentáře',blank = True, help_text='Text komentáře')
|
||||
|
||||
def __str__(self):
|
||||
return force_unicode(u'%s od %s: %s'%(self.cas,self.autor,self.text))
|
||||
def __str__(self):
|
||||
return force_unicode(u'%s od %s: %s'%(self.cas,self.autor,self.text))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from . import views
|
|||
staff_member_required = user_passes_test(lambda u: u.is_staff)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^korektury/$', staff_member_required(views.KorekturyListView.as_view()), name='korektury-list'),
|
||||
url(r'^korektury/(?P<pdf>\d+)/$', staff_member_required(views.KorekturyView.as_view()), name='korektury'),
|
||||
url(r'^korektury/help/', staff_member_required(views.KorekturyHelpView.as_view()), name='korektury-help'),
|
||||
url(r'^korektury/$', staff_member_required(views.KorekturyListView.as_view()), name='korektury-list'),
|
||||
url(r'^korektury/(?P<pdf>\d+)/$', staff_member_required(views.KorekturyView.as_view()), name='korektury'),
|
||||
url(r'^korektury/help/', staff_member_required(views.KorekturyHelpView.as_view()), name='korektury-help'),
|
||||
]
|
||||
|
|
|
@ -15,186 +15,186 @@ import os
|
|||
import unicodedata
|
||||
|
||||
class KorekturyHelpView(generic.TemplateView):
|
||||
template_name = 'korektury/help.html'
|
||||
template_name = 'korektury/help.html'
|
||||
|
||||
class KorekturyListView(generic.ListView):
|
||||
model = KorekturovanePDF
|
||||
template_name = 'korektury/seznam.html'
|
||||
model = KorekturovanePDF
|
||||
template_name = 'korektury/seznam.html'
|
||||
|
||||
### Korektury
|
||||
class KorekturyView(generic.TemplateView):
|
||||
model = Oprava
|
||||
template_name = 'korektury/opraf.html'
|
||||
form_class = OpravaForm
|
||||
model = Oprava
|
||||
template_name = 'korektury/opraf.html'
|
||||
form_class = OpravaForm
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
form = self.form_class(request.POST)
|
||||
q = request.POST
|
||||
scroll = q.get('scroll')
|
||||
def post(self, request, *args, **kwargs):
|
||||
form = self.form_class(request.POST)
|
||||
q = request.POST
|
||||
scroll = q.get('scroll')
|
||||
|
||||
# prirazeni autora podle prihlaseni
|
||||
autor_user = request.user
|
||||
# pokud existuje ucet (user), ale neni to organizator = 403
|
||||
autor = Organizator.objects.filter(user=autor_user).first()
|
||||
if not autor:
|
||||
return HttpResponseForbidden()
|
||||
# prirazeni autora podle prihlaseni
|
||||
autor_user = request.user
|
||||
# pokud existuje ucet (user), ale neni to organizator = 403
|
||||
autor = Organizator.objects.filter(user=autor_user).first()
|
||||
if not autor:
|
||||
return HttpResponseForbidden()
|
||||
|
||||
if not scroll:
|
||||
scroll = 0
|
||||
if not scroll:
|
||||
scroll = 0
|
||||
|
||||
action = q.get('action')
|
||||
if (action == ''): # Přidej
|
||||
x = int(q.get('x'))
|
||||
y = int(q.get('y'))
|
||||
text = q.get('txt')
|
||||
strana = int(q.get('img-id')[4:])
|
||||
pdf = KorekturovanePDF.objects.get(id=q.get('pdf'))
|
||||
action = q.get('action')
|
||||
if (action == ''): # Přidej
|
||||
x = int(q.get('x'))
|
||||
y = int(q.get('y'))
|
||||
text = q.get('txt')
|
||||
strana = int(q.get('img-id')[4:])
|
||||
pdf = KorekturovanePDF.objects.get(id=q.get('pdf'))
|
||||
|
||||
op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana,pdf = pdf)
|
||||
op.save()
|
||||
self.send_email_notification_komentar(op, autor, text)
|
||||
elif (action == 'del'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.delete()
|
||||
elif (action == 'update'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
text = q.get('txt')
|
||||
op.autor = autor
|
||||
op.text = text
|
||||
op.save()
|
||||
elif (action == 'undone'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.status = op.STATUS_K_OPRAVE
|
||||
op.save()
|
||||
elif (action == 'done'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.status = op.STATUS_OPRAVENO
|
||||
op.save()
|
||||
elif (action == 'ready'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.status = op.STATUS_K_ZANESENI
|
||||
op.save()
|
||||
elif (action == 'wontfix'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.status = op.STATUS_NENI_CHYBA
|
||||
op.save()
|
||||
elif (action == 'comment'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
text = q.get('txt')
|
||||
kom = Komentar(oprava=op,autor=autor,text=text)
|
||||
kom.save()
|
||||
self.send_email_notification_komentar(op, autor, text)
|
||||
elif (action == 'update-comment'):
|
||||
id = int(q.get('id'))
|
||||
kom = Komentar.objects.get(id=id)
|
||||
text = q.get('txt')
|
||||
kom.text = text
|
||||
kom.autor = autor
|
||||
kom.save()
|
||||
elif (action == 'del-comment'):
|
||||
id = int(q.get('id'))
|
||||
kom = Komentar.objects.get(id=id)
|
||||
kom.delete()
|
||||
elif (action == 'set-state'):
|
||||
pdf = KorekturovanePDF.objects.get(id=q.get('pdf'))
|
||||
if (q.get('state') == 'adding'):
|
||||
pdf.status = pdf.STATUS_PRIDAVANI
|
||||
elif (q.get('state') == 'comitting'):
|
||||
pdf.status = pdf.STATUS_ZANASENI
|
||||
elif (q.get('state') == 'deprecated'):
|
||||
pdf.status = pdf.STATUS_ZASTARALE
|
||||
pdf.save()
|
||||
context = self.get_context_data()
|
||||
context['scroll'] = scroll
|
||||
context['autor'] = autor
|
||||
return render(request, 'korektury/opraf.html',context)
|
||||
op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana,pdf = pdf)
|
||||
op.save()
|
||||
self.send_email_notification_komentar(op, autor, text)
|
||||
elif (action == 'del'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.delete()
|
||||
elif (action == 'update'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
text = q.get('txt')
|
||||
op.autor = autor
|
||||
op.text = text
|
||||
op.save()
|
||||
elif (action == 'undone'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.status = op.STATUS_K_OPRAVE
|
||||
op.save()
|
||||
elif (action == 'done'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.status = op.STATUS_OPRAVENO
|
||||
op.save()
|
||||
elif (action == 'ready'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.status = op.STATUS_K_ZANESENI
|
||||
op.save()
|
||||
elif (action == 'wontfix'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
op.status = op.STATUS_NENI_CHYBA
|
||||
op.save()
|
||||
elif (action == 'comment'):
|
||||
id = int(q.get('id'))
|
||||
op = Oprava.objects.get(id=id)
|
||||
text = q.get('txt')
|
||||
kom = Komentar(oprava=op,autor=autor,text=text)
|
||||
kom.save()
|
||||
self.send_email_notification_komentar(op, autor, text)
|
||||
elif (action == 'update-comment'):
|
||||
id = int(q.get('id'))
|
||||
kom = Komentar.objects.get(id=id)
|
||||
text = q.get('txt')
|
||||
kom.text = text
|
||||
kom.autor = autor
|
||||
kom.save()
|
||||
elif (action == 'del-comment'):
|
||||
id = int(q.get('id'))
|
||||
kom = Komentar.objects.get(id=id)
|
||||
kom.delete()
|
||||
elif (action == 'set-state'):
|
||||
pdf = KorekturovanePDF.objects.get(id=q.get('pdf'))
|
||||
if (q.get('state') == 'adding'):
|
||||
pdf.status = pdf.STATUS_PRIDAVANI
|
||||
elif (q.get('state') == 'comitting'):
|
||||
pdf.status = pdf.STATUS_ZANASENI
|
||||
elif (q.get('state') == 'deprecated'):
|
||||
pdf.status = pdf.STATUS_ZASTARALE
|
||||
pdf.save()
|
||||
context = self.get_context_data()
|
||||
context['scroll'] = scroll
|
||||
context['autor'] = autor
|
||||
return render(request, 'korektury/opraf.html',context)
|
||||
|
||||
def send_email_notification_komentar(self, oprava, autor, text):
|
||||
''' Rozesle e-mail pri pridani komentare,
|
||||
ktery obsahuje text komentare.
|
||||
'''
|
||||
def send_email_notification_komentar(self, oprava, autor, text):
|
||||
''' Rozesle e-mail pri pridani komentare,
|
||||
ktery obsahuje text komentare.
|
||||
'''
|
||||
|
||||
# parametry e-mailu
|
||||
odkaz = "https://mam.mff.cuni.cz/korektury/{}/".format(oprava.pdf.pk)
|
||||
from_email = 'korekturovatko@mam.mff.cuni.cz'
|
||||
subject = 'Nová korektura od {} v {}'.format(autor,
|
||||
oprava.pdf.nazev)
|
||||
text = u"Text komentáře:\n\n{}\n\n=== Konec textu komentáře ===\n\
|
||||
\nodkaz do korekturovátka: {}\n\
|
||||
\nVaše korekturovátko\n".format(text, odkaz)
|
||||
# parametry e-mailu
|
||||
odkaz = "https://mam.mff.cuni.cz/korektury/{}/".format(oprava.pdf.pk)
|
||||
from_email = 'korekturovatko@mam.mff.cuni.cz'
|
||||
subject = 'Nová korektura od {} v {}'.format(autor,
|
||||
oprava.pdf.nazev)
|
||||
text = u"Text komentáře:\n\n{}\n\n=== Konec textu komentáře ===\n\
|
||||
\nodkaz do korekturovátka: {}\n\
|
||||
\nVaše korekturovátko\n".format(text, odkaz)
|
||||
|
||||
# Prijemci e-mailu
|
||||
emails = set()
|
||||
# e-mail autora korektury
|
||||
email = oprava.autor.user.email
|
||||
if email:
|
||||
emails.add(email)
|
||||
# Prijemci e-mailu
|
||||
emails = set()
|
||||
# e-mail autora korektury
|
||||
email = oprava.autor.user.email
|
||||
if email:
|
||||
emails.add(email)
|
||||
|
||||
# nalezeni e-mailu na autory komentaru
|
||||
for komentar in oprava.komentar_set.all():
|
||||
email_komentujiciho = komentar.autor.user.email
|
||||
if email_komentujiciho:
|
||||
emails.add(email_komentujiciho)
|
||||
# nalezeni e-mailu na autory komentaru
|
||||
for komentar in oprava.komentar_set.all():
|
||||
email_komentujiciho = komentar.autor.user.email
|
||||
if email_komentujiciho:
|
||||
emails.add(email_komentujiciho)
|
||||
|
||||
# zodpovedny org
|
||||
if oprava.pdf.org:
|
||||
email_zobpovedny = oprava.pdf.org.user.email
|
||||
if email_zobpovedny:
|
||||
emails.add(email_zobpovedny)
|
||||
# zodpovedny org
|
||||
if oprava.pdf.org:
|
||||
email_zobpovedny = oprava.pdf.org.user.email
|
||||
if email_zobpovedny:
|
||||
emails.add(email_zobpovedny)
|
||||
|
||||
# odstran e-mail autora opravy
|
||||
email = autor.user.email
|
||||
if email:
|
||||
emails.discard(email)
|
||||
# odstran e-mail autora opravy
|
||||
email = autor.user.email
|
||||
if email:
|
||||
emails.discard(email)
|
||||
|
||||
if not settings.SEND_EMAIL_NOTIFICATIONS:
|
||||
print("Poslal bych upozornění na tyto adresy: ", " ".join(emails))
|
||||
return
|
||||
if not settings.SEND_EMAIL_NOTIFICATIONS:
|
||||
print("Poslal bych upozornění na tyto adresy: ", " ".join(emails))
|
||||
return
|
||||
|
||||
send_mail(subject, text, from_email, list(emails))
|
||||
send_mail(subject, text, from_email, list(emails))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(KorekturyView,self).get_context_data(**kwargs)
|
||||
pdf = get_object_or_404(KorekturovanePDF, id=self.kwargs['pdf'])
|
||||
context['pdf'] = pdf
|
||||
context['img_prefix'] = pdf.get_prefix()
|
||||
context['img_path'] = settings.KOREKTURY_IMG_DIR
|
||||
context['img_indexes'] = range(pdf.stran)
|
||||
context['form_oprava'] = OpravaForm()
|
||||
opravy = Oprava.objects.filter(pdf=self.kwargs['pdf'])
|
||||
zasluhy = {}
|
||||
for o in opravy:
|
||||
if o.autor in zasluhy:
|
||||
zasluhy[o.autor]+=1
|
||||
else:
|
||||
zasluhy[o.autor]=1
|
||||
o.komentare = o.komentar_set.all()
|
||||
for k in o.komentare:
|
||||
if k.autor in zasluhy:
|
||||
zasluhy[k.autor] += 1
|
||||
else:
|
||||
zasluhy[k.autor] = 1
|
||||
zasluhy = [
|
||||
{'autor': jmeno, 'pocet': pocet}
|
||||
for (jmeno, pocet) in zasluhy.items()
|
||||
]
|
||||
zasluhy.sort(key=lambda z: z['pocet'], reverse=True)
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(KorekturyView,self).get_context_data(**kwargs)
|
||||
pdf = get_object_or_404(KorekturovanePDF, id=self.kwargs['pdf'])
|
||||
context['pdf'] = pdf
|
||||
context['img_prefix'] = pdf.get_prefix()
|
||||
context['img_path'] = settings.KOREKTURY_IMG_DIR
|
||||
context['img_indexes'] = range(pdf.stran)
|
||||
context['form_oprava'] = OpravaForm()
|
||||
opravy = Oprava.objects.filter(pdf=self.kwargs['pdf'])
|
||||
zasluhy = {}
|
||||
for o in opravy:
|
||||
if o.autor in zasluhy:
|
||||
zasluhy[o.autor]+=1
|
||||
else:
|
||||
zasluhy[o.autor]=1
|
||||
o.komentare = o.komentar_set.all()
|
||||
for k in o.komentare:
|
||||
if k.autor in zasluhy:
|
||||
zasluhy[k.autor] += 1
|
||||
else:
|
||||
zasluhy[k.autor] = 1
|
||||
zasluhy = [
|
||||
{'autor': jmeno, 'pocet': pocet}
|
||||
for (jmeno, pocet) in zasluhy.items()
|
||||
]
|
||||
zasluhy.sort(key=lambda z: z['pocet'], reverse=True)
|
||||
|
||||
strany = set(o.strana for o in opravy)
|
||||
opravy_na_stranu = [{'strana': s, 'op_id': opravy.filter(strana=s)} for s in strany]
|
||||
context['opravy_strany'] = opravy_na_stranu
|
||||
|
||||
context['opravy'] = opravy
|
||||
context['zasluhy'] = zasluhy
|
||||
return context
|
||||
strany = set(o.strana for o in opravy)
|
||||
opravy_na_stranu = [{'strana': s, 'op_id': opravy.filter(strana=s)} for s in strany]
|
||||
context['opravy_strany'] = opravy_na_stranu
|
||||
|
||||
context['opravy'] = opravy
|
||||
context['zasluhy'] = zasluhy
|
||||
return context
|
||||
|
||||
def form_valid(self,form):
|
||||
return super(KorekturyView,self).form_valid(form)
|
||||
def form_valid(self,form):
|
||||
return super(KorekturyView,self).form_valid(form)
|
||||
|
||||
|
|
|
@ -10,91 +10,91 @@ from seminar.models import Soustredeni
|
|||
|
||||
|
||||
class Seznam_PrednaskaInline(admin.TabularInline):
|
||||
model = Prednaska.seznamy.through
|
||||
extra = 0
|
||||
model = Prednaska.seznamy.through
|
||||
extra = 0
|
||||
|
||||
def prednaska__nazev(self, obj):
|
||||
return mark_safe(
|
||||
u"<a href='/admin/prednasky/prednaska/{}'>{}</a>".format(
|
||||
obj.prednaska.id,
|
||||
escape(obj.prednaska.nazev)
|
||||
)
|
||||
)
|
||||
def prednaska__nazev(self, obj):
|
||||
return mark_safe(
|
||||
u"<a href='/admin/prednasky/prednaska/{}'>{}</a>".format(
|
||||
obj.prednaska.id,
|
||||
escape(obj.prednaska.nazev)
|
||||
)
|
||||
)
|
||||
|
||||
def prednaska__popis(self, obj):
|
||||
return mark_safe(
|
||||
u"<div style='width: 200px'>{}</div>".format(
|
||||
escape(obj.prednaska.popis)
|
||||
)
|
||||
)
|
||||
def prednaska__popis(self, obj):
|
||||
return mark_safe(
|
||||
u"<div style='width: 200px'>{}</div>".format(
|
||||
escape(obj.prednaska.popis)
|
||||
)
|
||||
)
|
||||
|
||||
def prednaska__anotace(self, obj):
|
||||
return obj.prednaska.anotace
|
||||
def prednaska__anotace(self, obj):
|
||||
return obj.prednaska.anotace
|
||||
|
||||
def prednaska__org(self, obj):
|
||||
return obj.prednaska.org
|
||||
def prednaska__org(self, obj):
|
||||
return obj.prednaska.org
|
||||
|
||||
def prednaska__obor(self, obj):
|
||||
return obj.prednaska.obor
|
||||
def prednaska__obor(self, obj):
|
||||
return obj.prednaska.obor
|
||||
|
||||
prednaska__nazev.short_description = u'Přednáška'
|
||||
prednaska__popis.short_description = u'Popis pro orgy'
|
||||
prednaska__anotace.short_description = u'Anotace'
|
||||
prednaska__org.short_description = u'Org'
|
||||
prednaska__obor.short_description = u'Obor'
|
||||
prednaska__nazev.short_description = u'Přednáška'
|
||||
prednaska__popis.short_description = u'Popis pro orgy'
|
||||
prednaska__anotace.short_description = u'Anotace'
|
||||
prednaska__org.short_description = u'Org'
|
||||
prednaska__obor.short_description = u'Obor'
|
||||
|
||||
readonly_fields = [
|
||||
'prednaska__nazev',
|
||||
'prednaska__obor',
|
||||
'prednaska__org',
|
||||
'prednaska__popis',
|
||||
'prednaska__anotace',
|
||||
]
|
||||
exclude = ['prednaska']
|
||||
readonly_fields = [
|
||||
'prednaska__nazev',
|
||||
'prednaska__obor',
|
||||
'prednaska__org',
|
||||
'prednaska__popis',
|
||||
'prednaska__anotace',
|
||||
]
|
||||
exclude = ['prednaska']
|
||||
|
||||
def has_add_permission(self, req): return False
|
||||
def has_add_permission(self, req): return False
|
||||
|
||||
|
||||
class SeznamAdmin(VersionAdmin):
|
||||
list_display = ['soustredeni', 'stav']
|
||||
inlines = [Seznam_PrednaskaInline]
|
||||
list_display = ['soustredeni', 'stav']
|
||||
inlines = [Seznam_PrednaskaInline]
|
||||
|
||||
admin.site.register(Seznam, SeznamAdmin)
|
||||
|
||||
|
||||
class PrednaskaAdmin(VersionAdmin):
|
||||
list_display = ['nazev', 'org', 'obor']
|
||||
list_filter = ['org', 'obor']
|
||||
search_fields = []
|
||||
filter_horizontal = ('seznamy', )
|
||||
list_display = ['nazev', 'org', 'obor']
|
||||
list_filter = ['org', 'obor']
|
||||
search_fields = []
|
||||
filter_horizontal = ('seznamy', )
|
||||
|
||||
actions = ['move_to_soustredeni']
|
||||
actions = ['move_to_soustredeni']
|
||||
|
||||
def move_to_soustredeni(self, request, queryset):
|
||||
sous = Soustredeni.objects.first()
|
||||
seznam = Seznam.objects.filter(soustredeni=sous, stav=STAV_NAVRH)
|
||||
if len(seznam) == 0:
|
||||
self.message_user(
|
||||
request,
|
||||
u"Není definován seznam pro aktuální soustředění, "
|
||||
u"nic se neprovedlo",
|
||||
messages.ERROR
|
||||
)
|
||||
return
|
||||
seznam = seznam[0]
|
||||
for prednaska in queryset:
|
||||
prednaska.seznamy.add(seznam)
|
||||
prednaska.save()
|
||||
def move_to_soustredeni(self, request, queryset):
|
||||
sous = Soustredeni.objects.first()
|
||||
seznam = Seznam.objects.filter(soustredeni=sous, stav=STAV_NAVRH)
|
||||
if len(seznam) == 0:
|
||||
self.message_user(
|
||||
request,
|
||||
u"Není definován seznam pro aktuální soustředění, "
|
||||
u"nic se neprovedlo",
|
||||
messages.ERROR
|
||||
)
|
||||
return
|
||||
seznam = seznam[0]
|
||||
for prednaska in queryset:
|
||||
prednaska.seznamy.add(seznam)
|
||||
prednaska.save()
|
||||
|
||||
self.message_user(
|
||||
request,
|
||||
u"Vybrané přednášky ({}) přidány jako návrhy na nejbližší "
|
||||
u"soustředění".format(len(queryset))
|
||||
)
|
||||
self.message_user(
|
||||
request,
|
||||
u"Vybrané přednášky ({}) přidány jako návrhy na nejbližší "
|
||||
u"soustředění".format(len(queryset))
|
||||
)
|
||||
|
||||
move_to_soustredeni.short_description = (
|
||||
u"Přidat přednášky do návrhu na nejbližší soustředění"
|
||||
)
|
||||
move_to_soustredeni.short_description = (
|
||||
u"Přidat přednášky do návrhu na nejbližší soustředění"
|
||||
)
|
||||
|
||||
|
||||
admin.site.register(Prednaska, PrednaskaAdmin)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
from django import forms
|
||||
|
||||
class NewPrednaskyForm(forms.Form):
|
||||
ucastnik = forms.CharField(label = 'Tvoje jméno', max_length = 100)
|
||||
ucastnik = forms.CharField(label = 'Tvoje jméno', max_length = 100)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -29,15 +29,15 @@ class Seznam(models.Model):
|
|||
stav = models.IntegerField('Stav',choices=STAV_CHOICES,default = STAV_NAVRH)
|
||||
|
||||
def __str__(self):
|
||||
return force_unicode("Seznam {}přednášek na {}".format("návrhů "
|
||||
if self.stav == STAV_NAVRH else "", self.soustredeni))
|
||||
return force_unicode("Seznam {}přednášek na {}".format("návrhů "
|
||||
if self.stav == STAV_NAVRH else "", self.soustredeni))
|
||||
|
||||
|
||||
CHOICES_OBTIZNOST = (
|
||||
(1, 'Lehká'),
|
||||
(2, 'Střední'),
|
||||
(3, 'Těžká'),
|
||||
)
|
||||
(1, 'Lehká'),
|
||||
(2, 'Střední'),
|
||||
(3, 'Těžká'),
|
||||
)
|
||||
|
||||
CHOICES_BODY = (
|
||||
(-1, '-1'),
|
||||
|
@ -82,5 +82,5 @@ class Hlasovani(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return force_unicode("{} dal {} bodů {} v seznamu {}".format(self.ucastnik,
|
||||
self.body, self.prednaska, self.seznam))
|
||||
self.body, self.prednaska, self.seznam))
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ from . import views
|
|||
staff_member_required = user_passes_test(lambda u: u.is_staff)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^prednasky/$', views.newPrednaska),
|
||||
url(r'^prednasky/hotovo$', views.Prednaska_hotovo),
|
||||
url(r'^prednasky/metaseznam_prednasek$', staff_member_required(views.MetaSeznamListView.as_view()), name='metaseznam-list'),
|
||||
url(r'^prednasky/seznam_prednasek/(?P<seznam>\d+)/$', staff_member_required(views.SeznamListView.as_view()), name='seznam-list'),
|
||||
url(r'^prednasky/seznam_prednasek/(?P<seznam>\d+)/export$', staff_member_required(views.SeznamExportView), name='seznam-export'),
|
||||
# url(r'^korektury/help/', staff_member_required(views.KorekturyHelpView.as_view()), name='korektury-help'),
|
||||
url(r'^prednasky/$', views.newPrednaska),
|
||||
url(r'^prednasky/hotovo$', views.Prednaska_hotovo),
|
||||
url(r'^prednasky/metaseznam_prednasek$', staff_member_required(views.MetaSeznamListView.as_view()), name='metaseznam-list'),
|
||||
url(r'^prednasky/seznam_prednasek/(?P<seznam>\d+)/$', staff_member_required(views.SeznamListView.as_view()), name='seznam-list'),
|
||||
url(r'^prednasky/seznam_prednasek/(?P<seznam>\d+)/export$', staff_member_required(views.SeznamExportView), name='seznam-export'),
|
||||
# url(r'^korektury/help/', staff_member_required(views.KorekturyHelpView.as_view()), name='korektury-help'),
|
||||
]
|
||||
|
|
|
@ -10,83 +10,83 @@ from seminar.models import Soustredeni
|
|||
from prednasky.forms import NewPrednaskyForm
|
||||
|
||||
def newPrednaska(request):
|
||||
# hlasovani se vztahuje k nejnovejsimu soustredeni
|
||||
sous = Soustredeni.objects.first()
|
||||
seznam = Seznam.objects.filter(soustredeni = sous, stav = STAV_NAVRH).first()
|
||||
print(seznam)
|
||||
# obsluha formulare
|
||||
if request.method == 'POST':
|
||||
form = NewPrednaskyForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
jmeno = form.cleaned_data['ucastnik']
|
||||
for i in request.POST:
|
||||
if i[0] == 'q':
|
||||
hlasovani = Hlasovani()
|
||||
print("q:"+i[1:])
|
||||
hlasovani.prednaska = Prednaska.objects.filter(pk = int(i[1:]))[0]
|
||||
hlasovani.body = int(request.POST[i])
|
||||
hlasovani.ucastnik = jmeno
|
||||
hlasovani.seznam = seznam
|
||||
hlasovani.save()
|
||||
# hlasovani se vztahuje k nejnovejsimu soustredeni
|
||||
sous = Soustredeni.objects.first()
|
||||
seznam = Seznam.objects.filter(soustredeni = sous, stav = STAV_NAVRH).first()
|
||||
print(seznam)
|
||||
# obsluha formulare
|
||||
if request.method == 'POST':
|
||||
form = NewPrednaskyForm(request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
jmeno = form.cleaned_data['ucastnik']
|
||||
for i in request.POST:
|
||||
if i[0] == 'q':
|
||||
hlasovani = Hlasovani()
|
||||
print("q:"+i[1:])
|
||||
hlasovani.prednaska = Prednaska.objects.filter(pk = int(i[1:]))[0]
|
||||
hlasovani.body = int(request.POST[i])
|
||||
hlasovani.ucastnik = jmeno
|
||||
hlasovani.seznam = seznam
|
||||
hlasovani.save()
|
||||
|
||||
# presmerovani na prave vzniklou galerii
|
||||
return HttpResponseRedirect('./hotovo')
|
||||
# presmerovani na prave vzniklou galerii
|
||||
return HttpResponseRedirect('./hotovo')
|
||||
|
||||
else:
|
||||
form = NewPrednaskyForm()
|
||||
else:
|
||||
form = NewPrednaskyForm()
|
||||
|
||||
return render(
|
||||
request,
|
||||
'prednasky/base.html',
|
||||
{'form': form, 'prednasky': seznam}
|
||||
)
|
||||
return render(
|
||||
request,
|
||||
'prednasky/base.html',
|
||||
{'form': form, 'prednasky': seznam}
|
||||
)
|
||||
|
||||
|
||||
def Prednaska_hotovo(request):
|
||||
return render(request, 'prednasky/hotovo.html')
|
||||
return render(request, 'prednasky/hotovo.html')
|
||||
|
||||
class MetaSeznamListView(generic.ListView):
|
||||
model = Seznam
|
||||
template_name = 'prednasky/metaseznam_prednasek.html'
|
||||
model = Seznam
|
||||
template_name = 'prednasky/metaseznam_prednasek.html'
|
||||
|
||||
|
||||
class SeznamListView(generic.ListView):
|
||||
template_name = 'prednasky/seznam_prednasek.html'
|
||||
template_name = 'prednasky/seznam_prednasek.html'
|
||||
|
||||
def get_queryset(self):
|
||||
self.seznam = get_object_or_404(Seznam, id=self.kwargs["seznam"])
|
||||
prednasky = Prednaska.objects.filter(seznamy=self.seznam).order_by(
|
||||
'org__user__first_name', 'org__user__last_name'
|
||||
).annotate(body=Sum('hlasovani__body'))
|
||||
return prednasky
|
||||
def get_queryset(self):
|
||||
self.seznam = get_object_or_404(Seznam, id=self.kwargs["seznam"])
|
||||
prednasky = Prednaska.objects.filter(seznamy=self.seznam).order_by(
|
||||
'org__user__first_name', 'org__user__last_name'
|
||||
).annotate(body=Sum('hlasovani__body'))
|
||||
return prednasky
|
||||
|
||||
|
||||
def SeznamExportView(request, seznam):
|
||||
u"""Vypíše výsledky hlasování ve formátu pro prologovský optimalizátor"""
|
||||
# TODO zřejmě se nepoužívá, časem vyřadit? nahradit tabulkou vhodnější pro
|
||||
# lidi?
|
||||
hlasovani = Hlasovani.objects.filter(seznam=seznam)
|
||||
prednasky = Prednaska.objects.filter(seznamy=seznam)
|
||||
orgove = set(p.org for p in prednasky)
|
||||
ucastnici = set(h.ucastnik for h in hlasovani)
|
||||
u"""Vypíše výsledky hlasování ve formátu pro prologovský optimalizátor"""
|
||||
# TODO zřejmě se nepoužívá, časem vyřadit? nahradit tabulkou vhodnější pro
|
||||
# lidi?
|
||||
hlasovani = Hlasovani.objects.filter(seznam=seznam)
|
||||
prednasky = Prednaska.objects.filter(seznamy=seznam)
|
||||
orgove = set(p.org for p in prednasky)
|
||||
ucastnici = set(h.ucastnik for h in hlasovani)
|
||||
|
||||
for p in prednasky:
|
||||
p.body = []
|
||||
for u in ucastnici:
|
||||
try:
|
||||
p.body.append(hlasovani.get(ucastnik=u, prednaska=p).body)
|
||||
except ObjectDoesNotExist:
|
||||
# účastník nehlasoval
|
||||
p.body.append("?")
|
||||
for p in prednasky:
|
||||
p.body = []
|
||||
for u in ucastnici:
|
||||
try:
|
||||
p.body.append(hlasovani.get(ucastnik=u, prednaska=p).body)
|
||||
except ObjectDoesNotExist:
|
||||
# účastník nehlasoval
|
||||
p.body.append("?")
|
||||
|
||||
for h in hlasovani:
|
||||
h.ucastnik = hash(h.ucastnik)
|
||||
for h in hlasovani:
|
||||
h.ucastnik = hash(h.ucastnik)
|
||||
|
||||
return render(
|
||||
request,
|
||||
'prednasky/seznam_prednasek_export.txt',
|
||||
{"hlasovani": hlasovani, "prednasky": prednasky, "orgove": orgove},
|
||||
content_type="text/plain"
|
||||
)
|
||||
return render(
|
||||
request,
|
||||
'prednasky/seznam_prednasek_export.txt',
|
||||
{"hlasovani": hlasovani, "prednasky": prednasky, "orgove": orgove},
|
||||
content_type="text/plain"
|
||||
)
|
||||
|
||||
|
||||
|
|
916
seminar/admin.py
916
seminar/admin.py
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
from django import forms
|
||||
|
||||
class NameForm(forms.Form):
|
||||
your_name = forms.CharField(label='Your name', max_length=100)
|
||||
your_name = forms.CharField(label='Your name', max_length=100)
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ User = django.contrib.auth.get_user_model()
|
|||
class Command(BaseCommand):
|
||||
help = "Clear database and load testing data."
|
||||
|
||||
def handle(self, **options):
|
||||
def handle(self, *args, **options):
|
||||
assert settings.DEBUG == True
|
||||
dbfile = settings.DATABASES['default']['NAME']
|
||||
if os.path.exists(dbfile):
|
||||
|
@ -26,9 +26,10 @@ class Command(BaseCommand):
|
|||
call_command('migrate', noinput=True)
|
||||
self.stdout.write('Vytvarim uzivatele "admin" (heslo "admin") a pseudo-nahodna data ...')
|
||||
create_test_data(size=8)
|
||||
self.stdout.write('Vytvoreno %d uzivatelu, %d skol, %d resitelu, %d rocniku, %d cisel, %d problemu, %d reseni.' %
|
||||
(User.objects.count(), Skola.objects.count(), Resitel.objects.count(), Rocnik.objects.count(),
|
||||
Cislo.objects.count(), Problem.objects.count(), Reseni.objects.count()))
|
||||
self.stdout.write('Vytvoreno %d uzivatelu, %d skol, %d resitelu, %d rocniku, %d cisel,'
|
||||
' %d problemu, %d reseni.'.format(User.objects.count(), Skola.objects.count(),
|
||||
Resitel.objects.count(), Rocnik.objects.count(), Cislo.objects.count(),
|
||||
Problem.objects.count(), Reseni.objects.count()))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class Migration(migrations.Migration):
|
|||
('datum', models.DateField(auto_now_add=True)),
|
||||
('text', models.TextField(null=True, verbose_name=b'Text novinky', blank=True)),
|
||||
('obrazek', models.ImageField(upload_to=b'image_novinky/%Y/%m/%d/', null=True, verbose_name=b'Obr\xc3\xa1zek', blank=True)),
|
||||
('zverejneno', models.BooleanField(default=b'False', verbose_name=b'Zve\xc5\x99ejn\xc4\x9bno')),
|
||||
('zverejneno', models.BooleanField(default=False, verbose_name=b'Zve\xc5\x99ejn\xc4\x9bno')),
|
||||
('autor', models.ForeignKey(verbose_name=b'Autor novinky', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
|
|
|
@ -289,7 +289,7 @@ class Migration(migrations.Migration):
|
|||
migrations.AlterField(
|
||||
model_name='novinky',
|
||||
name='zverejneno',
|
||||
field=models.BooleanField(default='False', verbose_name='Zveřejněno'),
|
||||
field=models.BooleanField(default=False, verbose_name='Zveřejněno'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='organizator',
|
||||
|
|
|
@ -64,7 +64,8 @@ class Osoba(SeminarModelBase):
|
|||
prezdivka = models.CharField('přezdívka', max_length=256)
|
||||
|
||||
# User, pokud má na webu účet
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, blank=True, null=True, verbose_name='uživatel')
|
||||
user = models.OneToOneField(settings.AUTH_USER_MODEL, blank=True, null=True,
|
||||
verbose_name='uživatel')
|
||||
|
||||
# Pohlaví. Že ho neznáme se snad nestane (a ušetří to práci při programování)
|
||||
pohlavi_muz = models.BooleanField('pohlaví (muž)', default=False)
|
||||
|
@ -119,7 +120,8 @@ class Osoba(SeminarModelBase):
|
|||
return force_unicode('%s %s' % (self.jmeno, self.prijmeni))
|
||||
|
||||
def inicial_krestni(self):
|
||||
return force_unicode('%s.' % (self.jmeno[0]))
|
||||
jmena = self.jmeno.split()
|
||||
return " ".join(['{}.'.format(jmeno[0]) for jmeno in jmena])
|
||||
|
||||
def __str__(self):
|
||||
return force_unicode("Osoba({})".format(self.plne_jmeno()))
|
||||
|
@ -400,7 +402,7 @@ class Cislo(SeminarModelBase):
|
|||
'zveřejněna výsledkovka',
|
||||
default=False,
|
||||
help_text='Je-li false u veřejného čísla,\
|
||||
není výsledkovka zatím veřejná.')
|
||||
není výsledkovka zatím veřejná.')
|
||||
|
||||
poznamka = models.TextField('neveřejná poznámka', blank=True,
|
||||
help_text='Neveřejná poznámka k číslu (plain text)')
|
||||
|
@ -828,7 +830,7 @@ class Hodnoceni(SeminarModelBase):
|
|||
|
||||
# Django neumí jednoduše serializovat partial nebo třídu s __call__
|
||||
# (https://docs.djangoproject.com/en/1.8/topics/migrations/),
|
||||
# neprojdou pak migrace. Takže rozlišení funkcí generujících názvy souboru
|
||||
# neprojdou pak migrace. Takže rozlišení funkcí generujících názvy souboru
|
||||
# podle adresáře řešíme takto.
|
||||
|
||||
##
|
||||
|
@ -1082,7 +1084,7 @@ class Obrazek(SeminarModelBase):
|
|||
null=True, blank=True)
|
||||
|
||||
text = models.ForeignKey(Text, verbose_name='text',
|
||||
help_text='text, ve kterém se obrázek vyskytuje', null=False, blank=False)
|
||||
help_text='text, ve kterém se obrázek vyskytuje', null=False, blank=False)
|
||||
|
||||
do_cisla_barevny = models.FileField('barevný obrázek do čísla',
|
||||
help_text = 'Barevná verze obrázku do čísla',
|
||||
|
|
130
seminar/tests.py
130
seminar/tests.py
|
@ -14,81 +14,81 @@ from seminar import ovvpfile
|
|||
from seminar import utils
|
||||
|
||||
class SeminarBasicTests(TestCase):
|
||||
def setUp(self):
|
||||
create_test_data(size=2)
|
||||
self.client = Client()
|
||||
def setUp(self):
|
||||
create_test_data(size=2)
|
||||
self.client = Client()
|
||||
|
||||
def tearDown(self):
|
||||
call_command('flush', noinput=True, verbosity=0, interactive=False)
|
||||
self.cleint = None
|
||||
def tearDown(self):
|
||||
call_command('flush', noinput=True, verbosity=0, interactive=False)
|
||||
self.cleint = None
|
||||
|
||||
def test_rocniky(self):
|
||||
r19 = Rocnik.objects.get(rocnik=21)
|
||||
self.assertEqual(r19.roman(), 'XXI')
|
||||
def test_rocniky(self):
|
||||
r19 = Rocnik.objects.get(rocnik=21)
|
||||
self.assertEqual(r19.roman(), 'XXI')
|
||||
|
||||
def test_render_cislo_e2e(self):
|
||||
cs = Cislo.objects.all()
|
||||
for c in cs[:4]:
|
||||
url = c.verejne_url()
|
||||
r = self.client.get(url)
|
||||
assert r.status_code == 200
|
||||
assert len(r.content) >= 100
|
||||
# TODO: Validate cntent as HTML
|
||||
def test_render_cislo_e2e(self):
|
||||
cs = Cislo.objects.all()
|
||||
for c in cs[:4]:
|
||||
url = c.verejne_url()
|
||||
r = self.client.get(url)
|
||||
assert r.status_code == 200
|
||||
assert len(r.content) >= 100
|
||||
# TODO: Validate cntent as HTML
|
||||
|
||||
def test_render_problem_e2e(self):
|
||||
ps = Problem.objects.all()
|
||||
for p in ps[:4]:
|
||||
url = p.verejne_url()
|
||||
r = self.client.get(url)
|
||||
assert r.status_code == 200
|
||||
assert len(r.content) >= 100
|
||||
# TODO: Validate cntent as HTML
|
||||
def test_render_problem_e2e(self):
|
||||
ps = Problem.objects.all()
|
||||
for p in ps[:4]:
|
||||
url = p.verejne_url()
|
||||
r = self.client.get(url)
|
||||
assert r.status_code == 200
|
||||
assert len(r.content) >= 100
|
||||
# TODO: Validate cntent as HTML
|
||||
|
||||
def test_export_e2e(self):
|
||||
i_url = '/aesop-export/index.csv'
|
||||
i_r = self.client.get(i_url)
|
||||
assert i_r.status_code == 200
|
||||
ls = i_r.content.strip().split('\n')
|
||||
def test_export_e2e(self):
|
||||
i_url = '/aesop-export/index.csv'
|
||||
i_r = self.client.get(i_url)
|
||||
assert i_r.status_code == 200
|
||||
ls = i_r.content.strip().split('\n')
|
||||
|
||||
for u in [ls[0], ls[-1]]:
|
||||
ex_r = self.client.get('/aesop-export/' + u)
|
||||
assert ex_r.status_code == 200
|
||||
assert len(ex_r.content) >= 100
|
||||
o = ovvpfile.parse(ex_r.content)
|
||||
assert o.headers['version'] == '1'
|
||||
for u in [ls[0], ls[-1]]:
|
||||
ex_r = self.client.get('/aesop-export/' + u)
|
||||
assert ex_r.status_code == 200
|
||||
assert len(ex_r.content) >= 100
|
||||
o = ovvpfile.parse(ex_r.content)
|
||||
assert o.headers['version'] == '1'
|
||||
|
||||
def test_admin_url(self):
|
||||
for m in [Skola, Resitel, Rocnik, Cislo, Problem, Reseni, Nastaveni]:
|
||||
o = m.objects.first()
|
||||
url = o.admin_url()
|
||||
assert url
|
||||
view = resolve(url)
|
||||
assert view
|
||||
def test_admin_url(self):
|
||||
for m in [Skola, Resitel, Rocnik, Cislo, Problem, Reseni, Nastaveni]:
|
||||
o = m.objects.first()
|
||||
url = o.admin_url()
|
||||
assert url
|
||||
view = resolve(url)
|
||||
assert view
|
||||
|
||||
def test_verejne_url(self):
|
||||
for m in [Rocnik, Cislo, Problem]:
|
||||
p = Problem.objects.first()
|
||||
url = p.verejne_url()
|
||||
assert url
|
||||
view = resolve(url)
|
||||
assert view
|
||||
def test_verejne_url(self):
|
||||
for m in [Rocnik, Cislo, Problem]:
|
||||
p = Problem.objects.first()
|
||||
url = p.verejne_url()
|
||||
assert url
|
||||
view = resolve(url)
|
||||
assert view
|
||||
|
||||
def test_ovvpfile(self):
|
||||
filetext = "H1\ta\nH2\tb\tc\n\nx\ty\tz\n0\t1\t2\n3\t4\t5\n"
|
||||
o = ovvpfile.parse(filetext)
|
||||
assert len(o.headers) == 2
|
||||
assert o.headers['H2'] == 'b\tc'
|
||||
def test_ovvpfile(self):
|
||||
filetext = "H1\ta\nH2\tb\tc\n\nx\ty\tz\n0\t1\t2\n3\t4\t5\n"
|
||||
o = ovvpfile.parse(filetext)
|
||||
assert len(o.headers) == 2
|
||||
assert o.headers['H2'] == 'b\tc'
|
||||
|
||||
assert o.columns == ['x','y','z']
|
||||
assert len(o.rows) == 2
|
||||
assert o.rows[0]['z'] == '2'
|
||||
assert o.columns == ['x','y','z']
|
||||
assert len(o.rows) == 2
|
||||
assert o.rows[0]['z'] == '2'
|
||||
|
||||
t = o.to_string()
|
||||
assert t == filetext
|
||||
t = o.to_string()
|
||||
assert t == filetext
|
||||
|
||||
def test_roman(self):
|
||||
for i in [0, 1, 23, 2015, 1999, 42, 4, 400, 78, 4321, 8765, 999]:
|
||||
r = utils.roman(i)
|
||||
fr = utils.from_roman(r)
|
||||
assert fr == i
|
||||
def test_roman(self):
|
||||
for i in [0, 1, 23, 2015, 1999, 42, 4, 400, 78, 4321, 8765, 999]:
|
||||
r = utils.roman(i)
|
||||
fr = utils.from_roman(r)
|
||||
assert fr == i
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import datetime
|
|||
import random
|
||||
import django.contrib.auth
|
||||
from django.db import transaction
|
||||
import unidecode
|
||||
|
||||
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici
|
||||
|
||||
|
@ -14,89 +15,163 @@ User = django.contrib.auth.get_user_model()
|
|||
|
||||
@transaction.atomic
|
||||
def create_test_data(size = 6, rnd = None):
|
||||
assert size >= 1
|
||||
# pevna pseudo-nahodnost
|
||||
rnd = rnd or random.Random(x=42)
|
||||
assert size >= 1
|
||||
# pevna pseudo-nahodnost
|
||||
rnd = rnd or random.Random(x=42)
|
||||
|
||||
# static URL stranky
|
||||
s = Site.objects.filter(name="example.com")
|
||||
f = FlatPage.objects.create(url="/", title="Seminář M&M", content = "<p>Vítejte na stránce semináře MaM!</p>")
|
||||
f.sites.add(s[0])
|
||||
f.save()
|
||||
# static URL stranky
|
||||
# FIXME: nakopirovat sem vsechny z produkcni databaze
|
||||
s = Site.objects.filter(name="example.com")
|
||||
f = FlatPage.objects.create(url="/", title="Seminář M&M", content = "<p>Vítejte na stránce semináře MaM!</p>")
|
||||
f.sites.add(s[0])
|
||||
f.save()
|
||||
|
||||
# users
|
||||
admin = User.objects.create_superuser(username='admin', email='', password='admin')
|
||||
# users
|
||||
admin = User.objects.create_superuser(username='admin', email='', password='admin')
|
||||
|
||||
usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip']
|
||||
orgs = []
|
||||
for org in usernames[:size]:
|
||||
o = User.objects.create_user(username=org, password=org)
|
||||
o.first_name = org.capitalize()
|
||||
o.save()
|
||||
orgs.append(o)
|
||||
usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip']
|
||||
orgs = []
|
||||
for org in usernames[:size]:
|
||||
o = User.objects.create_user(username=org, password=org)
|
||||
o.first_name = org.capitalize()
|
||||
o.save()
|
||||
orgs.append(o)
|
||||
|
||||
# skoly
|
||||
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='101 00', ulice=u'Krátká 5', nazev=u'První ZŠ', je_zs=True, je_ss=False)
|
||||
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='101 00', ulice=u'Krátká 5', nazev=u'První SŠ', je_zs=False, je_ss=True)
|
||||
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='102 00', ulice=u'Dlouhá 5', nazev=u'Druhá SŠ', je_zs=False, je_ss=True)
|
||||
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='103 00', ulice=u'Široká 3', nazev=u'Třetí SŠ a ZŠ', je_zs=True, je_ss=True)
|
||||
Skola.objects.create(mesto = u'Ostrava', stat='CZ', psc='700 00', ulice=u'Hluboká 42', nazev=u'Hutní gympl', je_zs=False, je_ss=True)
|
||||
Skola.objects.create(mesto = u'Humenné', stat='SK', psc='012 34', ulice=u'Pltká 1', nazev=u'Sredná škuola', je_zs=False, je_ss=True)
|
||||
# skoly
|
||||
skoly = []
|
||||
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='101 00', ulice='Krátká 5',
|
||||
nazev='První ZŠ', je_zs=True, je_ss=False))
|
||||
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='101 00', ulice='Krátká 5',
|
||||
nazev='První SŠ', je_zs=False, je_ss=True))
|
||||
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='102 00', ulice='Dlouhá 5',
|
||||
nazev='Druhá SŠ', je_zs=False, je_ss=True))
|
||||
skoly.append(Skola.objects.create(mesto = 'Praha', stat='CZ', psc='103 00', ulice='Široká 3',
|
||||
nazev='Třetí SŠ a ZŠ', je_zs=True, je_ss=True))
|
||||
skoly.append(Skola.objects.create(mesto = 'Ostrava', stat='CZ', psc='700 00', ulic='Hluboká 42',
|
||||
nazev='Hutní gympl', je_zs=False, je_ss=True))
|
||||
skoly.append(Skola.objects.create(mesto = 'Humenné', stat='SK', psc='012 34', ulice='Pltká 1',
|
||||
nazev='Sredná škuola', je_zs=False, je_ss=True))
|
||||
#FIXME pridat kontaktni osobu alespon nekde
|
||||
skoly.append(zlinska = Skola.objects.create(mesto = 'Zlín', stat='CZ', psc='76001',
|
||||
ulice='náměstí T.G. Masaryka 2734-9', nazev='Gymnázium a Střední jazyková škola s právem SJZ',
|
||||
kratky_nazev="GaSJŠspSJZ", je_zs=True, je_ss=True))
|
||||
|
||||
# resitele
|
||||
jmena_m = ['Aleš', 'Tomáš', 'Martin', 'Jakub', 'Petr', 'Lukáš', 'Cyril']
|
||||
jmena_f = ['Eva', 'Karolína', 'Zuzana', 'Sylvie', 'Iva', 'Jana', 'Marie']
|
||||
prijmeni_m = ['Novotný', 'Svoboda', 'Pecha', 'Kořen', 'Holan', 'Uhlíř', 'Chytráček', 'Pokora', 'Koch', 'Szegedy', 'Rudý']
|
||||
prijmeni_f = ['Novotná', 'Svobodová', 'Machová', 'Zelená', 'Yu-Xin', 'Mlsná', 'Dubná', 'Mrkvová', 'Suchá', 'Lovelace', 'Holcová']
|
||||
for i in range(3*size):
|
||||
skola = rnd.choice(Skola.objects.all())
|
||||
pohlavi = rnd.randint(0,1)
|
||||
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi])
|
||||
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi])
|
||||
Resitel.objects.create(skola = skola, datum_prihlaseni = datetime.date(rnd.randint(2002, 2014), rnd.randint(1,12), 1),
|
||||
jmeno =jmeno, prijmeni = prijmeni, rok_maturity = rnd.randint(2015, 2019),
|
||||
stat = skola.stat, zasilat = Resitel.ZASILAT_NIKAM, pohlavi_muz = pohlavi)
|
||||
resitele = list(Resitel.objects.all())
|
||||
# osoby
|
||||
jmena_m = ['Aleš', 'Tomáš', 'Martin', 'Jakub', 'Petr', 'Lukáš', 'Cyril', 'Pavel Karel']
|
||||
jmena_f = ['Eva', 'Karolína', 'Zuzana', 'Sylvie', 'Iva', 'Jana', 'Marie', 'Marta Iva', 'Shu Shan']
|
||||
prijmeni_m = ['Novotný', 'Svoboda', 'Pecha', 'Kořen', 'Holan', 'Uhlíř', 'Chytráček', 'Pokora',
|
||||
'Koch', 'Szegedy', 'Rudý', "von Neumann", "d'Este"]
|
||||
prijmeni_f = ['Novotná', 'Svobodová', 'Machová', 'Zelená', 'Yu-Xin', 'Mlsná', 'Dubná', 'Mrkvová',
|
||||
'Suchá', 'Lovelace', 'Holcová', 'Rui']
|
||||
prezdivka = ['Kaki', 'Hurdur', 'Maracuja', 'Bobbo', None, None, None, None, None, None, None,
|
||||
'Riki', 'Sapa', None, '', '---', 'Koko']
|
||||
domain = ['example.com', 'dolujeme.eu', 'mff.cuni.cz', 'strcprstskrzkrk.cz', 'british.co.uk',
|
||||
'splachni.to', 'haha.org']
|
||||
seznam_ulic = ['Krátká', 'Vlhká', 'Jungmanova', '17. listopadu', '4. října', 'Roztocká',
|
||||
'Forstova', 'Generála Františka Janouška', 'Náměstí Války', 'Svratecké náměstí',
|
||||
'Zelená lhota', 'Z Plynu', 'K Jezeru', 'U Kocourkova', 'Uštěpačná', 'Ostrorepská',
|
||||
'Zubří']
|
||||
seznam_mest = ['Praha', 'Brno', 'Ostrava', 'Horní Jelení', 'Dolní Zábrdovice', 'Prdelkov',
|
||||
'Stará myslivna', 'Kocourkov', 'Šalingrad', 'Medvědí hora', 'Basilej',
|
||||
'Unterschiedlich', 'Old York', 'Lancastershire', 'Vóloďháza']
|
||||
|
||||
# rocniky
|
||||
last_rocnik = 21
|
||||
for ri in range(last_rocnik - size, last_rocnik + 1):
|
||||
r = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri)
|
||||
osoby = []
|
||||
for i in range(3 * size):
|
||||
pohlavi = rnd.randint(0,1)
|
||||
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi])
|
||||
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi])
|
||||
prezdivka = rnd.choice(prezdivka)
|
||||
email = "@".join([unidecode.unidecode(jmeno), rnd.choice(domain)])
|
||||
telefon = [rnd.choice([k for k in range(10)]) for i in range(10)]
|
||||
narozeni = datetime.date(rnd.randint(1980, 2020), rnd.randint(1, 12), rnd.randint(1, 28))
|
||||
ulic = rnd.choice([seznam_ulic])
|
||||
cp = rnd.int(1, 99)
|
||||
ulice = " ".join(ulic, cp)
|
||||
mesto = rnd.choice([seznam_mest])
|
||||
psc = [rnd.choice([k for k in range(10)]) for i in range(6)]
|
||||
osoby.append(Osoba.objects.create(jmeno = jmeno, prijmeni = prijmeni, prezdivka = prezdivka,
|
||||
pohlavi_muz = pohlavi, email = email, telefon = telefon, datum_narozeni = narozeni,
|
||||
ulice = ulice, mesto = mesto, psc = psc,
|
||||
datum_registrace = datetime.date(rnd.randint(2019, 2029), rnd.randint(1, 12),
|
||||
rnd.randint(1, 28))))
|
||||
#TODO pridat foto male a velke. Jak?
|
||||
|
||||
# cisla
|
||||
cisel = rnd.randint(4, 6)
|
||||
# resitele a organizatori
|
||||
last_rocnik = 25
|
||||
resitele = []
|
||||
organizatori = []
|
||||
for os in osoby:
|
||||
rand = rnd.randint(0, 8)
|
||||
if not (rand % 8 == 0):
|
||||
resitele.append(Resitel.objects.create(osoba = os, skola = rnd.choice([skoly]),
|
||||
rok_maturity = rnd.randint(2019, 2029),
|
||||
zasilat = rnd.choice(Resitel.ZASILAT_CHOICES)))
|
||||
else:
|
||||
pusobnost = rnd.randint(1, last_rocnik)
|
||||
od = 1993 + last_rocnik - pusobnost
|
||||
do = od + rnd.randint(1, 8)
|
||||
# aktualni organizatori jeste nemaji vyplnene organizuje_do
|
||||
if do > datetime.now().year:
|
||||
do = None
|
||||
organizatori.append(Organizator.objects.create(osoba = os, organizuje_od = od,
|
||||
organizuje_do = do))
|
||||
|
||||
cs = {}
|
||||
for ci in range(1, cisel + 1):
|
||||
vydano = datetime.date(r.prvni_rok, ci + 6, 1)
|
||||
deadline = datetime.date(r.prvni_rok, ci + 8, 1) if ci + 2 < cisel else None
|
||||
c = Cislo.objects.create(rocnik = r, cislo = str(ci), datum_vydani=vydano, datum_deadline=deadline, verejne_db=True)
|
||||
cs[ci] = c
|
||||
# rocniky
|
||||
for ri in range(min(last_rocnik - size, 1), last_rocnik + 1):
|
||||
r = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri)
|
||||
|
||||
# problemy resene v ci
|
||||
seq='#ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
if ci >= 3:
|
||||
for pi in range(1, ((size + 1) // 2) + 1):
|
||||
p = Problem.objects.create(autor = rnd.choice(orgs), cislo_zadani=cs[ci-2], cislo_reseni=cs[ci],
|
||||
opravovatel = rnd.choice(orgs), kod = str(pi), nazev = u'Dummy úloha %s-%s' % (seq[ci], seq[pi]),
|
||||
stav = Problem.STAV_ZADANY, typ = Problem.TYP_ULOHA, body = rnd.randint(1, 5))
|
||||
p.text_problemu = (u"<p>Text problému <strong>%s.%s %s</strong><em> [id %d]</em> za %d body.</p>" %
|
||||
(p.cislo_zadani.kod(), p.kod, p.nazev, p.id, p.body))
|
||||
p.text_problemu_org = u"<p><strong>Neveřejný</strong> text problému.</p>"
|
||||
p.save()
|
||||
# cisla
|
||||
cisel = rnd.randint(4, 8)
|
||||
|
||||
poc_reseni = rnd.randint(size // 2, size * 2)
|
||||
res_sel = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2))
|
||||
for resitel in res_sel:
|
||||
res = Reseni.objects.create(problem = p, resitel = resitel,
|
||||
body = rnd.randint(0, p.body), cislo_body = cs[ci])
|
||||
slovnik_cisel = {}
|
||||
for ci in range(1, cisel + 1):
|
||||
if ci >= 3:
|
||||
vydano = datetime.date(r.prvni_rok, ci + 6, rnd.randint(1, 28))
|
||||
deadline = datetime.date(r.prvni_rok, ci + 8, rnd.randint(1, 28))
|
||||
else:
|
||||
vydano = datetime.date(r.druhy_rok, ci - 3, rnd.randint(1, 28))
|
||||
# posledni 2 cisla v rocniku nemaji deadline
|
||||
if (ci + 2 > cisel):
|
||||
deadline = datetime.date(r.druhy_rok, ci - 1, rnd.randint(1, 28))
|
||||
else:
|
||||
deadline = None
|
||||
cislo = Cislo.objects.create(rocnik = r, cislo = str(ci), datum_vydani=vydano,
|
||||
datum_deadline=deadline, verejne_db=True)
|
||||
slovnik_cisel[ci] = cislo
|
||||
|
||||
sous = Soustredeni.objects.create(rocnik=Rocnik.objects.first(), verejne_db=True, misto=u'Někde',
|
||||
datum_zacatku=datetime.date(2000, 11, 23), datum_konce=datetime.date(2000, 11, 27))
|
||||
for res in rnd.sample(resitele, 6):
|
||||
Soustredeni_Ucastnici.objects.create(resitel=res, soustredeni=sous)
|
||||
sous.save()
|
||||
# FIXME: misto typu ruzne typy objektu a vnoreni do sebe
|
||||
# TODO: vytvorit temata s ruznymi vlakny
|
||||
# TODO: nagenerovat starsim rocnikum pohadku
|
||||
|
||||
nastaveni = Nastaveni.objects.create(aktualni_rocnik = Rocnik.objects.last(),
|
||||
aktualni_cislo = Cislo.objects.all()[1])
|
||||
# problemy resene v ci
|
||||
# seq='#ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
# if ci >= 3:
|
||||
# for pi in range(1, ((size + 1) // 2) + 1):
|
||||
# p = Problem.objects.create(autor = rnd.choice(orgs), cislo_zadani=cs[ci-2],
|
||||
# cislo_reseni=cs[ci], opravovatel = rnd.choice(orgs), kod = str(pi),
|
||||
# nazev = u'Dummy úloha %s-%s' % (seq[ci], seq[pi]),
|
||||
# stav = Problem.STAV_ZADANY, typ = Problem.TYP_ULOHA, body = rnd.randint(1, 5))
|
||||
# p.text_problemu = (u"<p>Text problému <strong>%s.%s %s</strong><em> [id %d]</em> za %d body.</p>" %
|
||||
# (p.cislo_zadani.kod(), p.kod, p.nazev, p.id, p.body))
|
||||
# p.text_problemu_org = u"<p><strong>Neveřejný</strong> text problému.</p>"
|
||||
# p.save()
|
||||
#
|
||||
# poc_reseni = rnd.randint(size // 2, size * 2)
|
||||
# res_sel = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2))
|
||||
# for resitel in res_sel:
|
||||
# res = Reseni.objects.create(problem = p, resitel = resitel,
|
||||
# body = rnd.randint(0, p.body), cislo_body = cs[ci])
|
||||
#
|
||||
# TODO: nahodne nagenerovat problemum reseni a prilohy reseni, hodnoceni
|
||||
|
||||
|
||||
# TODO: vice soustredeni a k nim nahodne podmnoziny organizatoru a ucastniku
|
||||
sous = Soustredeni.objects.create(rocnik=Rocnik.objects.first(), verejne_db=True, misto=u'Někde',
|
||||
datum_zacatku=datetime.date(2000, 11, 23), datum_konce=datetime.date(2000, 11, 27))
|
||||
for res in rnd.sample(resitele, 6):
|
||||
Soustredeni_Ucastnici.objects.create(resitel=res, soustredeni=sous)
|
||||
sous.save()
|
||||
|
||||
nastaveni = Nastaveni.objects.create(aktualni_rocnik = Rocnik.objects.last(),
|
||||
aktualni_cislo = Cislo.objects.all()[1])
|
||||
|
||||
|
|
122
seminar/tools.py
122
seminar/tools.py
|
@ -5,78 +5,78 @@ from .models import Resitel
|
|||
from reversion import revisions as reversion
|
||||
|
||||
def merge_props(r1, r2, prop, pretend=True, smaller=False, equal=True):
|
||||
"""Merge r2.`prop` into r1.`prop`.
|
||||
"""Merge r2.`prop` into r1.`prop`.
|
||||
|
||||
If r1.`prop` unset, use r1.`prop`=r2.`prop`.
|
||||
If both set and equal=True, warn if not equal.
|
||||
If both set and smaller=True, use the smaller one.
|
||||
With pretend=True does not modify r1.
|
||||
"""
|
||||
a1 = r1.__getattribute__(prop)
|
||||
a2 = r2.__getattribute__(prop)
|
||||
if not a1:
|
||||
if not pretend:
|
||||
r1.__setattr__(prop, a2)
|
||||
elif a2:
|
||||
if equal and a1 != a2:
|
||||
log.warn(u"merge: Ruzna %s: %s VS %s", prop, a1, a2)
|
||||
if smaller:
|
||||
if not pretend:
|
||||
r1.__setattr__(prop, min(a1, a2))
|
||||
If r1.`prop` unset, use r1.`prop`=r2.`prop`.
|
||||
If both set and equal=True, warn if not equal.
|
||||
If both set and smaller=True, use the smaller one.
|
||||
With pretend=True does not modify r1.
|
||||
"""
|
||||
a1 = r1.__getattribute__(prop)
|
||||
a2 = r2.__getattribute__(prop)
|
||||
if not a1:
|
||||
if not pretend:
|
||||
r1.__setattr__(prop, a2)
|
||||
elif a2:
|
||||
if equal and a1 != a2:
|
||||
log.warn(u"merge: Ruzna %s: %s VS %s", prop, a1, a2)
|
||||
if smaller:
|
||||
if not pretend:
|
||||
r1.__setattr__(prop, min(a1, a2))
|
||||
|
||||
|
||||
def merge_Resitel(rbase, rmerge, pretend=True):
|
||||
"""Zahrne data a vztahy Resitele rmerge do Resitele rbase, pak smaze rmerge.
|
||||
"""Zahrne data a vztahy Resitele rmerge do Resitele rbase, pak smaze rmerge.
|
||||
|
||||
Selze pro uzivatele s user!=NULL. S pretend=True nezmeni databazi.
|
||||
"""
|
||||
# Ma relace: skola
|
||||
# Je v relaci: user, reseni, soustredeni_ucastnici, vysledky_base(VIEW)
|
||||
Selze pro uzivatele s user!=NULL. S pretend=True nezmeni databazi.
|
||||
"""
|
||||
# Ma relace: skola
|
||||
# Je v relaci: user, reseni, soustredeni_ucastnici, vysledky_base(VIEW)
|
||||
|
||||
log.info(u"merge: %s <- %s", unicode(rbase), unicode(rmerge))
|
||||
log.info(u"merge: %s <- %s", unicode(rbase), unicode(rmerge))
|
||||
|
||||
assert not rbase.user
|
||||
assert not rmerge.user
|
||||
assert rbase != rmerge
|
||||
assert not rbase.user
|
||||
assert not rmerge.user
|
||||
assert rbase != rmerge
|
||||
|
||||
if (rbase.jmeno != rmerge.jmeno) or (rbase.prijmeni != rmerge.prijmeni):
|
||||
log.error(u"merge: Ruzna jmena: %s VS %s", rbase, rmerge)
|
||||
if rbase.rok_maturity != rmerge.rok_maturity:
|
||||
log.error(u"merge: Ruzne roky maturity: %s VS %s", rbase.rok_maturity, rmerge.rok_maturity)
|
||||
if (rbase.jmeno != rmerge.jmeno) or (rbase.prijmeni != rmerge.prijmeni):
|
||||
log.error(u"merge: Ruzna jmena: %s VS %s", rbase, rmerge)
|
||||
if rbase.rok_maturity != rmerge.rok_maturity:
|
||||
log.error(u"merge: Ruzne roky maturity: %s VS %s", rbase.rok_maturity, rmerge.rok_maturity)
|
||||
|
||||
with reversion.create_revision():
|
||||
reversion.set_comment('Merge duplicitnich Resitelu: %r <- %r' % (rbase.pk, rmerge.pk))
|
||||
with reversion.create_revision():
|
||||
reversion.set_comment('Merge duplicitnich Resitelu: %r <- %r' % (rbase.pk, rmerge.pk))
|
||||
|
||||
merge_props(rbase, rmerge, 'skola', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'datum_narozeni', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'datum_prihlaseni', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'datum_souhlasu_zasilani', pretend=pretend, smaller=True, equal=False)
|
||||
merge_props(rbase, rmerge, 'datum_souhlasu_udaje', pretend=pretend, smaller=True, equal=False)
|
||||
merge_props(rbase, rmerge, 'email', pretend=pretend)
|
||||
if rmerge.import_mamoper_id and not pretend:
|
||||
rbase.import_mamoper_id += ' ' + rmerge.import_mamoper_id
|
||||
if rmerge.poznamka and not pretend:
|
||||
rbase.poznamka += ' ' + rmerge.poznamka
|
||||
merge_props(rbase, rmerge, 'mesto', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'pohlavi_muz', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'psc', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'stat', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'telefon', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'ulice', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'zasilat', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'skola', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'datum_narozeni', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'datum_prihlaseni', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'datum_souhlasu_zasilani', pretend=pretend, smaller=True, equal=False)
|
||||
merge_props(rbase, rmerge, 'datum_souhlasu_udaje', pretend=pretend, smaller=True, equal=False)
|
||||
merge_props(rbase, rmerge, 'email', pretend=pretend)
|
||||
if rmerge.import_mamoper_id and not pretend:
|
||||
rbase.import_mamoper_id += ' ' + rmerge.import_mamoper_id
|
||||
if rmerge.poznamka and not pretend:
|
||||
rbase.poznamka += ' ' + rmerge.poznamka
|
||||
merge_props(rbase, rmerge, 'mesto', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'pohlavi_muz', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'psc', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'stat', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'telefon', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'ulice', pretend=pretend)
|
||||
merge_props(rbase, rmerge, 'zasilat', pretend=pretend)
|
||||
|
||||
for res in rmerge.reseni.all():
|
||||
if not pretend:
|
||||
res.resitel = rbase
|
||||
res.save()
|
||||
for res in rmerge.reseni.all():
|
||||
if not pretend:
|
||||
res.resitel = rbase
|
||||
res.save()
|
||||
|
||||
for uc in rmerge.soustredeni_ucastnici_set.all():
|
||||
if not pretend:
|
||||
uc.resitel = rbase
|
||||
uc.save()
|
||||
for uc in rmerge.soustredeni_ucastnici_set.all():
|
||||
if not pretend:
|
||||
uc.resitel = rbase
|
||||
uc.save()
|
||||
|
||||
if not pretend:
|
||||
rmerge.delete()
|
||||
rbase.save()
|
||||
|
||||
if not pretend:
|
||||
rmerge.delete()
|
||||
rbase.save()
|
||||
|
||||
|
||||
|
|
182
seminar/urls.py
182
seminar/urls.py
|
@ -8,108 +8,108 @@ from django.views.generic.base import RedirectView
|
|||
staff_member_required = user_passes_test(lambda u: u.is_staff)
|
||||
|
||||
urlpatterns = [
|
||||
# REDIRECTy
|
||||
url(r'^jak-resit/$', RedirectView.as_view(url='/co-je-MaM/jak-resit/')),
|
||||
# REDIRECTy
|
||||
url(r'^jak-resit/$', RedirectView.as_view(url='/co-je-MaM/jak-resit/')),
|
||||
|
||||
# Organizatori
|
||||
url(r'^co-je-MaM/organizatori/$', views.CojemamOrganizatoriView.as_view(), name='organizatori'),
|
||||
url(r'^co-je-MaM/organizatori/organizovali/$', views.CojemamOrganizatoriStariView.as_view(), name='stari_organizatori'),
|
||||
# Organizatori
|
||||
url(r'^co-je-MaM/organizatori/$', views.CojemamOrganizatoriView.as_view(), name='organizatori'),
|
||||
url(r'^co-je-MaM/organizatori/organizovali/$', views.CojemamOrganizatoriStariView.as_view(), name='stari_organizatori'),
|
||||
|
||||
# Archiv
|
||||
url(r'^archiv/cisla/$', views.ArchivView.as_view()),
|
||||
url(r'^archiv/temata/$', views.ArchivTemataView.as_view()),
|
||||
# Archiv
|
||||
url(r'^archiv/cisla/$', views.ArchivView.as_view()),
|
||||
url(r'^archiv/temata/$', views.ArchivTemataView.as_view()),
|
||||
|
||||
url(r'^rocnik/(?P<rocnik>\d+)/$', views.RocnikView.as_view(), name='seminar_rocnik'),
|
||||
#url(r'^cislo/(?P<rocnik>\d+)\.(?P<cislo>[0-9-]+)/$', views.CisloView.as_view(), name='seminar_cislo'),
|
||||
url(r'^problem/(?P<pk>\d+)/$', views.ProblemView.as_view(), name='seminar_problem'),
|
||||
#url(r'^problem/(?P<pk>\d+)/(?P<prispevek>\d+)/$', views.PrispevekView.as_view(), name='seminar_problem_prispevek'),
|
||||
url(r'^rocnik/(?P<rocnik>\d+)/$', views.RocnikView.as_view(), name='seminar_rocnik'),
|
||||
#url(r'^cislo/(?P<rocnik>\d+)\.(?P<cislo>[0-9-]+)/$', views.CisloView.as_view(), name='seminar_cislo'),
|
||||
url(r'^problem/(?P<pk>\d+)/$', views.ProblemView.as_view(), name='seminar_problem'),
|
||||
#url(r'^problem/(?P<pk>\d+)/(?P<prispevek>\d+)/$', views.PrispevekView.as_view(), name='seminar_problem_prispevek'),
|
||||
|
||||
# Soustredeni
|
||||
url(
|
||||
r'^soustredeni/probehlo/$',
|
||||
views.SoustredeniListView.as_view(),
|
||||
name='seminar_seznam_soustredeni'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/probehlo/(?P<soustredeni>\d+)/$',
|
||||
views.SoustredeniView.as_view(),
|
||||
name='seminar_soustredeni'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/seznam_ucastniku$',
|
||||
staff_member_required(views.SoustredeniUcastniciView.as_view()),
|
||||
name='soustredeni_ucastnici'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/maily_ucastniku$',
|
||||
staff_member_required(views.SoustredeniMailyUcastnikuView.as_view()),
|
||||
name='maily_ucastniku'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/stvrzenky/(?P<first_num>\d+)$',
|
||||
staff_member_required(views.soustredeniStvrzenkyExportView),
|
||||
name='soustredeni_stvrzenky'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/export_ucastniku$',
|
||||
staff_member_required(views.soustredeniUcastniciExportView),
|
||||
name='soustredeni_ucastnici_export'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/fotogalerie/',
|
||||
include('galerie.urls')
|
||||
),
|
||||
# Soustredeni
|
||||
url(
|
||||
r'^soustredeni/probehlo/$',
|
||||
views.SoustredeniListView.as_view(),
|
||||
name='seminar_seznam_soustredeni'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/probehlo/(?P<soustredeni>\d+)/$',
|
||||
views.SoustredeniView.as_view(),
|
||||
name='seminar_soustredeni'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/seznam_ucastniku$',
|
||||
staff_member_required(views.SoustredeniUcastniciView.as_view()),
|
||||
name='soustredeni_ucastnici'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/maily_ucastniku$',
|
||||
staff_member_required(views.SoustredeniMailyUcastnikuView.as_view()),
|
||||
name='maily_ucastniku'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/stvrzenky/(?P<first_num>\d+)$',
|
||||
staff_member_required(views.soustredeniStvrzenkyExportView),
|
||||
name='soustredeni_stvrzenky'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/export_ucastniku$',
|
||||
staff_member_required(views.soustredeniUcastniciExportView),
|
||||
name='soustredeni_ucastnici_export'
|
||||
),
|
||||
url(
|
||||
r'^soustredeni/(?P<soustredeni>\d+)/fotogalerie/',
|
||||
include('galerie.urls')
|
||||
),
|
||||
|
||||
# Zadani
|
||||
url(r'^zadani/aktualni/$', views.AktualniZadaniView, name='seminar_aktualni_zadani'),
|
||||
url(r'^zadani/temata/$', views.ZadaniTemataView, name='seminar_temata'),
|
||||
#url(r'^zadani/vysledkova-listina/$', views.ZadaniAktualniVysledkovkaView, name='seminar_vysledky'),
|
||||
url(r'^$', views.TitulniStranaView.as_view(), name='titulni_strana'),
|
||||
url(r'^stare-novinky/$', views.StareNovinkyView.as_view(), name='stare_novinky'),
|
||||
# Zadani
|
||||
url(r'^zadani/aktualni/$', views.AktualniZadaniView, name='seminar_aktualni_zadani'),
|
||||
url(r'^zadani/temata/$', views.ZadaniTemataView, name='seminar_temata'),
|
||||
#url(r'^zadani/vysledkova-listina/$', views.ZadaniAktualniVysledkovkaView, name='seminar_vysledky'),
|
||||
url(r'^$', views.TitulniStranaView.as_view(), name='titulni_strana'),
|
||||
url(r'^stare-novinky/$', views.StareNovinkyView.as_view(), name='stare_novinky'),
|
||||
|
||||
# Clanky
|
||||
url(r'^clanky/resitel/$', views.ClankyResitelView.as_view(), name='clanky_resitel'),
|
||||
#url(r'^clanky/org/$', views.ClankyOrganizatorView.as_view(), name='clanky_organizator'),
|
||||
# Clanky
|
||||
url(r'^clanky/resitel/$', views.ClankyResitelView.as_view(), name='clanky_resitel'),
|
||||
#url(r'^clanky/org/$', views.ClankyOrganizatorView.as_view(), name='clanky_organizator'),
|
||||
|
||||
# Aesop
|
||||
url(r'^aesop-export/mam-rocnik-(?P<prvni_rok>\d+)\.csv$', export.ExportRocnikView.as_view(), name='seminar_export_rocnik'),
|
||||
url(r'^aesop-export/mam-sous-(?P<datum_zacatku>[\d-]+)\.csv$', export.ExportSousView.as_view(), name='seminar_export_sous'),
|
||||
url(r'^aesop-export/index.csv$', export.ExportIndexView.as_view(), name='seminar_export_index'),
|
||||
# Aesop
|
||||
url(r'^aesop-export/mam-rocnik-(?P<prvni_rok>\d+)\.csv$', export.ExportRocnikView.as_view(), name='seminar_export_rocnik'),
|
||||
url(r'^aesop-export/mam-sous-(?P<datum_zacatku>[\d-]+)\.csv$', export.ExportSousView.as_view(), name='seminar_export_sous'),
|
||||
url(r'^aesop-export/index.csv$', export.ExportIndexView.as_view(), name='seminar_export_index'),
|
||||
|
||||
# Stranky viditelne pouze pro orgy:
|
||||
#url(
|
||||
# r'^rocnik/(?P<rocnik>\d+)/vysledkovka.tex$',
|
||||
# staff_member_required(views.RocnikVysledkovkaView.as_view()),
|
||||
# name='seminar_cislo_vysledkovka'
|
||||
#),
|
||||
#url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/vysledkovka.tex$',
|
||||
# staff_member_required(views.CisloVysledkovkaView.as_view()), name='seminar_cislo_vysledkovka'),
|
||||
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/obalky.pdf$',
|
||||
staff_member_required(views.cisloObalkyView), name='seminar_cislo_obalky'),
|
||||
# Stranky viditelne pouze pro orgy:
|
||||
#url(
|
||||
# r'^rocnik/(?P<rocnik>\d+)/vysledkovka.tex$',
|
||||
# staff_member_required(views.RocnikVysledkovkaView.as_view()),
|
||||
# name='seminar_cislo_vysledkovka'
|
||||
#),
|
||||
#url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/vysledkovka.tex$',
|
||||
# staff_member_required(views.CisloVysledkovkaView.as_view()), name='seminar_cislo_vysledkovka'),
|
||||
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/obalky.pdf$',
|
||||
staff_member_required(views.cisloObalkyView), name='seminar_cislo_obalky'),
|
||||
|
||||
#url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/tituly.tex$',
|
||||
# staff_member_required(views.TitulyView), name='seminar_cislo_titul'),
|
||||
url(r'^stav$',
|
||||
staff_member_required(views.StavDatabazeView), name='stav_databaze'),
|
||||
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/obalkovani$',
|
||||
staff_member_required(views.obalkovaniView), name='seminar_cislo_resitel_obalkovani'),
|
||||
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/tex-download.json$',
|
||||
staff_member_required(views.texDownloadView), name='seminar_tex_download'),
|
||||
url(r'^soustredeni/(?P<soustredeni>\d+)/obalky.pdf',
|
||||
staff_member_required(views.soustredeniObalkyView), name='seminar_soustredeni_obalky'),
|
||||
#url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/tituly.tex$',
|
||||
# staff_member_required(views.TitulyView), name='seminar_cislo_titul'),
|
||||
url(r'^stav$',
|
||||
staff_member_required(views.StavDatabazeView), name='stav_databaze'),
|
||||
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/obalkovani$',
|
||||
staff_member_required(views.obalkovaniView), name='seminar_cislo_resitel_obalkovani'),
|
||||
url(r'^cislo/(?P<rocnik>\d+).(?P<cislo>[0-9-]+)/tex-download.json$',
|
||||
staff_member_required(views.texDownloadView), name='seminar_tex_download'),
|
||||
url(r'^soustredeni/(?P<soustredeni>\d+)/obalky.pdf',
|
||||
staff_member_required(views.soustredeniObalkyView), name='seminar_soustredeni_obalky'),
|
||||
|
||||
url(r'^tex-upload/login/$', views.LoginView, name='seminar_login'),
|
||||
url(
|
||||
r'^tex-upload/$',
|
||||
staff_member_required(views.texUploadView),
|
||||
name='seminar_tex_upload'
|
||||
),
|
||||
url(r'^prihlaska/$',views.get_name),
|
||||
url(r'^tex-upload/login/$', views.LoginView, name='seminar_login'),
|
||||
url(
|
||||
r'^tex-upload/$',
|
||||
staff_member_required(views.texUploadView),
|
||||
name='seminar_tex_upload'
|
||||
),
|
||||
url(r'^prihlaska/$',views.get_name),
|
||||
|
||||
# Ceka na autocomplete v3
|
||||
# url(r'^autocomplete/organizatori/$',
|
||||
# staff_member_required(views.OrganizatorAutocomplete.as_view()),
|
||||
# name='seminar_autocomplete_organizator')
|
||||
# Ceka na autocomplete v3
|
||||
# url(r'^autocomplete/organizatori/$',
|
||||
# staff_member_required(views.OrganizatorAutocomplete.as_view()),
|
||||
# name='seminar_autocomplete_organizator')
|
||||
|
||||
|
||||
]
|
||||
|
|
110
seminar/utils.py
110
seminar/utils.py
|
@ -6,77 +6,77 @@ from django.contrib.auth.decorators import user_passes_test
|
|||
staff_member_required = user_passes_test(lambda u: u.is_staff)
|
||||
|
||||
def histogram(seznam):
|
||||
d = {}
|
||||
for i in seznam:
|
||||
if i not in d:
|
||||
d[i] = 0
|
||||
d[i] += 1
|
||||
return d
|
||||
d = {}
|
||||
for i in seznam:
|
||||
if i not in d:
|
||||
d[i] = 0
|
||||
d[i] += 1
|
||||
return d
|
||||
|
||||
|
||||
roman_numerals = zip((1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
|
||||
('M', 'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I'))
|
||||
('M', 'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I'))
|
||||
|
||||
def roman(num):
|
||||
res = ""
|
||||
for i, n in roman_numerals:
|
||||
res += n * (num // i)
|
||||
num %= i
|
||||
return res
|
||||
res = ""
|
||||
for i, n in roman_numerals:
|
||||
res += n * (num // i)
|
||||
num %= i
|
||||
return res
|
||||
|
||||
def from_roman(rom):
|
||||
if not rom:
|
||||
return 0
|
||||
for i, n in roman_numerals:
|
||||
if rom.upper().startswith(n):
|
||||
return i + from_roman(rom[len(n):])
|
||||
raise Exception('Invalid roman numeral: "%s"', rom)
|
||||
if not rom:
|
||||
return 0
|
||||
for i, n in roman_numerals:
|
||||
if rom.upper().startswith(n):
|
||||
return i + from_roman(rom[len(n):])
|
||||
raise Exception('Invalid roman numeral: "%s"', rom)
|
||||
|
||||
|
||||
def seznam_problemu():
|
||||
from .models import Problem, Resitel, Rocnik, Reseni, Cislo
|
||||
problemy = []
|
||||
from .models import Problem, Resitel, Rocnik, Reseni, Cislo
|
||||
problemy = []
|
||||
|
||||
# Pomocna fce k formatovani problemovych hlasek
|
||||
def prb(cls, msg, objs=None):
|
||||
s = u'<b>%s:</b> %s' % (cls.__name__, msg)
|
||||
if objs:
|
||||
s += u' ['
|
||||
for o in objs:
|
||||
try:
|
||||
url = o.admin_url()
|
||||
except:
|
||||
url = None
|
||||
if url:
|
||||
s += u'<a href="%s">%s</a>, ' % (url, o.pk, )
|
||||
else:
|
||||
s += u'%s, ' % (o.pk, )
|
||||
s = s[:-2] + u']'
|
||||
problemy.append(s)
|
||||
# Pomocna fce k formatovani problemovych hlasek
|
||||
def prb(cls, msg, objs=None):
|
||||
s = u'<b>%s:</b> %s' % (cls.__name__, msg)
|
||||
if objs:
|
||||
s += u' ['
|
||||
for o in objs:
|
||||
try:
|
||||
url = o.admin_url()
|
||||
except:
|
||||
url = None
|
||||
if url:
|
||||
s += u'<a href="%s">%s</a>, ' % (url, o.pk, )
|
||||
else:
|
||||
s += u'%s, ' % (o.pk, )
|
||||
s = s[:-2] + u']'
|
||||
problemy.append(s)
|
||||
|
||||
# Duplicita jmen
|
||||
jmena = {}
|
||||
for r in Resitel.objects.all():
|
||||
j = r.plne_jmeno()
|
||||
if j not in jmena:
|
||||
jmena[j] = []
|
||||
jmena[j].append(r)
|
||||
for j in jmena:
|
||||
if len(jmena[j]) > 1:
|
||||
prb(Resitel, u'Duplicitní jméno "%s"' % (j, ), jmena[j])
|
||||
# Duplicita jmen
|
||||
jmena = {}
|
||||
for r in Resitel.objects.all():
|
||||
j = r.plne_jmeno()
|
||||
if j not in jmena:
|
||||
jmena[j] = []
|
||||
jmena[j].append(r)
|
||||
for j in jmena:
|
||||
if len(jmena[j]) > 1:
|
||||
prb(Resitel, u'Duplicitní jméno "%s"' % (j, ), jmena[j])
|
||||
|
||||
# Data maturity a narození
|
||||
for r in Resitel.objects.all():
|
||||
if not r.rok_maturity:
|
||||
prb(Resitel, u'Neznámý rok maturity', [r])
|
||||
if r.rok_maturity and (r.rok_maturity < 1990 or r.rok_maturity > datetime.date.today().year + 10):
|
||||
prb(Resitel, u'Podezřelé datum maturity', [r])
|
||||
if r.datum_narozeni and (r.datum_narozeni.year < 1970 or r.datum_narozeni.year > datetime.date.today().year - 12):
|
||||
prb(Resitel, u'Podezřelé datum narození', [r])
|
||||
# Data maturity a narození
|
||||
for r in Resitel.objects.all():
|
||||
if not r.rok_maturity:
|
||||
prb(Resitel, u'Neznámý rok maturity', [r])
|
||||
if r.rok_maturity and (r.rok_maturity < 1990 or r.rok_maturity > datetime.date.today().year + 10):
|
||||
prb(Resitel, u'Podezřelé datum maturity', [r])
|
||||
if r.datum_narozeni and (r.datum_narozeni.year < 1970 or r.datum_narozeni.year > datetime.date.today().year - 12):
|
||||
prb(Resitel, u'Podezřelé datum narození', [r])
|
||||
# if not r.email:
|
||||
# prb(Resitel, u'Neznámý email', [r])
|
||||
|
||||
return problemy
|
||||
return problemy
|
||||
|
||||
|
||||
|
||||
|
|
1360
seminar/views.py
1360
seminar/views.py
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue