galerie | moznost radit podgalerie podle cisla poradi
This commit is contained in:
parent
7d1bda5fce
commit
1a8cfec157
5 changed files with 71 additions and 2 deletions
39
galerie/migrations/0003_add_galerie_poradi.py
Normal file
39
galerie/migrations/0003_add_galerie_poradi.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
import galerie.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('galerie', '0002_auto_20151013_1145'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='galerie',
|
||||
name='poradi',
|
||||
field=models.IntegerField(null=True, verbose_name=b'Po\xc5\x99ad\xc3\xad', blank=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='obrazek',
|
||||
name='obrazek_maly',
|
||||
field=models.ImageField(upload_to=galerie.models.obrazek_filename_maly, null=True, editable=False),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='obrazek',
|
||||
name='obrazek_stredni',
|
||||
field=models.ImageField(upload_to=galerie.models.obrazek_filename_stredni, null=True, editable=False),
|
||||
preserve_default=True,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='obrazek',
|
||||
name='obrazek_velky',
|
||||
field=models.ImageField(help_text=b'Lze vlo\xc5\xbeit libovoln\xc4\x9b velk\xc3\xbd obr\xc3\xa1zek. Ide\xc3\xa1ln\xc3\xad je, aby alespo\xc5\x88 jeden rozm\xc4\x9br m\xc4\x9bl alespo\xc5\x88 500px.', upload_to=galerie.models.obrazek_filename),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -147,6 +147,7 @@ class Galerie(models.Model):
|
|||
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
|
||||
|
|
|
@ -8,15 +8,20 @@
|
|||
<h2>{{galerie.nazev}}</h2>
|
||||
|
||||
{# podgalerie #}
|
||||
{% if galerie.galerie_set.all or galerie.galerie_up %}
|
||||
{% if podgalerie or galerie.galerie_up %}
|
||||
<h3> PODGALERIE </h3>
|
||||
<ul>
|
||||
{% if galerie.galerie_up %}
|
||||
<li><a href="../{{galerie.galerie_up.pk}}">..</a>
|
||||
{% endif %}
|
||||
{% for galerie in galerie.galerie_set.all %}
|
||||
{% for galerie in podgalerie %}
|
||||
{% if galerie.zobrazit < 1 or user.is_staff %}
|
||||
<li><a href="../{{galerie.pk}}">{{galerie}}</a>
|
||||
{% if user.is_staff and galerie.zobrazit > 0 %}
|
||||
({{galerie.poradi}})
|
||||
<span class="plus"><a href="plus/{{galerie.pk}}/">+</a></span>
|
||||
<span class="minus"><a href="minus/{{galerie.pk}}/">-</a></span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -6,5 +6,7 @@ urlpatterns = patterns('',
|
|||
(r'^(?P<pk>\d+)/$', 'galerie.views.nahled'),
|
||||
(r'^(?P<pk>\d+)/(?P<fotka>\d+)/$', 'galerie.views.detail'),
|
||||
(r'^(?P<galerie>\d+)/new/$', 'galerie.views.new_galerie'),
|
||||
(r'^(?P<galerie>\d+)/plus/(?P<subgalerie>\d+)/$', 'galerie.views.plus_galerie'),
|
||||
(r'^(?P<galerie>\d+)/minus/(?P<subgalerie>\d+)/$', 'galerie.views.minus_galerie'),
|
||||
)
|
||||
|
||||
|
|
|
@ -23,10 +23,12 @@ def zobrazit(galerie, request):
|
|||
def nahled(request, pk, soustredeni):
|
||||
"""Zobrazeni nahledu vsech fotek ve skupine."""
|
||||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
podgalerie = Galerie.objects.filter(galerie_up = galerie).order_by('poradi')
|
||||
obrazky = Obrazek.objects.filter(galerie = galerie).order_by('datum')
|
||||
preview = zobrazit(galerie, request)
|
||||
return render(request, 'galerie/GalerieNahled.html',
|
||||
{'galerie' : galerie,
|
||||
'podgalerie' : podgalerie,
|
||||
'obrazky' : obrazky,
|
||||
'preview' : preview,
|
||||
})
|
||||
|
@ -121,6 +123,7 @@ def new_galerie(request, galerie, soustredeni):
|
|||
gal.galerie_up = galerie_up
|
||||
else:
|
||||
gal.soustredeni = soustredeni
|
||||
gal.poradi = int(len(gal.galerie_up.galerie_set.all())) + 1
|
||||
gal.save()
|
||||
|
||||
# zpracovani obrazku v galerii
|
||||
|
@ -144,3 +147,22 @@ def new_galerie(request, galerie, soustredeni):
|
|||
'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('../../')
|
||||
|
||||
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('../../')
|
||||
|
||||
|
|
Loading…
Reference in a new issue