59 lines
2.1 KiB
Python
59 lines
2.1 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.utils.translation import ugettext_lazy as _
|
|
|
|
from combo.data.models import CellBase
|
|
from combo.data.library import register_cell_class
|
|
from combo.utils import NothingInCacheException
|
|
|
|
from .utils import is_family_enabled, get_family_json
|
|
|
|
|
|
@register_cell_class
|
|
class FamilyInfosCell(CellBase):
|
|
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_json('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.')}
|
|
|
|
def render(self, context):
|
|
self.context = context
|
|
if not context.get('synchronous'):
|
|
raise NothingInCacheException()
|
|
return super(FamilyInfosCell, self).render(context)
|