Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.6 KiB
98 lines
2.6 KiB
# coding: utf-8
|
|
|
|
import random
|
|
|
|
from django.http import HttpResponse, Http404
|
|
from django.shortcuts import render, HttpResponseRedirect, get_object_or_404
|
|
from django.template import RequestContext
|
|
from galerie.models import Obrazek, Galerie
|
|
from seminar.models import Soustredeni
|
|
|
|
|
|
#def index(request, stitek=None):
|
|
#if stitek == None:
|
|
#return HttpResponseRedirect('./0/')
|
|
#
|
|
#galerie = Galerie.publikovane_galerie()
|
|
#if int(stitek) != 0:
|
|
#galerie = galerie.filter(stitek = stitek)
|
|
#if not galerie:
|
|
#raise Http404
|
|
#galerie = galerie.order_by("-datum_zmeny")
|
|
#
|
|
#return render(request, 'Galerie/GalerieIndex.html',
|
|
#{'galerie' : galerie,
|
|
#'stitky' : Stitek.stitky_u_galerii(),
|
|
#'umisteni_stitek' : stitek,
|
|
#'umisteni_Fotogalerie' : True,
|
|
#})
|
|
|
|
def nahled(request, pk, soustredeni):
|
|
"""Zobrazeni nahledu vsech fotek ve skupine."""
|
|
galerie = get_object_or_404(Galerie, pk=pk)
|
|
preview = False
|
|
if galerie.zobrazit >= 1:
|
|
if request.user.is_staff:
|
|
preview = True;
|
|
else:
|
|
raise Http404
|
|
return render(request, 'galerie/GalerieNahled.html',
|
|
{'galerie' : galerie,
|
|
'preview' : preview,
|
|
})
|
|
|
|
def detail(request, pk, fotka):
|
|
"""Zobrazeni nahledu fotky s id 'fotka'."""
|
|
MAX_VYSKA = 600
|
|
MAX_SIRKA = 600
|
|
MAX_VYSKA_MALA = 100
|
|
MAX_SIRKA_MALA = 200
|
|
NAHLEDU = 3
|
|
|
|
galerie = get_object_or_404(Galerie, pk=pk)
|
|
preview = False
|
|
if not galerie.je_publikovano():
|
|
if request.user.is_authenticated():
|
|
preview = True;
|
|
else:
|
|
raise Http404
|
|
obrazek = get_object_or_404(Obrazek, pk=fotka)
|
|
obrazky = galerie.obrazky.all()
|
|
|
|
# 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.
|
|
obrazky_dalsi = obrazky[znacka+1:znacka+NAHLEDU+1]
|
|
if znacka > NAHLEDU:
|
|
obrazky_predchozi = obrazky[znacka-NAHLEDU:znacka]
|
|
else:
|
|
obrazky_predchozi = obrazky[0:znacka]
|
|
|
|
# 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,
|
|
'obrazek' : obrazek,
|
|
'vyska' : vyska,
|
|
'sirka' : sirka,
|
|
'obrazky_predchozi' : obrazky_predchozi,
|
|
'obrazky_dalsi' : obrazky_dalsi,
|
|
'preview' : preview,
|
|
'umisteni_Fotogalerie' : True,
|
|
})
|
|
|
|
|