X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6d42bc478e3d1bd90eb294464748c21e4de0fc63..c6537f136f4ec0230f5e7c71dd1abf9616151a47:/src/social/models.py?ds=inline
diff --git a/src/social/models.py b/src/social/models.py
index 29029ee6b..e85298803 100644
--- a/src/social/models.py
+++ b/src/social/models.py
@@ -6,7 +6,7 @@ from django.db import models
from django.conf import settings
from django.core.exceptions import ValidationError
from django.urls import reverse
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import gettext_lazy as _, get_language
from catalogue.models import Book
from wolnelektury.utils import cached_render, clear_cached_renders
@@ -53,24 +53,16 @@ class Cite(models.Model):
sticky = models.BooleanField(_('sticky'), default=False, db_index=True,
help_text=_('Sticky cites will take precedense.'))
- banner = models.BooleanField(_('banner'), default=False, help_text=
- 'Dostosuj wielkoÅÄ do obrazu tÅa, zignoruj tekst.'
- '
(PrzestarzaÅe; użyj funkcji "Obraz" w sekcji "Media box")')
-
background_plain = models.BooleanField(_('plain background'), default=False)
background_color = models.CharField(_('background color'), max_length=32, blank=True)
image = models.ImageField(
- _('image'), upload_to='social/cite', null=True, blank=True,
- help_text=_('Best image is exactly 975px wide and weights under 100kB.'))
- image_shift = models.IntegerField(
- _('shift'), null=True, blank=True,
- help_text='PrzesuniÄcie w pionie, w procentach. 0 to wyrównanie do górnej krawÄdzi, 100 do dolnej. DomyÅlne jest 50%.'
- '
(PrzestarzaÅe; użyj obrazka o wÅaÅciwych proporcjach;)')
- image_title = models.CharField(_('title'), max_length=255, null=True, blank=True)
- image_author = models.CharField(_('author'), max_length=255, blank=True, null=True)
- image_link = models.URLField(_('link'), blank=True, null=True)
- image_license = models.CharField(_('license name'), max_length=255, blank=True, null=True)
- image_license_link = models.URLField(_('license link'), blank=True, null=True)
+ _('background image'), upload_to='social/cite', null=True, blank=True,
+ help_text=_('Best background is 975 x 315 px and under 100kB.'))
+ image_title = models.CharField(_('background title'), max_length=255, null=True, blank=True)
+ image_author = models.CharField(_('background author'), max_length=255, blank=True, null=True)
+ image_link = models.URLField(_('background link'), blank=True, null=True)
+ image_license = models.CharField(_('background license name'), max_length=255, blank=True, null=True)
+ image_license_link = models.URLField(_('background license link'), blank=True, null=True)
created_at = models.DateTimeField(_('created at'), auto_now_add=True)
group = models.ForeignKey(BannerGroup, verbose_name=_('group'), null=True, blank=True, on_delete=models.SET_NULL)
@@ -106,9 +98,6 @@ class Cite(models.Model):
return self.vip or self.text or self.book
def layout(self):
- if self.banner:
- # TODO: move all banners to pictures.
- return 'banner'
pieces = []
if self.has_box():
pieces.append('box')
@@ -134,25 +123,37 @@ class Cite(models.Model):
class Carousel(models.Model):
- slug = models.SlugField(_('slug'), unique=True)
+ placement = models.SlugField(_('placement'), choices=[
+ ('main', 'main'),
+ ('main_2022', 'main 2022'),
+ ])
+ priority = models.SmallIntegerField(_('priority'), default=0)
+ language = models.CharField(_('language'), max_length=2, blank=True, default='', choices=settings.LANGUAGES)
class Meta:
- ordering = ('slug',)
+# ordering = ('placement', '-priority')
verbose_name = _('carousel')
verbose_name_plural = _('carousels')
def __str__(self):
- return self.slug
+ 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)
+ order = models.PositiveSmallIntegerField(_('order'))
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')