# Radioco - Broadcasting Radio Recording Scheduling system.
# Copyright (C) 2014 Iago Veloso Abalo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import datetime
import json
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.http import HttpResponseBadRequest
from django.shortcuts import render
from django.utils import timezone
from django.utils.dateparse import parse_datetime
from django.views.generic import FormView
from radioco.apps.global_settings.models import CalendarConfiguration
from radioco.apps.radioco.tz_utils import transform_dt_to_default_tz
from radioco.apps.radioco.utils import GetObjectMixin, DeletePermissionMixin
from radioco.apps.schedules.forms import DeleteScheduleForm
from radioco.apps.schedules.models import Schedule
[docs]def schedule_list(request):
calendar_configuration = CalendarConfiguration.get_global()
context = {
'min_time': calendar_configuration.min_time.strftime('%H:%M:%S'),
'max_time': calendar_configuration.max_time.strftime('%H:%M:%S'),
'slot_duration': unicode(calendar_configuration.slot_duration),
'first_day': calendar_configuration.first_day + 1,
'language': request.LANGUAGE_CODE,
'transmissions': reverse('api:transmission-list'),
}
return render(request, 'schedules/schedules_list.html', context)
[docs]class DeleteScheduleView(GetObjectMixin, DeletePermissionMixin, FormView):
template_name = 'admin/schedules/delete_modal.html'
form_class = DeleteScheduleForm
model = Schedule
schedule_id = None
transmission_dt = None
[docs] def get(self, request, *args, **kwargs):
try:
self.transmission_dt = parse_datetime(request.GET['transmission_dt'])
except ValueError:
pass
if not self.transmission_dt:
return HttpResponseBadRequest('Invalid request! transmission_dt is invalid.')
return super(DeleteScheduleView, self).get(request, *args, **kwargs)
[docs] def get_initial(self):
return {
'schedule': self.object,
'transmission_dt': self.transmission_dt,
}
[docs] def get_context_data(self, **kwargs):
context = super(DeleteScheduleView, self).get_context_data(**kwargs)
context['schedule'] = self.object
context['transmission_dt'] = self.transmission_dt
return context