58 lines
2.2 KiB
Python
58 lines
2.2 KiB
Python
# combo - content management system
|
|
# Copyright (C) 2017 Entr'ouvert
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
# under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from django.contrib import messages
|
|
from django.http import HttpResponseRedirect
|
|
from django.views.generic import View, DetailView
|
|
from django.views.generic.detail import SingleObjectMixin
|
|
|
|
from .forms import BookingForm
|
|
from .models import BookingCalendar
|
|
from .utils import (get_form_url_with_params, get_chrono_events,
|
|
get_calendar_context_vars)
|
|
|
|
|
|
class BookingView(SingleObjectMixin, View):
|
|
|
|
http_method_names = ['post']
|
|
model = BookingCalendar
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
cell = self.get_object()
|
|
form = BookingForm(request.POST, cell=cell)
|
|
try:
|
|
form.is_valid()
|
|
except ValueError as exc:
|
|
messages.error(request, exc.message)
|
|
redirect_url = '%s?%s' % (
|
|
cell.page.get_online_url(), request.GET.urlencode())
|
|
return HttpResponseRedirect(redirect_url)
|
|
data = form.cleaned_data
|
|
url = get_form_url_with_params(cell, data)
|
|
return HttpResponseRedirect(url)
|
|
|
|
|
|
class CalendarContentAjaxView(DetailView):
|
|
model = BookingCalendar
|
|
template_name = 'calendar/booking_calendar_content.html'
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super(CalendarContentAjaxView, self).get_context_data(**kwargs)
|
|
context['cell'] = self.object
|
|
events_data = get_chrono_events(self.object.agenda_reference, context.get('synchronous'))
|
|
context.update(get_calendar_context_vars(self.request, self.object, events_data))
|
|
return context
|