]> git.0d.be Git - django-panik-combo.git/blobdiff - panikombo/forms.py
add Topik object, wrapper around Page
[django-panik-combo.git] / panikombo / forms.py
index 57f0329ff1229f04573008fd4b777fb1b52474c7..d7a20a6fe0d7092973ae6e95f53995742cb16054 100644 (file)
@@ -1,10 +1,12 @@
 from django import forms
 from django_select2.widgets import HeavySelect2Widget, convert_to_js_string_arr
 from django import forms
 from django_select2.widgets import HeavySelect2Widget, convert_to_js_string_arr
+from taggit.forms import TagWidget
 
 
-from emissions.models import SoundFile
+from emissions.models import SoundFile, Episode
 
 
-from .models import SoundCell
-from .views import soundfiles
+from .models import (SoundCell, EpisodeCell, EpisodeAutoSelectionCell,
+        NewsItemAutoSelectionCell, Topik)
+from .views import soundfiles, episodes
 
 class SoundFileWidget(HeavySelect2Widget):
     def render_texts(self, selected_choices, choices):
 
 class SoundFileWidget(HeavySelect2Widget):
     def render_texts(self, selected_choices, choices):
@@ -25,3 +27,42 @@ class SoundCellForm(forms.ModelForm):
     def __init__(self, *args, **kwargs):
         super(SoundCellForm, self).__init__(*args, **kwargs)
         self.fields['soundfile'].widget = SoundFileWidget(data_view=soundfiles)
     def __init__(self, *args, **kwargs):
         super(SoundCellForm, self).__init__(*args, **kwargs)
         self.fields['soundfile'].widget = SoundFileWidget(data_view=soundfiles)
+
+
+class EpisodeWidget(HeavySelect2Widget):
+    def render_texts(self, selected_choices, choices):
+        queryset = Episode.objects.filter(id__in=selected_choices)
+        def fmt(episode):
+            return '%s - %s' % (episode.emission.title, episode.title)
+        texts = [fmt(episode) for episode in queryset.select_related()]
+        return convert_to_js_string_arr(texts)
+
+
+class EpisodeCellForm(forms.ModelForm):
+    class Meta:
+        model = EpisodeCell
+        fields = ('episode', )
+
+    def __init__(self, *args, **kwargs):
+        super(EpisodeCellForm, self).__init__(*args, **kwargs)
+        self.fields['episode'].widget = EpisodeWidget(data_view=episodes)
+
+
+class EpisodeAutoSelectionCellForm(forms.ModelForm):
+    class Meta:
+        model = EpisodeAutoSelectionCell
+        fields = ('title', 'tags', 'category')
+        widgets = {'tags': TagWidget()}
+
+
+class NewsItemAutoSelectionCellForm(forms.ModelForm):
+    class Meta:
+        model = NewsItemAutoSelectionCell
+        fields = ('title', 'tags', 'future')
+        widgets = {'tags': TagWidget()}
+
+
+class TopikEditForm(forms.ModelForm):
+    class Meta:
+        model = Topik
+        fields = ('image',)