Merge branch 'master' of atrey.karlin.mff.cuni.cz:/akce/MaM/MaMweb/mamweb
This commit is contained in:
		
						commit
						38b42d2d3f
					
				
					 10 changed files with 192 additions and 92 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 | ||||
| 
 | ||||
|  | @ -28,16 +31,24 @@ def prepnout_fotogalerii_do_org_rezimu(modeladmin, request, queryset): | |||
| 
 | ||||
| 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}, | ||||
|     } | ||||
| 
 | ||||
| class ObrazekAdmin(admin.ModelAdmin): | ||||
|   list_display = ('obrazek_velky', 'nazev', 'popis') | ||||
|     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', 'pk', 'datum_zmeny', 'zobrazit', 'soustredeni') | ||||
|     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) | ||||
|  | @ -57,6 +57,12 @@ class Obrazek(models.Model): | |||
|     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): | ||||
|   nazev = models.CharField('Název', max_length=100) | ||||
|  |  | |||
|  | @ -6,6 +6,10 @@ Galerie {{galerie.nazev}} | |||
| 
 | ||||
| {% block content %} | ||||
| 
 | ||||
|   {% if galerie.zobrazit > 0 %} | ||||
|     <div class="mam-org-only"> | ||||
|   {% endif %} | ||||
| 
 | ||||
|   <h2> | ||||
|     {% for g in cesta %} | ||||
|       {% if not forloop.last %} | ||||
|  | @ -19,7 +23,7 @@ Galerie {{galerie.nazev}} | |||
|   {% if not obrazky %} | ||||
|    <div class="galerie_hlavicka"> | ||||
|     {% if galerie.titulni_obrazek %} | ||||
|       <img src="{{ galerie.titulni_obrazek.obrazek_stredni.url }}" style="border: 1px solid black;"> | ||||
|       <img src="{{ galerie.titulni_obrazek.obrazek_stredni.url }}" class="titulni_obrazek"> | ||||
|     {% endif %} | ||||
|    </div> | ||||
|   {% endif %} | ||||
|  | @ -45,8 +49,8 @@ Galerie {{galerie.nazev}} | |||
|             {% if galerie.titulni_obrazek %} | ||||
|             {% with galerie.titulni_obrazek.obrazek_maly as obrazek %} | ||||
|             <img src="{{ obrazek.url }}" | ||||
|                 width="{{ obrazek.width }}" | ||||
|                 height="{{ obrazek.height }}" /> | ||||
|                 width="{% widthratio obrazek.width 167 obrazek.width %}" | ||||
|                 height="{% widthratio obrazek.width 167 obrazek.height %}" /> | ||||
|             {% endwith %} | ||||
|             {% endif %} | ||||
|             <div> | ||||
|  | @ -103,4 +107,9 @@ Galerie {{galerie.nazev}} | |||
|       </div> | ||||
|     {% endif %} | ||||
|   {% endif %} | ||||
| 
 | ||||
|   {% if galerie.zobrazit > 0 %} | ||||
|     </div> {# mam-org-only #} | ||||
|   {% endif %} | ||||
| 
 | ||||
| {% endblock content %} | ||||
|  |  | |||
|  | @ -18,6 +18,15 @@ body { | |||
|   border: orange 2px dashed; | ||||
| } | ||||
| 
 | ||||
| .mam-org-only .mam-org-only { | ||||
|     border: 0px; | ||||
| } | ||||
| 
 | ||||
| li.mam-org-only { | ||||
|     padding: 3px 0px; | ||||
|     margin: -2px 0px; | ||||
| } | ||||
| 
 | ||||
| table .border-r { | ||||
|   border-right: solid 1px; | ||||
| } | ||||
|  | @ -446,7 +455,8 @@ div.zadani_azad_termin { | |||
| /* galerie */ | ||||
| 
 | ||||
| /* velká fotka */ | ||||
| .galerie .obrazek { | ||||
| /* zmenšování spolu s oknem prohlížeče */ | ||||
| .galerie .obrazek, .titulni_obrazek { | ||||
|     max-width: 100%; | ||||
|     height: auto; | ||||
|     width: auto\9; /* ie8 */ | ||||
|  | @ -482,7 +492,6 @@ div.zadani_azad_termin { | |||
| .galerie { | ||||
|   position: relative; | ||||
|   text-align: center; | ||||
|   /*width: 100%;*/ | ||||
|   margin: 20px auto 0 auto; | ||||
| } | ||||
| 
 | ||||
|  | @ -503,6 +512,11 @@ div.zadani_azad_termin { | |||
|   text-align: center; | ||||
| } | ||||
| 
 | ||||
| /* titulní obrázek hlavní galerie soustředění */ | ||||
| .titulni_obrazek { | ||||
|     border: 1px solid black; | ||||
| } | ||||
| 
 | ||||
| .galerie_nahledy{ | ||||
|   /*margin: 1em 0;*/ | ||||
|   margin: 0 auto 30px auto; | ||||
|  |  | |||
|  | @ -334,7 +334,7 @@ create_modeladmin(ProblemNavrhAdmin, Problem, 'ProblemNavrh', verbose_name=u'Pro | |||
| 
 | ||||
| class ProblemZadanyAdmin(ProblemAdmin): | ||||
|     list_display = ['nazev', 'typ', 'autor', 'opravovatel', 'kod', 'cislo_zadani', 'pocet_reseni', 'verejne'] | ||||
|     list_filter = ['typ', 'cislo_zadani__cislo', 'cislo_zadani__rocnik'] | ||||
|     list_filter = ['typ', 'zamereni', 'cislo_zadani__cislo', 'cislo_zadani__rocnik'] | ||||
|     inlines = [ReseniKProblemuInline] | ||||
| 
 | ||||
|     def get_queryset(self, request): | ||||
|  |  | |||
|  | @ -27,6 +27,16 @@ | |||
|   {% endfor %} | ||||
|   </ul> | ||||
| 
 | ||||
|   {% if user.is_staff %} | ||||
|   	<div class="mam-org-only"> | ||||
| 	<h3> Orgovské odkazy </h3> | ||||
| 	<ul> | ||||
| 		<li><a href="obalky.pdf">Obálky (PDF)</a></li> | ||||
| 		<li><a href="tituly.tex">Tituly (TeX)</a></li> | ||||
| 	</ul> | ||||
| 	</div> | ||||
|   {% endif %} | ||||
| 
 | ||||
|   {% if cislo.verejna_vysledkovka %} | ||||
|   <h3>Výsledkovka</h3> | ||||
|   {% else %} | ||||
|  |  | |||
|  | @ -21,13 +21,10 @@ | |||
|   {# Projdi vsechna soustredeni #} | ||||
|   {% for soustredeni in object_list %} | ||||
|     {# Kdyz je verejne -> zobraz #} | ||||
|     {% if soustredeni.verejne_db or user.is_authenticated %} | ||||
|       {% if not soustredeni.verejne_db and user.is_authenticated %} | ||||
|         Groups of user: {{user.groups.all}} <br> | ||||
|         <!-- TODO pri prihlasovani ucastniku dodelat prava | ||||
|         jen na group org ve view --> | ||||
|         Toto soustředění není veřejné, vidíte ho jen proto, | ||||
|         že jste přihlášení. <br> | ||||
|     {% if soustredeni.verejne_db or user.is_staff %} | ||||
|       {% if not soustredeni.verejne_db and user.is_staff %} | ||||
|         <div class="mam-org-only"> | ||||
|         <!--Groups of user: {{user.groups.all}} <br>--> | ||||
|       {% endif %} | ||||
|       {# misto soustredeni TODO upravit#} | ||||
|       <h2> | ||||
|  | @ -42,7 +39,7 @@ | |||
|         {% if soustredeni.galerie_set.all %} | ||||
|           {% for galerie in soustredeni.galerie_set.all %} | ||||
|             {% if galerie.zobrazit == 0 or user.is_staff %} | ||||
|         <li> | ||||
|               <li {% if galerie.zobrazit > 0 and user.is_staff %}class="mam-org-only"{% endif %}> | ||||
|                 <a href="../{{soustredeni.pk}}/fotogalerie/{{galerie.pk}}">Fotogalerie</a> | ||||
|                 {# TODO kdyz je titulni obrazek, tak asi i titulni obrazek #} | ||||
|               </li> | ||||
|  | @ -73,6 +70,9 @@ | |||
|         {% endfor %} | ||||
|         </ul> | ||||
|       {% endif %} | ||||
|       {% if not soustredeni.verejne_db and user.is_staff %} | ||||
|         </div> {# class="mam-org-only" #} | ||||
|       {% endif %} | ||||
|     {% endif %} | ||||
|     {% empty %} | ||||
|       Žádná soustředění zatím neproběhla! | ||||
|  |  | |||
|  | @ -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' %} | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ from django.core.urlresolvers import reverse | |||
| from django.views import generic | ||||
| from django.utils.translation import ugettext as _ | ||||
| from django.http import Http404 | ||||
| from django.db.models import Q | ||||
| 
 | ||||
| from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici | ||||
| from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva | ||||
|  | @ -72,17 +73,17 @@ 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 | ||||
|         # Pokud neni zverejnene cislo nezverejnuj odpocet | ||||
|         if nastaveni.aktualni_cislo.verejne(): | ||||
|           # pokus se zjistit termin odeslani a pokud neni zadany, | ||||
|           # nezverejnuj odpocet | ||||
|           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: | ||||
|               context['dead'] = None | ||||
|         else: | ||||
|             context['dead'] = None | ||||
|         return context | ||||
| 
 | ||||
| class StareNovinkyView(generic.ListView): | ||||
|  | @ -344,28 +345,42 @@ class RocnikVysledkovkaView(RocnikView): | |||
| 
 | ||||
| ### Generovani obalek | ||||
| class CisloObalkyStruct: | ||||
|     resitele = None | ||||
|     rocnik = None | ||||
|     problemy = None | ||||
|     cisla = None | ||||
| 
 | ||||
| def cisloObalkyView(request,rocnik,cislo): | ||||
| 
 | ||||
| # Vraci QuerySet aktualnich resitelu = nekdy neco poslali, ale jeste neodmaturovali | ||||
| def aktualniResitele(rocnik): | ||||
|     letos = Rocnik.objects.filter(rocnik = rocnik).first() | ||||
|     return Resitel.objects.filter(rok_maturity__gt = letos.prvni_rok) | ||||
| #   # ALERT: pokud nekdo nema vypleny rok maturity, tak neni aktualni, protoze Karel Tesar a jini | ||||
| #    return Resitel.objects.filter(Q(rok_maturity__gt = letos.prvni_rok)|Q(rok_maturity = None)) | ||||
|      | ||||
| # Vraci QuerySet aktivnich resitelu =  | ||||
| # jeste neodmaturovali &&  | ||||
| # (pokud je aktualni cislo mensi nez 3, pak (letos || loni) neco poslali | ||||
| # jinak letos neco poslali) | ||||
| def aktivniResitele(rocnik,cislo): | ||||
|     letos = CisloObalkyStruct() | ||||
|     loni = CisloObalkyStruct() | ||||
| 
 | ||||
|     letos.rocnik = Rocnik.objects.filter(rocnik = rocnik)[0] | ||||
|     loni.rocnik = Rocnik.objects.filter(rocnik = int(rocnik)-1)[0] | ||||
|     letos.problemy = Problem.objects.filter(cislo_zadani = Cislo.objects.filter(rocnik=letos.rocnik,cislo__lte = cislo)) | ||||
|     loni.problemy = Problem.objects.filter(cislo_zadani = Cislo.objects.filter(rocnik=loni.rocnik)) | ||||
|     letos.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=letos.problemy)).distinct() | ||||
|     loni.resitele = Resitel.objects.filter(reseni = Reseni.objects.filter(problem=loni.problemy)).distinct() | ||||
| 
 | ||||
|     loni.resitele = loni.resitele.filter(rok_maturity__gt =  letos.rocnik.prvni_rok) | ||||
|     aktualni_resitele = aktualniResitele(rocnik) | ||||
|      | ||||
|     letos.rocnik = Rocnik.objects.filter(rocnik = rocnik).first() | ||||
|     loni.rocnik = Rocnik.objects.filter(rocnik = int(rocnik)-1).first() | ||||
|     letos.cisla = Cislo.objects.filter(rocnik=letos.rocnik,cislo__lte = cislo) | ||||
|     loni.cisla = Cislo.objects.filter(rocnik=loni.rocnik)  | ||||
|     if int(cislo) > 3: | ||||
|         resitele = letos.resitele | ||||
|         problemy = Problem.objects.filter(cislo_zadani = letos.cisla) | ||||
|     else: | ||||
|         resitele = list(letos.resitele) + list(loni.resitele) | ||||
|     return obalkyView(request,resitele) | ||||
|         problemy = Problem.objects.filter(Q(cislo_zadani = letos.cisla)|Q(cislo_zadani=loni.cisla)) | ||||
|     resitele = aktualni_resitele.filter(reseni = Reseni.objects.filter(problem=problemy)).distinct() | ||||
| 
 | ||||
|     return resitele | ||||
|      | ||||
| 
 | ||||
| def cisloObalkyView(request,rocnik,cislo): | ||||
|     return obalkyView(request,aktivniResitele(rocnik,cislo)) | ||||
| 
 | ||||
| 
 | ||||
| def obalkyView(request,resitele): | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Aneta
						Aneta