X-Git-Url: https://git.0d.be/?p=django-panik-combo.git;a=blobdiff_plain;f=panikombo%2Fmodels.py;h=350f77e609fe11a3894a502929daede0bc985178;hp=558896239c9b903d1f8f8216eb3417c554eb9e8e;hb=a53294a17b610fa38589d1ebe223ddad42d07f11;hpb=e46d55da78c87c9ae4160ff7c5291a30e60d1436 diff --git a/panikombo/models.py b/panikombo/models.py index 5588962..350f77e 100644 --- a/panikombo/models.py +++ b/panikombo/models.py @@ -6,7 +6,9 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ from ckeditor.fields import RichTextField +from taggit.models import Tag from taggit.managers import TaggableManager +from taggit.utils import parse_tags from combo.data.models import CellBase from combo.data.library import register_cell_class @@ -80,10 +82,16 @@ class EpisodeCell(CellBase): return '' +def get_parsed_tags(tagstring): + tags = parse_tags(tagstring) + return [x for x in Tag.objects.filter(name__in=tags)] + + @register_cell_class class EpisodeAutoSelectionCell(CellBase): title = models.CharField(_('Title'), max_length=50, blank=True) tags = TaggableManager(_('Tags'), blank=True) + and_tags = models.CharField(_('And Tags'), max_length=100, blank=True) category = models.ForeignKey('emissions.Category', null=True, blank=True) period = models.PositiveSmallIntegerField( _('Period'), default=0, @@ -101,6 +109,9 @@ class EpisodeAutoSelectionCell(CellBase): episodes_queryset = episodes_queryset.filter(emission__categories__in=[self.category.id]) if self.tags.count(): episodes_queryset = episodes_queryset.filter(tags__in=self.tags.all()) + if self.and_tags: + and_tags = get_parsed_tags(self.and_tags) + episodes_queryset = episodes_queryset.filter(tags__in=and_tags) if self.period == 0: episodes_queryset = episodes_queryset.extra( @@ -153,6 +164,7 @@ class EpisodeAutoSelectionCell(CellBase): class NewsItemAutoSelectionCell(CellBase): title = models.CharField(_('Title'), max_length=50, blank=True) tags = TaggableManager(_('Tags'), blank=True) + and_tags = models.CharField(_('And Tags'), max_length=100, blank=True) future = models.BooleanField(_('Future Events Only'), default=True) category = models.ForeignKey('emissions.NewsCategory', verbose_name=_('Category'), null=True, blank=True) @@ -164,6 +176,9 @@ class NewsItemAutoSelectionCell(CellBase): newsitems_queryset = NewsItem.objects.select_related() if self.tags.count(): newsitems_queryset = newsitems_queryset.filter(tags__in=self.tags.all()) + if self.and_tags: + and_tags = get_parsed_tags(self.and_tags) + newsitems_queryset = newsitems_queryset.filter(tags__in=and_tags) if self.future: newsitems_queryset = newsitems_queryset.filter(event_date__gte=date.today()) if self.category: