73 lines
2.7 KiB
Python
73 lines
2.7 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/>.
|
|
|
|
import datetime
|
|
|
|
from django.conf import settings
|
|
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from combo.data.library import register_cell_class
|
|
from combo.data.models import CellBase
|
|
|
|
from .utils import get_calendar_context_vars, get_chrono_events, is_chrono_enabled, is_wcs_enabled
|
|
|
|
|
|
@register_cell_class
|
|
class BookingCalendar(CellBase):
|
|
|
|
title = models.CharField(_('Title'), max_length=128, blank=True, null=True)
|
|
agenda_reference = models.CharField(_('Agenda'), max_length=128)
|
|
formdef_reference = models.CharField(_('Form'), max_length=128)
|
|
slot_duration = models.DurationField(
|
|
_('Slot duration'),
|
|
default=datetime.timedelta(minutes=30),
|
|
help_text=_('Format is hours:minutes:seconds'),
|
|
)
|
|
minimal_booking_duration = models.DurationField(
|
|
_('Minimal booking duration'),
|
|
default=datetime.timedelta(hours=1),
|
|
help_text=_('Format is hours:minutes:seconds'),
|
|
)
|
|
days_displayed = models.PositiveSmallIntegerField(_('Number of days to display'), default=7)
|
|
|
|
default_template_name = 'calendar/booking_calendar_cell.html'
|
|
|
|
class Meta:
|
|
verbose_name = _('Booking Calendar')
|
|
|
|
def get_default_form_class(self):
|
|
from .forms import BookingCalendarForm
|
|
|
|
return BookingCalendarForm
|
|
|
|
@classmethod
|
|
def is_enabled(cls):
|
|
return settings.BOOKING_CALENDAR_CELL_ENABLED and is_chrono_enabled() and is_wcs_enabled()
|
|
|
|
def is_visible(self, request, **kwargs):
|
|
return self.agenda_reference and self.formdef_reference and super().is_visible(request, **kwargs)
|
|
|
|
def get_cell_extra_context(self, context):
|
|
if context.get('placeholder_search_mode'):
|
|
return {}
|
|
extra_context = super().get_cell_extra_context(context)
|
|
events_data = get_chrono_events(self.agenda_reference, not (context.get('synchronous')))
|
|
extra_context.update(
|
|
get_calendar_context_vars(context['request'], extra_context['cell'], events_data)
|
|
)
|
|
return extra_context
|