add Topik object, wrapper around Page
authorFrédéric Péters <fpeters@0d.be>
Mon, 25 May 2015 14:18:19 +0000 (16:18 +0200)
committerFrédéric Péters <fpeters@0d.be>
Mon, 25 May 2015 14:18:19 +0000 (16:18 +0200)
panikombo/forms.py
panikombo/migrations/0005_topik.py [new file with mode: 0644]
panikombo/models.py
panikombo/templates/panikombo/topik_form.html [new file with mode: 0644]
panikombo/views.py

index b4b4ef7..d7a20a6 100644 (file)
@@ -5,7 +5,7 @@ from taggit.forms import TagWidget
 from emissions.models import SoundFile, Episode
 
 from .models import (SoundCell, EpisodeCell, EpisodeAutoSelectionCell,
-        NewsItemAutoSelectionCell)
+        NewsItemAutoSelectionCell, Topik)
 from .views import soundfiles, episodes
 
 class SoundFileWidget(HeavySelect2Widget):
@@ -60,3 +60,9 @@ class NewsItemAutoSelectionCellForm(forms.ModelForm):
         model = NewsItemAutoSelectionCell
         fields = ('title', 'tags', 'future')
         widgets = {'tags': TagWidget()}
+
+
+class TopikEditForm(forms.ModelForm):
+    class Meta:
+        model = Topik
+        fields = ('image',)
diff --git a/panikombo/migrations/0005_topik.py b/panikombo/migrations/0005_topik.py
new file mode 100644 (file)
index 0000000..226df96
--- /dev/null
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import panikombo.models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('data', '0005_auto_20150226_0903'),
+        ('panikombo', '0004_newsitemautoselectioncell'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Topik',
+            fields=[
+                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('image', models.ImageField(max_length=250, upload_to=panikombo.models.get_topik_image_path, null=True, verbose_name='Image', blank=True)),
+                ('got_focus', models.DateTimeField(default=None, null=True, blank=True)),
+                ('has_focus', models.BooleanField(default=False)),
+                ('page', models.ForeignKey(to='data.Page')),
+            ],
+            options={
+            },
+            bases=(models.Model,),
+        ),
+    ]
index 4a6ab48..4f9baeb 100644 (file)
@@ -1,4 +1,5 @@
 from datetime import date
+import os
 
 from django import template
 from django.db import models
@@ -137,3 +138,17 @@ class NewsItemAutoSelectionCell(CellBase):
         if self.title:
             return self.title
         return ''
+
+
+def get_topik_image_path(instance, filename):
+    return os.path.join('images', 'topik', instance.page.slug,
+            os.path.basename(filename))
+
+class Topik(models.Model):
+    page = models.ForeignKey('data.Page')
+    image = models.ImageField(_('Image'),
+            upload_to=get_topik_image_path, max_length=250, null=True, blank=True)
+
+    # denormalized from Focus
+    got_focus = models.DateTimeField(default=None, null=True, blank=True)
+    has_focus = models.BooleanField(default=False)
diff --git a/panikombo/templates/panikombo/topik_form.html b/panikombo/templates/panikombo/topik_form.html
new file mode 100644 (file)
index 0000000..fed894e
--- /dev/null
@@ -0,0 +1,22 @@
+{% extends "combo/manager_base.html" %}
+{% load i18n %}
+
+{% block appbar %}
+<h2>{% trans 'Topik Options' %}</h2>
+{% endblock %}
+
+{% block content %}
+<form method="post" enctype="multipart/form-data">
+{% csrf_token %}
+{{form.as_p}}
+  <div class="buttons">
+    <button>{% trans "Save" %}</button>
+    {% if object.id %}
+    <a class="cancel" href="{{ object.get_absolute_url }}">{% trans 'Cancel' %}</a>
+    {% else %}
+    <a class="cancel" href="{% url 'combo-manager-homepage' %}">{% trans 'Cancel' %}</a>
+    {% endif %}
+  </div>
+</form>
+{% endblock %}
+
index 7af24d7..a76ac84 100644 (file)
@@ -1,7 +1,10 @@
+from django.core.urlresolvers import reverse
 from django.db.models import Q
+from django.views.generic.edit import UpdateView
 import django_select2
 
 from emissions.models import SoundFile, Episode
+from .models import Topik
 
 class SoundFilesView(django_select2.views.Select2View):
     def get_results(self, request, terms, page, context):
@@ -30,3 +33,16 @@ class EpisodesView(django_select2.views.Select2View):
         return ('nil', False, ((x.id, fmt(x)) for x in queryset.select_related()))
 
 episodes = EpisodesView.as_view()
+
+
+class TopikEdit(UpdateView):
+    model = Topik
+
+    def get_form_class(self):
+        from .forms import TopikEditForm
+        return TopikEditForm
+
+    def get_success_url(self):
+        return reverse('combo-manager-page-view', kwargs={'pk': self.object.page.id})
+
+topik_edit = TopikEdit.as_view()