--- /dev/null
+*.pyc
+*.swp
+/dist
+/panikombo.egg-info
+django.mo
--- /dev/null
+Frederic Peters <fred@radiopanik.ogr>
--- /dev/null
+include AUTHORS
+include COPYING
+include README
--- /dev/null
+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)
--- /dev/null
+# -*- 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,),
+ ),
+ ]
--- /dev/null
+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
--- /dev/null
+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()
--- /dev/null
+#! /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,
+)