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.
126 lines
3.5 KiB
126 lines
3.5 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
|
|
|
|
from galerie.forms import KomentarForm, NewGalerieForm
|
|
|
|
|
|
#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 zobrazit(galerie, request):
|
|
preview = False
|
|
if galerie.zobrazit >= 1:
|
|
if request.user.is_staff:
|
|
preview = True;
|
|
else:
|
|
raise Http404
|
|
return preview
|
|
|
|
|
|
def nahled(request, pk, soustredeni):
|
|
"""Zobrazeni nahledu vsech fotek ve skupine."""
|
|
galerie = get_object_or_404(Galerie, pk=pk)
|
|
preview = zobrazit(galerie, request)
|
|
return render(request, 'galerie/GalerieNahled.html',
|
|
{'galerie' : galerie,
|
|
'preview' : preview,
|
|
})
|
|
|
|
def detail(request, pk, fotka, soustredeni):
|
|
"""Zobrazeni nahledu fotky s id 'fotka'."""
|
|
MAX_VYSKA = 600
|
|
MAX_SIRKA = 600
|
|
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()
|
|
|
|
# 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
|
|
|
|
# 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,
|
|
'form' : form,
|
|
})
|
|
|
|
|
|
def new_galerie(request, galerie, soustredeni):
|
|
if request.method == 'POST':
|
|
form = NewGalerieForm(request.POST, request.FILES)
|
|
if form.is_valid():
|
|
# TODO dopsat vytvoreni fotogalerie
|
|
for obr in request.FILES.getlist('obr'):
|
|
pass # TODO dopsat ulozeni obrazku
|
|
# TODO presmerovani na nove vytvořenou galerii
|
|
|
|
else:
|
|
form = NewGalerieForm()
|
|
|
|
return render(request, 'galerie/GalerieNew.html',
|
|
{
|
|
'form' : form,
|
|
})
|
|
|