basic family information cell (#8125)

This commit is contained in:
Serghei Mihai 2015-08-27 18:50:33 +02:00
parent 4e94b62894
commit f26afe2cb1
8 changed files with 139 additions and 0 deletions

11
combo/apps/family/README Normal file
View File

@ -0,0 +1,11 @@
Combo family cell
=================
This cell is visible only if the setting:
FAMILY_SERVICE = {
"url": "<webservice url",
"signature_key": "<key">
}
is declared.

View File

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import ckeditor.fields
class Migration(migrations.Migration):
dependencies = [
('auth', '0001_initial'),
('data', '0010_feedcell'),
]
operations = [
migrations.CreateModel(
name='FamilyInfosCell',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('placeholder', models.CharField(max_length=20)),
('order', models.PositiveIntegerField()),
('slug', models.SlugField(verbose_name='Slug', blank=True)),
('public', models.BooleanField(default=True, verbose_name='Public')),
('groups', models.ManyToManyField(to='auth.Group', verbose_name='Groups', blank=True)),
('page', models.ForeignKey(to='data.Page')),
],
options={
'verbose_name': 'Family Information Cell',
},
bases=(models.Model,),
),
]

View File

View File

@ -0,0 +1,44 @@
import requests
from django.conf import settings
from django.db import models
from django import template
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, sign_url
@register_cell_class
class FamilyInfosCell(CellBase):
template_name = 'family/infos.html'
user_dependant = True
class Meta:
verbose_name = _('Family Information Cell')
@classmethod
def is_enabled(cls):
return hasattr(settings, 'FAMILY_SERVICE')
def get_cell_extra_context(self):
data = {'alternate_text': self.alternate_text}
context = self.context
if context.get('user'):
if context.get('request') and hasattr(context['request'], 'session') and \
context['request'].session.get('mellon_session'):
mellon = context.get('request').session['mellon_session']
query = '?NameID=' + mellon['name_id_content']
query += '&orig=' + context['request'].get_host()
url = sign_url(settings.FAMILY_SERVICE.get('url') + '/family/' + query,
settings.FAMILY_SERVICE.get('signature_key'))
r = requests.get(url)
data.update({'family': r.json()})
return data
def render(self, context):
self.context = context
if not context.get('synchronous'):
raise NothingInCacheException()
return super(FamilyInfosCell, self).render(context)

View File

@ -0,0 +1,34 @@
{% load i18n %}
{% if family %}
<h2>{% trans "Informations related to your family" %}</h2>
{% with data=family.data %}
{% if data %}
{% if data.adults %}
<h3>{% trans "Adults" %}</h3>
<ul>
{% for adult in data.adults %}
<li>
{% include 'family/person.html' with person=adult %}
</li>
{% endfor %}
</ul>
{% endif %}
{% if data.children %}
<h3>{% trans "Children" %}</h3>
<ul>
{% for child in data.children %}
<li>
{% include 'family/person.html' with person=child %}
</li>
{% endfor %}
</ul>
{% endif %}
{% else %}
<p>{% trans "No family linked to your account." %}</p>
{% endif %}
{% endwith %}
{% else %}
<p>{% trans "You have to connect and link you account to a family" %}</p>
{% endif %}

View File

@ -0,0 +1,17 @@
{% load i18n %}
<p>{{ person.first_name }} {{ person.last_name }}</p>
{% blocktrans with birthdate=person.birthdate %}
Born on {{ birthdate }}
{% endblocktrans %}
<h4>{% trans "Address" %}</h4>
<p>{{ person.address }}</p>
{% if person.phone or person.cellphone or person.email %}
<h4>{% trans "Contact" %}</h4>
<ul class='contact'>
{% if person.cellphone %}<li class='cellphone'>{% trans "Cellphone:" %} {{ person.cellphone }}</li>{% endif %}
{% if person.phone %}<li class='phone'>{% trans "Phone:" %} {{ person.phone }}</li>{% endif %}
{% if person.email %}<li class='email'>{% trans "Email:" %} {{ person.email }}</li>{% endif %}
</ul>
{% endif %}

View File

@ -62,6 +62,7 @@ INSTALLED_APPS = (
'combo.public',
'combo.apps.wcs',
'combo.apps.publik',
'combo.apps.family',
)
INSTALLED_APPS = plugins.register_plugins_apps(INSTALLED_APPS)