From 68fe3fd4a42f4d3ee02ce2bc7fc12cf48334d0bb Mon Sep 17 00:00:00 2001 From: Josue Kouka Date: Wed, 17 May 2017 18:19:07 +0200 Subject: [PATCH 1/3] add calendar cell model (#16393) --- combo/apps/chrono/README | 10 ++++ combo/apps/chrono/__init__.py | 28 ++++++++++ combo/apps/chrono/models.py | 71 ++++++++++++++++++++++++ combo/apps/chrono/templates/chrono/base.html | 9 +++ combo/apps/chrono/templates/chrono/calendar.html | 10 ++++ combo/settings.py | 1 + 6 files changed, 129 insertions(+) create mode 100644 combo/apps/chrono/README create mode 100644 combo/apps/chrono/__init__.py create mode 100644 combo/apps/chrono/models.py create mode 100644 combo/apps/chrono/templates/chrono/base.html create mode 100644 combo/apps/chrono/templates/chrono/calendar.html diff --git a/combo/apps/chrono/README b/combo/apps/chrono/README new file mode 100644 index 0000000..7049345 --- /dev/null +++ b/combo/apps/chrono/README @@ -0,0 +1,10 @@ +Combo calendar cell +================= + +To be visible, this cell needs a 'chrono' entry in settings.KNOWN_SERVICES + +session_vars are defineed such as: +{ + "my_session_var1_name": "value", + "my_session_var2_name": "ref_to_received_key", +} diff --git a/combo/apps/chrono/__init__.py b/combo/apps/chrono/__init__.py new file mode 100644 index 0000000..45e59d6 --- /dev/null +++ b/combo/apps/chrono/__init__.py @@ -0,0 +1,28 @@ +# combo - content management system +# Copyright (C) 2015 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 . + +import django.apps + + +class AppConfig(django.apps.AppConfig): + name = 'combo.apps.chrono' + + def get_before_urls(self): + from . import urls + return urls.urlpatterns + + +default_app_config = 'combo.apps.chrono.AppConfig' diff --git a/combo/apps/chrono/models.py b/combo/apps/chrono/models.py new file mode 100644 index 0000000..5e8cee5 --- /dev/null +++ b/combo/apps/chrono/models.py @@ -0,0 +1,71 @@ +# combo - content management system +# Copyright (C) 2015 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 . + +import json +from datetime import datetime + +from django.db import models +from django.utils.translation import ugettext_lazy as _ +from django.utils.dateparse import parse_time +from django.core.urlresolvers import reverse + +from combo.data.models import CellBase +from combo.data.library import register_cell_class +from .utils import is_chrono_enabled + +from jsonfield import JSONField + + +@register_cell_class +class CalendarCell(CellBase): + + title = models.CharField(_('Title'), max_length=128) + events_source = models.URLField(_('Events source URL')) + form_url = models.URLField(_('Application form URL')) + session_vars = JSONField(_('Session vars')) + slot_duration = models.TimeField( + _('Slot duration'), default=parse_time('00:30')) + business_hours_start = models.TimeField( + _('Business hour start'), default=parse_time('08:00')) + business_hours_end = models.TimeField( + _('Business hour end'), default=parse_time('18:00')) + event_default_title = models.CharField( + _('Event default title'), max_length=32) + + template_name = 'chrono/calendar.html' + + class Meta: + verbose_name = _('Calendar Cell') + + class Media: + js = ( + 'chrono/lib/moment.min.js', + 'chrono/fullcalendar.min.js', + 'chrono/chrono.js' + ) + css = {'all': ('chrono/fullcalendar.min.css', 'chrono/chrono.css',)} + + @classmethod + def is_enabled(cls): + return is_chrono_enabled + + def render(self, context): + context['events_source_url'] = reverse('chrono-events', kwargs={'pk': self.pk}) + context['events_booking_url'] = reverse('chrono-booking', kwargs={'pk': self.pk}) + include = ['slot_duration', 'business_hours_start', 'business_hours_end', 'event_default_title'] + context['chrono'] = json.dumps({key: str(value) for key, value in vars(self).items() + if key in include}) + return super(CalendarCell, self).render(context) diff --git a/combo/apps/chrono/templates/chrono/base.html b/combo/apps/chrono/templates/chrono/base.html new file mode 100644 index 0000000..0191a31 --- /dev/null +++ b/combo/apps/chrono/templates/chrono/base.html @@ -0,0 +1,9 @@ +{% load staticfiles i18n %} + +{% block scripts %} + + + + + +{% endblock %} diff --git a/combo/apps/chrono/templates/chrono/calendar.html b/combo/apps/chrono/templates/chrono/calendar.html new file mode 100644 index 0000000..1e154d1 --- /dev/null +++ b/combo/apps/chrono/templates/chrono/calendar.html @@ -0,0 +1,10 @@ +

Calendar

+ + + +
+
diff --git a/combo/settings.py b/combo/settings.py index 0f0247d..e631696 100644 --- a/combo/settings.py +++ b/combo/settings.py @@ -75,6 +75,7 @@ INSTALLED_APPS = ( 'combo.apps.notifications', 'combo.apps.search', 'combo.apps.usersearch', + 'combo.apps.chrono', 'haystack', 'xstatic.pkg.chartnew_js', ) -- 2.11.0