family: rewrite info cell logic/template for readability and behaviour (#13945)

* do not call webservices for anonymous users;
 * display a proper error in case of webservice failure;
 * always include cell title and appropriate margins.
This commit is contained in:
Frédéric Péters 2016-11-13 12:28:17 +01:00
parent 81b7ff7d8c
commit 81cb7b096c
2 changed files with 48 additions and 44 deletions

View File

@ -40,12 +40,15 @@ class FamilyInfosCell(CellBase):
return is_family_enabled()
def get_cell_extra_context(self, context):
user = self.get_concerned_user(context)
if not user or user.is_anonymous():
return {}
response = get_family_json('family/',
user=self.get_concerned_user(context),
user=user,
raise_if_not_cached=not(context.get('synchronous')))
if response.status_code == 200:
return {'family': response.json()}
return {}
return {'error': _('An error occured while retrieving family details.')}
def render(self, context):
self.context = context

View File

@ -1,45 +1,46 @@
{% load i18n %}
{% if family %}
<h2>{% trans "Informations related to your family" %}</h2>
{% with data=family.data %}
{% if data %}
<div class="family_unlink">
<a href="{% url 'family-unlink' %}" rel="popup">{% trans "Unlink" %}</a>
<div>
{% if not user.is_authenticated %}
<p>{% trans "You have to connect and link your account to a family." %}</p>
{% elif error %}
<p>{{error}}</p>
{% elif not family.data %}
<p>{% trans "No family linked to your account." %}</p>
{% url 'family-link' as link_url %}
<p>
{% blocktrans %}
If you have family credentials, please
<a href="{{ link_url }}" rel="popup">click here</a> to link your personal
account to it.
{% endblocktrans %}
</p>
{% else %}
<div class="family_unlink">
<a href="{% url 'family-unlink' %}" rel="popup">{% trans "Unlink" %}</a>
</div>
{% with data=family.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 %}
{% endwith %}
{% endif %}
</div>
{% 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>
{% url 'family-link' as link_url %}
<p>{% blocktrans %}If you have family credentials, please
<a href="{{ link_url }}" rel="popup">click here</a> to link your personal
account to it.
{% endblocktrans %}
</p>
{% endif %}
{% endwith %}
{% else %}
<p>{% trans "You have to connect and link you account to a family" %}</p>
{% endif %}