0001-add-calendar-cell-model-16393.patch
combo/apps/chrono/README | ||
---|---|---|
1 |
Combo calendar cell |
|
2 |
================= |
|
3 | ||
4 |
To be visible, this cell needs a 'chrono' entry in settings.KNOWN_SERVICES |
|
5 | ||
6 |
session_vars are defineed such as: |
|
7 |
{ |
|
8 |
"my_session_var1_name": "value", |
|
9 |
"my_session_var2_name": "ref_to_received_key", |
|
10 |
} |
combo/apps/chrono/__init__.py | ||
---|---|---|
1 |
# combo - content management system |
|
2 |
# Copyright (C) 2015 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
import django.apps |
|
18 | ||
19 | ||
20 |
class AppConfig(django.apps.AppConfig): |
|
21 |
name = 'combo.apps.chrono' |
|
22 | ||
23 |
def get_before_urls(self): |
|
24 |
from . import urls |
|
25 |
return urls.urlpatterns |
|
26 | ||
27 | ||
28 |
default_app_config = 'combo.apps.chrono.AppConfig' |
combo/apps/chrono/models.py | ||
---|---|---|
1 |
# combo - content management system |
|
2 |
# Copyright (C) 2015 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
import json |
|
18 |
from datetime import datetime |
|
19 | ||
20 |
from django.db import models |
|
21 |
from django.utils.translation import ugettext_lazy as _ |
|
22 |
from django.utils.dateparse import parse_time |
|
23 |
from django.core.urlresolvers import reverse |
|
24 | ||
25 |
from combo.data.models import CellBase |
|
26 |
from combo.data.library import register_cell_class |
|
27 |
from .utils import is_chrono_enabled |
|
28 | ||
29 |
from jsonfield import JSONField |
|
30 | ||
31 | ||
32 |
@register_cell_class |
|
33 |
class CalendarCell(CellBase): |
|
34 | ||
35 |
title = models.CharField(_('Title'), max_length=128) |
|
36 |
events_source = models.URLField(_('Events source URL')) |
|
37 |
form_url = models.URLField(_('Application form URL')) |
|
38 |
session_vars = JSONField(_('Session vars')) |
|
39 |
slot_duration = models.TimeField( |
|
40 |
_('Slot duration'), default=parse_time('00:30')) |
|
41 |
business_hours_start = models.TimeField( |
|
42 |
_('Business hour start'), default=parse_time('08:00')) |
|
43 |
business_hours_end = models.TimeField( |
|
44 |
_('Business hour end'), default=parse_time('18:00')) |
|
45 |
event_default_title = models.CharField( |
|
46 |
_('Event default title'), max_length=32) |
|
47 | ||
48 |
template_name = 'chrono/calendar.html' |
|
49 | ||
50 |
class Meta: |
|
51 |
verbose_name = _('Calendar Cell') |
|
52 | ||
53 |
class Media: |
|
54 |
js = ( |
|
55 |
'chrono/lib/moment.min.js', |
|
56 |
'chrono/fullcalendar.min.js', |
|
57 |
'chrono/chrono.js' |
|
58 |
) |
|
59 |
css = {'all': ('chrono/fullcalendar.min.css', 'chrono/chrono.css',)} |
|
60 | ||
61 |
@classmethod |
|
62 |
def is_enabled(cls): |
|
63 |
return is_chrono_enabled |
|
64 | ||
65 |
def render(self, context): |
|
66 |
context['events_source_url'] = reverse('chrono-events', kwargs={'pk': self.pk}) |
|
67 |
context['events_booking_url'] = reverse('chrono-booking', kwargs={'pk': self.pk}) |
|
68 |
include = ['slot_duration', 'business_hours_start', 'business_hours_end', 'event_default_title'] |
|
69 |
context['chrono'] = json.dumps({key: str(value) for key, value in vars(self).items() |
|
70 |
if key in include}) |
|
71 |
return super(CalendarCell, self).render(context) |
combo/apps/chrono/templates/chrono/base.html | ||
---|---|---|
1 |
{% load staticfiles i18n %} |
|
2 | ||
3 |
{% block scripts %} |
|
4 |
<link rel='stylesheet' href='calendar/fullcalendar.css' /> |
|
5 |
<script src='lib/jquery.min.js'></script> |
|
6 |
<script src='lib/moment.min.js'></script> |
|
7 |
<script src='fullcalendar/fullcalendar.js'></script> |
|
8 |
<script src='chrono.js'></script> |
|
9 |
{% endblock %} |
combo/apps/chrono/templates/chrono/calendar.html | ||
---|---|---|
1 |
<h2>Calendar</h2> |
|
2 | ||
3 |
<script type="text/javascript"> |
|
4 |
var events_source_url = "{{events_source_url}}"; |
|
5 |
var events_booking_url = "{{events_booking_url}}"; |
|
6 |
var chrono = JSON.parse(unescape('{{chrono | safe }}')); |
|
7 |
</script> |
|
8 | ||
9 |
<div id="calendar"> |
|
10 |
</div> |
combo/settings.py | ||
---|---|---|
75 | 75 |
'combo.apps.notifications', |
76 | 76 |
'combo.apps.search', |
77 | 77 |
'combo.apps.usersearch', |
78 |
'combo.apps.chrono', |
|
78 | 79 |
'haystack', |
79 | 80 |
'xstatic.pkg.chartnew_js', |
80 | 81 |
) |
81 |
- |