2015-11-10 14:38:23 +01:00
|
|
|
# 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/>.
|
|
|
|
|
2015-08-27 18:50:33 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
from combo.data.models import CellBase
|
|
|
|
from combo.data.library import register_cell_class
|
2016-04-06 00:23:33 +02:00
|
|
|
|
2017-12-05 18:07:11 +01:00
|
|
|
from .utils import is_family_enabled, get_family
|
2015-08-27 18:50:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
@register_cell_class
|
|
|
|
class FamilyInfosCell(CellBase):
|
|
|
|
template_name = 'family/infos.html'
|
|
|
|
user_dependant = True
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Family Information Cell')
|
|
|
|
|
2015-09-30 10:33:07 +02:00
|
|
|
class Media:
|
|
|
|
js = ('xstatic/jquery-ui.min.js', 'js/gadjo.js',)
|
|
|
|
|
2015-08-27 18:50:33 +02:00
|
|
|
@classmethod
|
|
|
|
def is_enabled(cls):
|
2016-06-29 17:40:00 +02:00
|
|
|
return is_family_enabled()
|
2015-08-27 18:50:33 +02:00
|
|
|
|
2016-01-13 13:29:56 +01:00
|
|
|
def get_cell_extra_context(self, context):
|
2017-10-14 22:08:21 +02:00
|
|
|
if context.get('placeholder_search_mode'):
|
|
|
|
return {}
|
2016-11-13 12:28:17 +01:00
|
|
|
user = self.get_concerned_user(context)
|
2019-10-14 13:43:08 +02:00
|
|
|
if not user or user.is_anonymous:
|
2016-11-13 12:28:17 +01:00
|
|
|
return {}
|
2017-12-05 18:07:11 +01:00
|
|
|
response = get_family(user=user,
|
2016-04-06 00:23:33 +02:00
|
|
|
raise_if_not_cached=not(context.get('synchronous')))
|
|
|
|
if response.status_code == 200:
|
|
|
|
return {'family': response.json()}
|
2016-11-13 12:28:17 +01:00
|
|
|
return {'error': _('An error occured while retrieving family details.')}
|