- def flush_includes(self):
- flush_ssi_includes([
- template % (self.pk, lang)
- for template in [
- '/ludzie/cite/%s.%s.html',
- '/ludzie/cite_main/%s.%s.html',
- ]
- for lang in [lc for (lc, _ln) in settings.LANGUAGES]] +
- ['/ludzie/cite_info/%s.html' % self.pk])
+ @cached_render('social/cite_promo.html')
+ def main_box(self):
+ return {
+ 'cite': self,
+ 'main': True,
+ }
+
+ def clear_cache(self):
+ clear_cached_renders(self.main_box)
+
+
+class Carousel(models.Model):
+ placement = models.SlugField('miejsce', choices=[
+ ('main', 'main'),
+ ('main_2022', 'main 2022'),
+ ])
+ priority = models.SmallIntegerField('priorytet', default=0)
+ language = models.CharField('język', max_length=2, blank=True, default='', choices=settings.LANGUAGES)
+
+ class Meta:
+# ordering = ('placement', '-priority')
+ verbose_name = 'karuzela'
+ verbose_name_plural = 'karuzele'
+
+ def __str__(self):
+ return self.placement
+
+ @classmethod
+ def get(cls, placement):
+ carousel = cls.objects.filter(placement=placement).order_by('-priority', '?').first()
+ if carousel is None:
+ carousel = cls.objects.create(placement=placement)
+ return carousel
+
+
+class CarouselItem(models.Model):
+ order = models.PositiveSmallIntegerField('kolejność')
+ carousel = models.ForeignKey(Carousel, models.CASCADE, verbose_name='karuzela')
+ banner = models.ForeignKey(
+ Cite, models.CASCADE, null=True, blank=True, verbose_name='banner')
+ banner_group = models.ForeignKey(
+ BannerGroup, models.CASCADE, null=True, blank=True, verbose_name='grupa bannerów')
+
+ class Meta:
+ ordering = ('order',)
+ verbose_name = 'element karuzeli'
+ verbose_name_plural = 'elementy karuzeli'
+
+ def __str__(self):
+ return str(self.banner or self.banner_group)
+
+ def clean(self):
+ if not self.banner and not self.banner_group:
+ raise ValidationError('Proszę wskazać banner albo grupę bannerów.')
+ elif self.banner and self.banner_group:
+ raise ValidationError('Proszę wskazać banner albo grupę bannerów.')
+
+ def get_banner(self):
+ return self.banner or self.banner_group.get_banner()