67 lines
2.3 KiB
Python
67 lines
2.3 KiB
Python
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
from django.conf import settings
|
|
from django.db import models
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from combo.data.library import register_cell_class
|
|
from combo.data.models import JsonCellBase
|
|
|
|
|
|
@register_cell_class
|
|
class WeeklyAgendaCell(JsonCellBase):
|
|
title = models.CharField(_('Title'), max_length=150, blank=True)
|
|
agenda_reference = models.CharField(_('Agenda'), max_length=128)
|
|
user_external_template = models.CharField(max_length=255)
|
|
|
|
default_template_name = 'family/weekly_agenda.html'
|
|
force_async = True
|
|
|
|
class Meta:
|
|
verbose_name = _('Weekly agenda cell')
|
|
|
|
class Media:
|
|
js = ('js/combo.weekly_agenda.js',)
|
|
css = {'all': ('css/combo.weekly_agenda.css',)}
|
|
|
|
@classmethod
|
|
def is_enabled(cls):
|
|
return settings.PUBLIK_FAMILY_CELL_ENABLED
|
|
|
|
@property
|
|
def url(self):
|
|
chrono = list(settings.KNOWN_SERVICES.get('chrono').values())[0]
|
|
chrono_url = chrono.get('url') or ''
|
|
if not chrono_url.endswith('/'):
|
|
chrono_url += '/'
|
|
return '%sapi/agendas/datetimes/?agendas=%s&user_external_id=%s&show_past_events=true' % (
|
|
chrono_url,
|
|
self.agenda_reference,
|
|
self.user_external_template,
|
|
)
|
|
|
|
def is_visible(self, **kwargs):
|
|
user = kwargs.get('user')
|
|
if not user or user.is_anonymous:
|
|
return False
|
|
return super().is_visible(**kwargs)
|
|
|
|
def get_cell_extra_context(self, context):
|
|
if context.get('placeholder_search_mode'):
|
|
return {}
|
|
return super().get_cell_extra_context(context)
|