add topik cell
authorFrédéric Péters <fpeters@0d.be>
Sun, 31 May 2015 13:20:56 +0000 (15:20 +0200)
committerFrédéric Péters <fpeters@0d.be>
Sun, 31 May 2015 13:20:56 +0000 (15:20 +0200)
panikombo/migrations/0008_topikcell.py [new file with mode: 0644]
panikombo/models.py

diff --git a/panikombo/migrations/0008_topikcell.py b/panikombo/migrations/0008_topikcell.py
new file mode 100644 (file)
index 0000000..e117285
--- /dev/null
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import ckeditor.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('auth', '0001_initial'),
+        ('data', '0009_auto_20150529_2247'),
+        ('panikombo', '0007_newsitemautoselectioncell_category'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='TopikCell',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('placeholder', models.CharField(max_length=20)),
+                ('order', models.PositiveIntegerField()),
+                ('slug', models.SlugField(verbose_name='Slug', blank=True)),
+                ('public', models.BooleanField(default=True, verbose_name='Public')),
+                ('text', ckeditor.fields.RichTextField(null=True, verbose_name='Text', blank=True)),
+                ('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
+                ('page', models.ForeignKey(to='data.Page')),
+                ('topik', models.ForeignKey(to='panikombo.Topik', null=True)),
+            ],
+            options={
+                'verbose_name': 'Topik',
+            },
+            bases=(models.Model,),
+        ),
+    ]
index 617212a..c587791 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
@@ -172,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'),
@@ -180,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