99 lines
3.3 KiB
Python
99 lines
3.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 CellBase, JsonCellBase
|
|
|
|
from .utils import get_family, is_family_enabled
|
|
|
|
|
|
@register_cell_class
|
|
class FamilyInfosCell(CellBase):
|
|
default_template_name = 'family/infos.html'
|
|
user_dependant = True
|
|
|
|
class Meta:
|
|
verbose_name = _('Family Information Cell')
|
|
|
|
class Media:
|
|
js = (
|
|
'xstatic/jquery-ui.min.js',
|
|
'js/gadjo.js',
|
|
)
|
|
|
|
@classmethod
|
|
def is_enabled(cls):
|
|
return is_family_enabled()
|
|
|
|
def get_cell_extra_context(self, context):
|
|
if context.get('placeholder_search_mode'):
|
|
return {}
|
|
user = self.get_concerned_user(context)
|
|
if not user or user.is_anonymous:
|
|
return {}
|
|
response = get_family(user=user, raise_if_not_cached=not (context.get('synchronous')))
|
|
if response.status_code == 200:
|
|
return {'family': response.json()}
|
|
return {'error': _('An error occured while retrieving family details.')}
|
|
|
|
|
|
@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_id_key = models.CharField(max_length=50)
|
|
|
|
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 += '/'
|
|
# XXX events=all param is not supported for now
|
|
return (
|
|
'%sapi/agendas/datetimes/?agendas=%s&user_external_id=%s:{{ user_external_id|default:user_nameid }}'
|
|
% (chrono_url, self.agenda_reference, self.user_external_id_key)
|
|
)
|
|
|
|
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)
|