- 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(_('placement'), choices=[
+ ('main', 'main'),
+ ])
+ priority = models.SmallIntegerField(_('priority'), default=0)
+ language = models.CharField(_('language'), max_length=2, blank=True, default='', choices=settings.LANGUAGES)
+
+ class Meta:
+# ordering = ('placement', '-priority')
+ verbose_name = _('carousel')
+ verbose_name_plural = _('carousels')
+
+ def __str__(self):
+ return self.placement
+
+ @classmethod
+ def get(cls, placement):
+ carousel = cls.objects.filter(models.Q(language='') | models.Q(language=get_language()), 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(_('order'), unique=True)
+ carousel = models.ForeignKey(Carousel, models.CASCADE, verbose_name=_('carousel'))
+ 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=_('banner group'))
+
+ class Meta:
+ ordering = ('order',)
+ unique_together = [('carousel', 'order')]
+ verbose_name = _('carousel item')
+ verbose_name_plural = _('carousel items')
+
+ 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(_('Either banner or banner group is required.'))
+ elif self.banner and self.banner_group:
+ raise ValidationError(_('Either banner or banner group is required.'))
+
+ def get_banner(self):
+ return self.banner or self.banner_group.get_banner()