Merge branch 'master' into stable
Kvůli starým galeriím
This commit is contained in:
		
						commit
						d948653e33
					
				
					 3 changed files with 73 additions and 35 deletions
				
			
		|  | @ -31,36 +31,54 @@ def obrazek_filename_velky(): | |||
| def obrazek_filename(self, filename): | ||||
|     gal = self.galerie | ||||
|     cislo_gal = force_unicode(gal.pk) | ||||
|     cesta = "" | ||||
|     while(not gal.soustredeni): | ||||
| 
 | ||||
|     # najdi kořenovou galerii | ||||
|     while (gal.galerie_up): | ||||
|         gal = gal.galerie_up | ||||
|     return os.path.join('Galerie', "soustredeni_" + force_unicode(gal.soustredeni.pk), "galerie_" + cislo_gal, "velky", force_unicode(self.nazev)) | ||||
| 
 | ||||
|     # soustředění je v cestě jen pokud galerie pod nějaké patří | ||||
|     cesta = ( | ||||
|         ['Galerie'] + | ||||
|         (["soustredeni_" + force_unicode(gal.soustredeni.pk)] if gal.soustredeni else []) + | ||||
|         ["galerie_" + cislo_gal, force_unicode(self.nazev)] | ||||
|     ) | ||||
| 
 | ||||
|     return os.path.join(*cesta) | ||||
| 
 | ||||
| class Obrazek(models.Model): | ||||
|   obrazek_velky = models.ImageField(upload_to=obrazek_filename, | ||||
|     help_text = "Lze vložit libovolně velký obrázek. Ideální je, aby alespoň jeden rozměr měl alespoň 500px.") | ||||
|   obrazek_stredni = ImageSpecField(source='obrazek_velky', | ||||
|                                 processors=[Transpose(Transpose.AUTO), ResizeToFit(900, 675, upscale=False)], | ||||
|                                 options={'quality': 95}) | ||||
|   obrazek_maly = ImageSpecField(source='obrazek_velky', | ||||
|                                 processors=[Transpose(Transpose.AUTO), ResizeToFit(167, 167, upscale=False)], | ||||
|                                 options={'quality': 95}) | ||||
|   nazev = models.CharField('Název', max_length=50, blank = True, null = True) | ||||
|   popis = models.TextField('Popis', blank = True, null = True) | ||||
|   datum_vlozeni = models.DateTimeField('Datum vložení', auto_now_add = True) | ||||
|   galerie = models.ForeignKey('Galerie', blank=True, null=True) | ||||
|   poradi = models.IntegerField('Pořadí', blank = True, null = True) | ||||
|   def __unicode__(self): | ||||
|     return self.nazev + " -- " + unicode(self.obrazek_velky.name) | ||||
|   class Meta: | ||||
|     verbose_name = 'Obrázek' | ||||
|     verbose_name_plural = 'Obrázky' | ||||
|     ordering = ['nazev'] | ||||
|     obrazek_velky = models.ImageField(upload_to=obrazek_filename, | ||||
|       help_text = "Lze vložit libovolně velký obrázek. Ideální je, aby alespoň jeden rozměr měl alespoň 500px.") | ||||
|     obrazek_stredni = ImageSpecField(source='obrazek_velky', | ||||
|                                   processors=[Transpose(Transpose.AUTO), ResizeToFit(900, 675, upscale=False)], | ||||
|                                   options={'quality': 95}) | ||||
|     obrazek_maly = ImageSpecField(source='obrazek_velky', | ||||
|                                   processors=[Transpose(Transpose.AUTO), ResizeToFit(167, 167, upscale=False)], | ||||
|                                   options={'quality': 95}) | ||||
|     nazev = models.CharField('Název', max_length=50, blank=True, null=True) | ||||
|     popis = models.TextField('Popis', blank=True, null=True) | ||||
|     datum_vlozeni = models.DateTimeField('Datum vložení', auto_now_add=True) | ||||
|     galerie = models.ForeignKey('Galerie', blank=True, null=True) | ||||
|     poradi = models.IntegerField('Pořadí', blank=True, null=True) | ||||
| 
 | ||||
|   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 | ||||
|     def __unicode__(self): | ||||
|           return unicode(self.obrazek_velky.name) | ||||
| 
 | ||||
|     class Meta: | ||||
|       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 | ||||
| 
 | ||||
|     def save(self, *args, **kwargs): | ||||
|         # obrázek potřebuje název, protože se z něj generuje cesta pro jeho uložení | ||||
|         # (a pak se podle něj taky řadí) | ||||
|         if self.nazev is None: | ||||
|             self.nazev = os.path.basename(self.obrazek_velky.name) | ||||
|         super(Obrazek, self).save(*args, **kwargs) | ||||
| 
 | ||||
|    | ||||
| 
 | ||||
|  |  | |||
|  | @ -43,18 +43,22 @@ Galerie {{galerie.nazev}} | |||
|     {% endif %} | ||||
| 
 | ||||
|     {% if podgalerie %} | ||||
|       {% with 22 as max_delka_nazvu %} | ||||
|       <div class="galerie_nahledy"> | ||||
|       {% for galerie in podgalerie %} | ||||
|         <a href="../{{galerie.pk}}" class="podgalerie_nahled"> | ||||
|         <a href="../{{galerie.pk}}" | ||||
|           {% if galerie.nazev|length > max_delka_nazvu %} | ||||
|             title="{{ galerie.nazev }}" | ||||
|           {% endif %} | ||||
|          class="podgalerie_nahled"> | ||||
|             {% if galerie.titulni_obrazek %} | ||||
|             {% with galerie.titulni_obrazek.obrazek_maly as obrazek %} | ||||
|             <img src="{{ obrazek.url }}" | ||||
|                 width="{% widthratio obrazek.width 167 obrazek.width %}" | ||||
|                 height="{% widthratio obrazek.width 167 obrazek.height %}" /> | ||||
|             {% endwith %} | ||||
|               {% with galerie.titulni_obrazek.obrazek_maly as obrazek %} | ||||
|                 <img src="{{ obrazek.url }}" | ||||
|                 /> | ||||
|               {% endwith %} | ||||
|             {% endif %} | ||||
|             <div> | ||||
|             {{ galerie }} | ||||
|             <div class="nazev_galerie"> | ||||
|             {{ galerie|truncatechars:max_delka_nazvu }} | ||||
|             </div> | ||||
|         </a> | ||||
|         {% if user.is_staff and galerie.zobrazit > 0 %} | ||||
|  | @ -66,6 +70,7 @@ Galerie {{galerie.nazev}} | |||
|         {% endif %} | ||||
|       {% endfor %} | ||||
|       </div> | ||||
|       {% endwith %} | ||||
|     {% endif %} | ||||
|   {% endif %} | ||||
|   {% if user.is_staff and galerie.zobrazit > 0 %} | ||||
|  | @ -78,8 +83,15 @@ Galerie {{galerie.nazev}} | |||
|   {% if obrazky %} | ||||
|   <div class="galerie_nahledy"> | ||||
|     {% for obrazek in obrazky %} | ||||
|         <a title="Zobrazit tuto fotografii" href="./{{obrazek.pk}}#nahoru" class="galerie_nahled"><span class="vystredeno"></span><img | ||||
|         <a | ||||
|             {% if obrazek.popis %} | ||||
|               title="{{ obrazek.popis }}" | ||||
|             {% endif %} | ||||
|             href="./{{obrazek.pk}}#nahoru" class="galerie_nahled"><span class="vystredeno"></span><img | ||||
|             src="{{obrazek.obrazek_maly.url}}" | ||||
|             {% if obrazek.popis %} | ||||
|               title="{{ obrazek.popis }}" | ||||
|             {% endif %} | ||||
|             width="{{ obrazek.obrazek_maly.width }}" | ||||
|             height="{{ obrazek.obrazek_maly.height }}" /> | ||||
|         </a> | ||||
|  |  | |||
|  | @ -613,6 +613,14 @@ div.zadani_azad_termin { | |||
| .podgalerie_nahled img { | ||||
|     margin-top: 20px; | ||||
|     margin-bottom: 15px; | ||||
|     max-height: 125px; | ||||
|     max-width: 167px; | ||||
| } | ||||
| 
 | ||||
| .podgalerie_nahled .nazev_galerie { | ||||
|     position: absolute; | ||||
|     width: 100%; | ||||
|     top: 160px; | ||||
| } | ||||
| 
 | ||||
| /* plus a minus tlacitka */ | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Matěj Kocián
						Matěj Kocián