]> git.0d.be Git - django-panik-combo.git/blobdiff - panikombo/models.py
add topik cell
[django-panik-combo.git] / panikombo / models.py
index 102a5ed9799511f56916539e6996741b2a4ab21b..c587791c1e53621f62582f6ee5627da9bb88d7a2 100644 (file)
@@ -5,6 +5,7 @@ from django import template
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
+from ckeditor.fields import RichTextField
 from taggit.managers import TaggableManager
 
 from combo.data.models import CellBase
@@ -126,6 +127,8 @@ class NewsItemAutoSelectionCell(CellBase):
     title = models.CharField(_('Title'), max_length=50, blank=True)
     tags = TaggableManager(_('Tags'), blank=True)
     future = models.BooleanField(_('Future Events Only'), default=True)
+    category = models.ForeignKey('emissions.NewsCategory',
+            verbose_name=_('Category'), null=True, blank=True)
 
     class Meta:
         verbose_name = _('Automatic Newsitem Selection')
@@ -136,6 +139,9 @@ class NewsItemAutoSelectionCell(CellBase):
             newsitems_queryset = newsitems_queryset.filter(tags__in=self.tags.all())
         if self.future:
             newsitems_queryset = newsitems_queryset.filter(event_date__gte=date.today())
+        if self.category:
+            newsitems_queryset = newsitems_queryset.filter(category=self.category)
+        newsitems_queryset = newsitems_queryset.order_by('-event_date', '-creation_timestamp')
         return newsitems_queryset
 
     def render(self, context):
@@ -167,6 +173,11 @@ class Topik(models.Model):
     got_focus = models.DateTimeField(default=None, null=True, blank=True)
     has_focus = models.BooleanField(default=False)
 
+    def __unicode__(self):
+        if not self.page:
+            return super(Topik, self).__unicode__()
+        return unicode(self.page)
+
 
 class ItemTopik(models.Model):
     newsitem = models.ForeignKey('emissions.NewsItem', verbose_name=_('News Item'),
@@ -175,3 +186,19 @@ class ItemTopik(models.Model):
             null=True, blank=True)
     topik = models.ForeignKey('Topik', verbose_name='Topik',
             null=True, blank=True)
+
+
+@register_cell_class
+class TopikCell(CellBase):
+    topik = models.ForeignKey(Topik, null=True)
+    text = RichTextField(_('Text'), blank=True, null=True)
+
+    template_name = 'panikombo/topik-cell.html'
+
+    class Meta:
+        verbose_name = _('Topik')
+
+    def get_additional_label(self):
+        if not self.topik:
+            return ''
+        return self.topik.page.title