initial version
authorFrédéric Péters <fpeters@0d.be>
Thu, 12 Mar 2015 16:52:26 +0000 (17:52 +0100)
committerFrédéric Péters <fpeters@0d.be>
Thu, 12 Mar 2015 16:52:26 +0000 (17:52 +0100)
.gitignore [new file with mode: 0644]
AUTHORS [new file with mode: 0644]
MANIFEST.in [new file with mode: 0644]
panikombo/__init__.py [new file with mode: 0644]
panikombo/forms.py [new file with mode: 0644]
panikombo/migrations/0001_initial.py [new file with mode: 0644]
panikombo/migrations/__init__.py [new file with mode: 0644]
panikombo/models.py [new file with mode: 0644]
panikombo/views.py [new file with mode: 0644]
setup.py [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..5dc1306
--- /dev/null
@@ -0,0 +1,5 @@
+*.pyc
+*.swp
+/dist
+/panikombo.egg-info
+django.mo
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..73a960c
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Frederic Peters <fred@radiopanik.ogr>
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644 (file)
index 0000000..7f82931
--- /dev/null
@@ -0,0 +1,3 @@
+include AUTHORS
+include COPYING
+include README
diff --git a/panikombo/__init__.py b/panikombo/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/panikombo/forms.py b/panikombo/forms.py
new file mode 100644 (file)
index 0000000..57f0329
--- /dev/null
@@ -0,0 +1,27 @@
+from django import forms
+from django_select2.widgets import HeavySelect2Widget, convert_to_js_string_arr
+
+from emissions.models import SoundFile
+
+from .models import SoundCell
+from .views import soundfiles
+
+class SoundFileWidget(HeavySelect2Widget):
+    def render_texts(self, selected_choices, choices):
+        queryset = SoundFile.objects.filter(id__in=selected_choices)
+        def fmt(soundfile):
+            return '%s - %s - %s' % (soundfile.episode.emission.title,
+                    soundfile.episode.title,
+                    soundfile.title or soundfile.id)
+        texts = [fmt(soundfile) for soundfile in queryset.select_related()]
+        return convert_to_js_string_arr(texts)
+
+
+class SoundCellForm(forms.ModelForm):
+    class Meta:
+        model = SoundCell
+        fields = ('soundfile',)
+
+    def __init__(self, *args, **kwargs):
+        super(SoundCellForm, self).__init__(*args, **kwargs)
+        self.fields['soundfile'].widget = SoundFileWidget(data_view=soundfiles)
diff --git a/panikombo/migrations/0001_initial.py b/panikombo/migrations/0001_initial.py
new file mode 100644 (file)
index 0000000..fef818b
--- /dev/null
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('auth', '0001_initial'),
+        ('emissions', '0001_initial'),
+        ('data', '0005_auto_20150226_0903'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='SoundCell',
+            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')),
+                ('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
+                ('page', models.ForeignKey(to='data.Page')),
+                ('soundfile', models.ForeignKey(to='emissions.SoundFile', null=True)),
+            ],
+            options={
+                'verbose_name': 'Sound',
+            },
+            bases=(models.Model,),
+        ),
+    ]
diff --git a/panikombo/migrations/__init__.py b/panikombo/migrations/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/panikombo/models.py b/panikombo/models.py
new file mode 100644 (file)
index 0000000..96021a0
--- /dev/null
@@ -0,0 +1,22 @@
+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
+
+@register_cell_class
+class SoundCell(CellBase):
+    soundfile = models.ForeignKey('emissions.SoundFile', null=True)
+
+    class Meta:
+        verbose_name = _('Sound')
+
+    def render(self, context):
+        tmpl = template.loader.get_template('panikombo/audio.html')
+        context['soundfile'] = self.soundfile
+        return tmpl.render(context)
+
+    def get_default_form_class(self):
+        from .forms import SoundCellForm
+        return SoundCellForm
diff --git a/panikombo/views.py b/panikombo/views.py
new file mode 100644 (file)
index 0000000..9fc516d
--- /dev/null
@@ -0,0 +1,19 @@
+from django.db.models import Q
+import django_select2
+
+from emissions.models import SoundFile
+
+class SoundFilesView(django_select2.views.Select2View):
+    def get_results(self, request, terms, page, context):
+        queryset = SoundFile.objects.all()
+        for term in terms.split():
+            queryset = queryset.filter(Q(title__icontains=term) |
+                    Q(episode__title__icontains=term) |
+                    Q(episode__emission__title__icontains=term))
+        def fmt(soundfile):
+            return '%s - %s - %s' % (soundfile.episode.emission.title,
+                    soundfile.episode.title,
+                    soundfile.title or soundfile.id)
+        return ('nil', False, ((x.id, fmt(x)) for x in queryset.select_related()))
+
+soundfiles = SoundFilesView.as_view()
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..232076e
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,35 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+try:
+    from setuptools import setup
+except ImportError:
+    from ez_setup import use_setuptools
+    use_setuptools()
+    from setuptools import setup
+
+
+setup(
+    name='panikombo',
+    version='0.1',
+    description='Combo extensions for Radio Panik',
+    author='Frederic Peters',
+    author_email='fred@radiopanik.org',
+    packages=[
+        'panikombo',
+        'panikombo.migrations',
+    ],
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Environment :: Web Environment',
+        'Framework :: Django',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
+        'Topic :: Multimedia :: Sound/Audio',
+    ],
+    zip_safe=False,
+)