Merge branch 'master' of atrey.karlin.mff.cuni.cz:/akce/MaM/MaMweb/mamweb
This commit is contained in:
commit
f309affdd8
5 changed files with 85 additions and 33 deletions
|
@ -3,6 +3,9 @@
|
|||
from galerie.models import Obrazek, Galerie
|
||||
from django.contrib import admin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django import forms
|
||||
from django.db import models
|
||||
import autocomplete_light
|
||||
|
||||
# akction
|
||||
|
||||
|
@ -27,17 +30,25 @@ def prepnout_fotogalerii_do_org_rezimu(modeladmin, request, queryset):
|
|||
'Přepnout do režimu úprav (zneveřejní galerii)'
|
||||
|
||||
class GalerieInline(admin.TabularInline):
|
||||
model = Obrazek
|
||||
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')
|
||||
list_display = ('obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag')
|
||||
|
||||
class GalerieAdmin(admin.ModelAdmin):
|
||||
model = Galerie
|
||||
fields = ('zobrazit', 'nazev', 'titulni_obrazek', 'popis', 'galerie_up', 'soustredeni', 'poradi')
|
||||
list_display = ('nazev', 'pk', 'datum_zmeny', 'zobrazit', 'soustredeni')
|
||||
inlines = [GalerieInline]
|
||||
actions = [zverejnit_fotogalerii, prepnout_fotogalerii_do_org_rezimu]
|
||||
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', 'pk', 'poradi', 'datum_zmeny', 'zobrazit', 'soustredeni')
|
||||
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)
|
||||
|
|
49
galerie/autocomplete_light_registry.py
Normal file
49
galerie/autocomplete_light_registry.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import autocomplete_light
|
||||
|
||||
from models import Obrazek, Galerie
|
||||
from views import cesta_od_korene
|
||||
|
||||
|
||||
class ObrazekAutocomplete(autocomplete_light.AutocompleteModelBase):
|
||||
|
||||
model = Obrazek
|
||||
search_fields = ['nazev', 'popis']
|
||||
split_words = True
|
||||
limit_choices = 15
|
||||
attrs = {
|
||||
# This will set the input placeholder attribute:
|
||||
'placeholder': u'Obrázek',
|
||||
# This will set the yourlabs.Autocomplete.minimumCharacters
|
||||
# options, the naming conversion is handled by jQuery
|
||||
'data-autocomplete-minimum-characters': 1,
|
||||
}
|
||||
|
||||
choice_html_format = '''
|
||||
<span class="block" data-value="{}">
|
||||
<span class="block">
|
||||
{}
|
||||
<span class="block">{}</span>
|
||||
</span>
|
||||
</span>
|
||||
'''
|
||||
|
||||
def choice_label(self, obrazek):
|
||||
cesta = "/".join(g.nazev for g in cesta_od_korene(obrazek.galerie))
|
||||
popis = "{}<br>".format(obrazek.popis) if obrazek.popis else ""
|
||||
return '{}<br>{}{}'.format(obrazek.nazev, popis, cesta)
|
||||
|
||||
def choice_html(self, obrazek):
|
||||
"""Vrátí kus html i s obrázkem, které se pak ukazuje v nabídce"""
|
||||
return self.choice_html_format.format(self.choice_value(obrazek),
|
||||
obrazek.obrazek_maly_tag(), self.choice_label(obrazek))
|
||||
|
||||
widget_attrs={
|
||||
'data-widget-maximum-values': 15,
|
||||
'class': 'modern-style',
|
||||
}
|
||||
|
||||
autocomplete_light.register(ObrazekAutocomplete)
|
|
@ -56,6 +56,12 @@ class Obrazek(models.Model):
|
|||
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
|
||||
|
||||
|
||||
|
||||
class Galerie(models.Model):
|
||||
|
|
|
@ -22,23 +22,9 @@ M&M je korespondeční seminář. Několikrát do roka zdarma vydáváme ča
|
|||
<div class="odpocet">
|
||||
<p><b>Do konce <a href="https://mam.mff.cuni.cz/zadani/aktualni/">odeslání řešení</a> zbývá:<br>
|
||||
<big>{{ted|timesince:dead}}</big></b></p>
|
||||
|
||||
|
||||
<!--
|
||||
{{cas_do_konce_dni}} dní
|
||||
{% if cas_do_konce_dni < 5 %}
|
||||
{{cas_do_konce_hodin}} hodin
|
||||
{% if cas_do_konce_hodin < 5 %}
|
||||
{{cas_do_konce_minut}} minut
|
||||
{% if cas_do_konce_minut < 5 %}
|
||||
{{cas_do_konce_sekund}}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
-->
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Novinky #}
|
||||
<h2>Novinky</h2>
|
||||
{% include 'seminar/novinky.html' %}
|
||||
|
|
|
@ -73,16 +73,16 @@ class TitulniStranaView(generic.ListView):
|
|||
context = super(TitulniStranaView, self).get_context_data(**kwargs)
|
||||
nastaveni = get_object_or_404(Nastaveni)
|
||||
cas_deadline = nastaveni.aktualni_cislo.datum_deadline
|
||||
try:
|
||||
rozdil_casu = datetime.combine(cas_deadline, datetime.max.time()) \
|
||||
- datetime.now()
|
||||
context['cas_do_konce_dni'] = rozdil_casu.days
|
||||
context['cas_do_konce_hodin'] = rozdil_casu.seconds / 3600
|
||||
context['cas_do_konce_minut'] = (rozdil_casu.seconds / 60) % 60
|
||||
context['cas_do_konce_sekund'] = rozdil_casu.seconds % 60
|
||||
context['dead'] = datetime.combine(cas_deadline, datetime.max.time())
|
||||
context['ted'] = datetime.now()
|
||||
except:
|
||||
# Pokud neni zverejnene cislo nezverejnuj odpocet
|
||||
if nastaveni.aktualni_cislo.verejne():
|
||||
# pokus se zjistit termin odeslani a pokud neni zadany,
|
||||
# nezverejnuj odpocet
|
||||
try:
|
||||
context['dead'] = datetime.combine(cas_deadline, datetime.max.time())
|
||||
context['ted'] = datetime.now()
|
||||
except:
|
||||
context['dead'] = None
|
||||
else:
|
||||
context['dead'] = None
|
||||
return context
|
||||
|
||||
|
|
Loading…
Reference in a new issue