from emissions.models import SoundFile, Episode
-from .models import SoundCell, EpisodeCell, EpisodeAutoSelectionCell
+from .models import (SoundCell, EpisodeCell, EpisodeAutoSelectionCell,
+ NewsItemAutoSelectionCell)
from .views import soundfiles, episodes
class SoundFileWidget(HeavySelect2Widget):
model = EpisodeAutoSelectionCell
fields = ('title', 'tags', 'category')
widgets = {'tags': TagWidget()}
+
+
+class NewsItemAutoSelectionCellForm(forms.ModelForm):
+ class Meta:
+ model = NewsItemAutoSelectionCell
+ fields = ('title', 'tags', 'future')
+ widgets = {'tags': TagWidget()}
--- /dev/null
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import taggit.managers
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('auth', '0001_initial'),
+ ('data', '0005_auto_20150226_0903'),
+ ('taggit', '0001_initial'),
+ ('panikombo', '0003_episodeautoselectioncell'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='NewsItemAutoSelectionCell',
+ 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')),
+ ('title', models.CharField(max_length=50, verbose_name='Title', blank=True)),
+ ('future', models.BooleanField(default=True, verbose_name='Future Events Only')),
+ ('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
+ ('page', models.ForeignKey(to='data.Page')),
+ ('tags', taggit.managers.TaggableManager(to='taggit.Tag', through='taggit.TaggedItem', blank=True, help_text='A comma-separated list of tags.', verbose_name='Tags')),
+ ],
+ options={
+ 'verbose_name': 'Automatic Newsitem Selection',
+ },
+ bases=(models.Model,),
+ ),
+ ]
+from datetime import date
+
from django import template
from django.db import models
from django.utils.translation import ugettext_lazy as _
from combo.data.models import CellBase
from combo.data.library import register_cell_class
-from emissions.models import Episode
+from emissions.models import Episode, NewsItem
@register_cell_class
class SoundCell(CellBase):
episodes_queryset = Episode.objects.select_related()
if self.category:
episodes_queryset = episodes_queryset.filter(emission__categories__in=[self.category.id])
- if self.tags:
+ if self.tags.count():
episodes_queryset = episodes_queryset.filter(tags__in=self.tags.all())
episodes_queryset = episodes_queryset.extra(select={
def get_default_form_class(self):
from .forms import EpisodeAutoSelectionCellForm
return EpisodeAutoSelectionCellForm
+
+
+@register_cell_class
+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)
+
+ class Meta:
+ verbose_name = _('Automatic Newsitem Selection')
+
+ def render(self, context):
+ tmpl = template.loader.get_template('panikombo/newsitem_auto_selection.html')
+ context['title'] = self.title
+
+ newsitems_queryset = NewsItem.objects.select_related()
+ if self.tags.count():
+ newsitems_queryset = newsitems_queryset.filter(tags__in=self.tags.all())
+ if self.future:
+ newsitems_queryset = newsitems_queryset.filter(event_date__gte=date.today())
+
+ context['newsitems'] = newsitems_queryset
+ return tmpl.render(context)
+
+ def get_default_form_class(self):
+ from .forms import NewsItemAutoSelectionCellForm
+ return NewsItemAutoSelectionCellForm