Commit c6a69145 authored by fred's avatar fred

reworked handling of schedules

a single emission can be scheduled on different times (like "creation
radiophonique" on Monday, Wednesday and Friday)
parent 3e6c4cf1
......@@ -5,7 +5,7 @@ import unicodedata
from django import forms
from django.forms import fields
from .models import Emission, Episode, Diffusion
from .models import Emission, Episode, Diffusion, Schedule
def slugify(s):
s = unicodedata.normalize('NFKD', s).encode('ascii', 'ignore').lower()
......@@ -44,9 +44,6 @@ class EmissionForm(forms.ModelForm):
class Meta:
model = Emission
exclude = ('slug',)
widgets = {
'first_diffusion': DayAndHourWidget(),
}
def save(self, commit=True):
if not self.instance.slug:
......@@ -71,3 +68,12 @@ class EpisodeNewForm(EpisodeForm):
diffusion.datetime = self.cleaned_data.get('diffusion')
diffusion.save()
return episode
class ScheduleForm(forms.ModelForm):
class Meta:
model = Schedule
widgets = {
'emission': forms.HiddenInput(),
'datetime': DayAndHourWidget(),
}
......@@ -24,8 +24,6 @@ class Emission(models.Model):
text = RichTextField(null=True)
archived = models.BooleanField(default=False)
first_diffusion = models.DateTimeField(null=True)
categories = models.ManyToManyField(Category)
def get_absolute_url(self):
......@@ -35,6 +33,12 @@ class Emission(models.Model):
return self.title
class Schedule(models.Model):
emission = models.ForeignKey('Emission', verbose_name=u'Emission')
datetime = models.DateTimeField()
first = models.BooleanField(default=True)
class Episode(models.Model):
emission = models.ForeignKey('Emission', verbose_name=u'Emission')
title = models.CharField(max_length=50)
......
......@@ -19,6 +19,25 @@
{{ emission.text|safe }}
{% endif %}
<h3>Horaires</h3>
<ul>
{% for schedule in schedules %}
<li>{{ schedule.datetime|date:"l G:i" }}
<a href="schedule/{{ schedule.id }}/remove" class="icon-remove-sign" title="Retirer"></a>
</li>
{% endfor %}
</ul>
<a id="add-schedule-link" href="#">Ajouter un horaire de diffusion</a>
<form id="add-schedule-form" action="add-schedule" method="POST" style="display: none;">
{% csrf_token %}
{{ add_schedule_form.as_p }}
<input type="submit" value="Ajouter cet horaire"/>
</form>
<h3>Épisodes</h3>
<ul class="episode-list">
......@@ -30,4 +49,17 @@
<a href="add">New Episode</a> - <a href="edit/">Edit</a>
{% endblock %}
{% block page-end %}
<script>
$(function() {
$('#add-schedule-link').click(
function() {
$('#add-schedule-form').dialog({modal: true, title: 'Horaire', width: 'auto'});
});
});
</script>
{% endblock %}
......@@ -9,9 +9,14 @@ urlpatterns = patterns('',
url(r'^(?P<slug>[\w,-]+)/$', EmissionDetailView.as_view(), name='emission-view'),
url(r'^(?P<slug>[\w,-]+)/edit/$', EmissionUpdateView.as_view(), name='emission-update'),
url(r'^(?P<slug>[\w,-]+)/delete/$', EmissionDeleteView.as_view(), name='emission-delete'),
url(r'^(?P<slug>[\w,-]+)/add-schedule$', EmissionAddScheduleView.as_view(), name='emission-add-schedule'),
url(r'^(?P<emission_slug>[\w,-]+)/schedule/(?P<pk>\d+)/remove$',
ScheduleDeleteView.as_view(), name='schedule-delete'),
url(r'^(?P<emission_slug>[\w,-]+)/add$', EpisodeCreateView.as_view(), name='episode-add'),
url(r'^(?P<emission_slug>[\w,-]+)/(?P<slug>[\w,-]+)/$', EpisodeDetailView.as_view(), name='episode-view'),
url(r'^(?P<emission_slug>[\w,-]+)/(?P<slug>[\w,-]+)/edit/$', EpisodeUpdateView.as_view(), name='episode-update'),
url(r'^(?P<emission_slug>[\w,-]+)/(?P<slug>[\w,-]+)/delete/$', EpisodeDeleteView.as_view(), name='episode-delete'),
)
from django.core.urlresolvers import reverse_lazy
from django.core.urlresolvers import reverse, reverse_lazy
from django.views.generic.base import TemplateView
from django.views.generic.base import TemplateView, RedirectView
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from .models import Emission, Episode, Diffusion, Category
from .forms import EmissionForm, EpisodeForm, EpisodeNewForm
from .models import Emission, Episode, Diffusion, Category, Schedule
from .forms import EmissionForm, EpisodeForm, EpisodeNewForm, ScheduleForm
__all__ = ['EmissionListView', 'EmissionDetailView', 'EmissionCreateView',
'EmissionUpdateView', 'EmissionDeleteView',
'EpisodeCreateView', 'EpisodeDetailView', 'EpisodeUpdateView',
'EpisodeDeleteView',
'CategoryListView']
'EpisodeDeleteView', 'EmissionAddScheduleView',
'ScheduleDeleteView', 'CategoryListView']
class EmissionListView(ListView):
......@@ -35,7 +35,8 @@ class EmissionDetailView(DetailView):
def get_context_data(self, **kwargs):
context = super(EmissionDetailView, self).get_context_data(**kwargs)
#context['episodes'] = Episode.objects.filter(emission=self.object.id)
context['add_schedule_form'] = ScheduleForm(initial={'emission': self.object})
context['schedules'] = Schedule.objects.filter(emission=self.object)
context['episodes'] = Episode.objects.raw('''
SELECT emissions_episode.*,
datetime AS first_diffusion
......@@ -98,3 +99,17 @@ class EpisodeUpdateView(UpdateView):
class EpisodeDeleteView(DeleteView):
model = Episode
class EmissionAddScheduleView(CreateView):
form_class = ScheduleForm
model = Schedule
def get_success_url(self):
return self.object.emission.get_absolute_url()
class ScheduleDeleteView(RedirectView):
def get_redirect_url(self, emission_slug, pk):
Schedule.objects.filter(id=pk).delete()
return reverse('emission-view', kwargs={'slug': str(emission_slug)})
This diff is collapsed.
This diff is collapsed.
......@@ -313,6 +313,18 @@ ul.episode-list {
-webkit-column-count: 2;
}
[class^="icon-"]:before, [class*=" icon-"]:before {
font-family: FontAwesome;
font-weight: normal;
font-style: normal;
display: inline-block;
text-decoration: none;
}
a [class^="icon-"], a [class*=" icon-"] {
display: inline-block;
text-decoration: none;
}
.icon-edit:before { content: "\f044"; }
.icon-remove-sign:before { content: "\f057"; }
.icon-remove:before { content: "\f00d"; }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -7,6 +7,8 @@
<title>{% block page-title %}Panik DB{% endblock %}</title>
<link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/style.css"/>
<script src="{{ STATIC_URL }}js/jquery.js"></script>
<script src="{{ STATIC_URL }}js/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/smoothness/jquery-ui-1.10.0.custom.css"/>
{% block extrascripts %}
{% endblock %}
</head>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment