teamnet axel cell draft

This commit is contained in:
Serghei Mihai 2015-07-16 23:08:01 +02:00
parent b98bedebec
commit fa0040a9ae
3 changed files with 160 additions and 0 deletions

View File

View File

@ -0,0 +1,113 @@
# combo - content management system
# Copyright (C) 2014-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/>.
import urllib
import logging
from django.conf import settings
from django import template
from django.db import models
from django.forms import models as model_forms
from django.utils.translation import ugettext_lazy as _
import cmsplugin_blurp.utils
from jsonfield import JSONField
from combo.data.models import CellBase
from combo.data.library import register_cell_class
from combo.utils import NothingInCacheException
logger = logging.getLogger(__name__)
def is_teamnet_axel_enabled(cls):
return hasattr(settings, 'TEMPLATE_VARS') \
and settings.TEMPLATE_VARS.get('teamnet_axel_ws_url')
def get_teamnet_axel_site():
return {
'url': settings.TEMPLATE_VARS['teamnet_axel_ws_url'],
'secret': settings.TEMPLATE_VARS['teamnet_axel_ws_secret'],
'orig': settings.TEMPLATE_VARS['teamnet_axel_ws_orig'],
}
class TeamnetAxelBlurpMixin(object):
is_enabled = classmethod(is_teamnet_axel_enabled)
user_dependant = True
def get_blurp_renderer(self, context):
source = {
'slug': 'teamnet_axel',
'parser_type': 'json',
'verify_certificate': False,
'allow_redirects': False
}
site = get_teamnet_axel_site()
url = site['url'] + '/' + self.api_url + '/?'
url += 'orig=%s' % site['orig']
source['auth_mech'] = 'hmac-sha1'
source['signature_key'] = str(site['secret'])
if context.get('user'):
if context.get('request') and hasattr(context['request'], 'session') \
and context['request'].session.get('mellon_session'):
mellon = context['request'].session['mellon_session']
nameid = mellon['name_id_content']
url += '&NameID=' + urllib.quote(nameid)
source['url'] = url
logger.info('url: %s' % source['url'])
sources = [source]
renderer = cmsplugin_blurp.utils.create_renderer(self.variable_name, {
'name': self._meta.verbose_name,
'class': 'cmsplugin_blurp.renderers.data_source.DictRendererWithDefault',
'sources': sources,
'template_name': self.template_name,
'refresh': 10,
'ajax': False,
})
if not context.get('ajax') and not renderer.has_cached_content(context):
raise NothingInCacheException()
return renderer
class TeamnetAxelDataBaseCell(CellBase, TeamnetAxelBlurpMixin):
is_enabled = classmethod(is_teamnet_axel_enabled)
class Meta:
abstract = True
def render(self, context):
renderer = self.get_blurp_renderer(context)
template = renderer.render_template()
context = renderer.render(context)
return template.render(context)
@register_cell_class
class TeamnetAxelFamilyCell(TeamnetAxelDataBaseCell):
api_url = 'family'
variable_name = 'family'
template_name = 'combo/teamnet_axel/family.html'
class Meta:
verbose_name = _('Teamnet Axel Family')

View File

@ -0,0 +1,47 @@
{% load i18n %}
<h2>{% trans 'Votre famille' %}</h2>
{% for slug, f in family.iteritems %}
{% if f.data.data.responsables %}
<h3>{% trans "Responsables" %}</h3>
<ul>
{% for r in f.data.data.responsables %}
<li>{{ r.civilite }} {{ r.prenom }} {{ r.nom }}<br />
{% if r.sexe == "F" %}{% trans "Née le" %}{% else %}{% trans "Né le" %}{% endif %} {{ r.naissance }}
{% if r.situation %}<br />{{ r.situation }}{% endif %}
{% if r.csp %}, {{ r.csp }}{% endif %}
{% if r.orgaalloc %}<br />
{% trans "Allocataire du " %} {{ r.orgaalloc }}
<br />{% endif %}
<strong>{% trans "Adresse :" %}</strong> {{ r.norue }} {{ r.voie }}, {{ r.codepostal }} {{ r.ville }}<br />
{% if r.telportable or r.telportbureau or r.mail %}
<strong>{% trans "Contacts : " %}</strong><br />
{% if r.telportable %}{% trans "Téléphone portable :" %} {{ r.telportable }}<br />{% endif %}
{% if r.telfixe %}{% trans "Téléphone fixe :" %} {{ r.telfixe }}<br />{% endif %}
{% if r.mail %}{% trans "Courriel :" %} {{ r.mail }}<br />{% endif %}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% if f.data.data.enfants %}
<h3>{% trans "Enfants" %}</h3>
<ul>
{% for k in f.data.data.enfants %}
<li>{{ k.civilite }}{{ k.prenom}} {{ k.nom}}<br />
{% if k.sexe == "F" %}{% trans "Née le" %}{% else %}{% trans "Né le" %}{% endif %} {{ k.naissance }}<br />
<strong>{% trans "Adresse :" %}</strong> {{ k.norue }} {{ k.voie }}, {{ k.codepostal }} {{ k.ville }}<br />
{% if k.telportable or k.telportbureau or k.mail %}
<strong>{% trans "Contacts : " %}</strong><br />
{% if k.telportable %}{% trans "Téléphone portable :" %} {{ k.telportable }}<br />{% endif %}
{% if k.telfixe %}{% trans "Téléphone fixe :" %} {{ k.telfixe }}<br />{% endif %}
{% if k.mail %}{% trans "Courriel :" %} {{ k.mail }}<br />{% endif %}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
<!-- <pre> -->
<!-- {{f.data.data.enfants|pprint }} -->
<!-- </pre> -->
{% endfor %}