Commit 13f0d94c authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Merge branch 'tc/society-header' into 'master'

Added Societies Header on Profiles

Closes #755

See merge request !1040
parents d24295de d5435309
...@@ -7,8 +7,8 @@ msgid "" ...@@ -7,8 +7,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-11-12 19:36+0100\n" "POT-Creation-Date: 2018-11-14 19:57+0100\n"
"PO-Revision-Date: 2018-11-12 19:37+0100\n" "PO-Revision-Date: 2018-11-14 19:58+0100\n"
"Last-Translator: Thom Wiggers <thom@thomwiggers.nl>\n" "Last-Translator: Thom Wiggers <thom@thomwiggers.nl>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: nl\n" "Language: nl\n"
...@@ -50,6 +50,14 @@ msgstr "Voornaam" ...@@ -50,6 +50,14 @@ msgstr "Voornaam"
msgid "Last name" msgid "Last name"
msgstr "Achternaam" msgstr "Achternaam"
#: admin.py
msgid "Email"
msgstr "E-mail"
#: admin.py
msgid "Download email addresses for selected users"
msgstr "Download e-mailadressen voor geselecteerde gebruikers"
#: admin.py #: admin.py
msgid "Address" msgid "Address"
msgstr "Adres" msgstr "Adres"
...@@ -1003,6 +1011,10 @@ msgstr "Voorzitter" ...@@ -1003,6 +1011,10 @@ msgstr "Voorzitter"
msgid "today" msgid "today"
msgstr "heden" msgstr "heden"
#: templates/members/profile.html
msgid "Societies"
msgstr "Gezelschappen"
#: templates/members/statistics.html #: templates/members/statistics.html
msgid "Statistics" msgid "Statistics"
msgstr "Statistieken" msgstr "Statistieken"
......
...@@ -9,10 +9,13 @@ from members.models import Membership, Member ...@@ -9,10 +9,13 @@ from members.models import Membership, Member
from utils.snippets import datetime_to_lectureyear from utils.snippets import datetime_to_lectureyear
def member_achievements(member): def _member_group_memberships(member, skip_condition):
memberships = member.membergroupmembership_set.all() memberships = member.membergroupmembership_set.all()
achievements = {} data = {}
for membership in memberships: for membership in memberships:
if skip_condition(membership):
continue
period = { period = {
'since': membership.since, 'since': membership.since,
'until': membership.until, 'until': membership.until,
...@@ -27,17 +30,24 @@ def member_achievements(member): ...@@ -27,17 +30,24 @@ def member_achievements(member):
period['until'] = membership.group.board.until period['until'] = membership.group.board.until
name = membership.group.name name = membership.group.name
if achievements.get(name): if data.get(name):
achievements[name]['periods'].append(period) data[name]['periods'].append(period)
if achievements[name]['earliest'] > membership.since: if data[name]['earliest'] > membership.since:
achievements[name]['earliest'] = membership.since data[name]['earliest'] = membership.since
achievements[name]['periods'].sort(key=lambda x: x['since']) data[name]['periods'].sort(key=lambda x: x['since'])
else: else:
achievements[name] = { data[name] = {
'name': name, 'name': name,
'periods': [period], 'periods': [period],
'earliest': membership.since, 'earliest': membership.since,
} }
return data
def member_achievements(member):
achievements = _member_group_memberships(
member, lambda membership: hasattr(membership.group, 'society'))
mentor_years = member.mentorship_set.all() mentor_years = member.mentorship_set.all()
for mentor_year in mentor_years: for mentor_year in mentor_years:
name = "Mentor in {}".format(mentor_year.year) name = "Mentor in {}".format(mentor_year.year)
...@@ -52,6 +62,13 @@ def member_achievements(member): ...@@ -52,6 +62,13 @@ def member_achievements(member):
return sorted(achievements.values(), key=lambda x: x['earliest']) return sorted(achievements.values(), key=lambda x: x['earliest'])
def member_societies(member):
societies = _member_group_memberships(member, lambda membership: (
hasattr(membership.group, 'board') or
hasattr(membership.group, 'committee')))
return sorted(societies.values(), key=lambda x: x['earliest'])
def gen_stats_member_type(member_types): def gen_stats_member_type(member_types):
total = dict() total = dict()
for member_type in member_types: for member_type in member_types:
......
...@@ -87,6 +87,31 @@ ...@@ -87,6 +87,31 @@
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} {% endif %}
{% if societies %}
<hr class="separator">
<h4>{% trans "Societies" %}</h4>
<ul class="list-unstyled">
{% for society in societies %}
<li class="mb-1">
<strong>{{ society.name }}</strong>
<br>
{% for period in society.periods %}
{% if period.role %}
<span>{{ period.role }}: </span>
{% elif period.chair %}
<span>{% trans "Chair" %}: </span>
{% endif %}
<i>{% if period.since|date:'Y m d' == '1970 01 01' %}?{% else %}
{{ period.since }}{% endif %} -
{% if period.until %}{{ period.until }}{% else %}
{% trans "today" %}{% endif %}</i>
<br>
{% endfor %}
</li>
{% endfor %}
</ul>
{% endif %}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -21,6 +21,7 @@ from members.models import EmailChange, Membership ...@@ -21,6 +21,7 @@ from members.models import EmailChange, Membership
from . import models from . import models
from .forms import ProfileForm, EmailChangeForm from .forms import ProfileForm, EmailChangeForm
from .services import member_achievements from .services import member_achievements
from .services import member_societies
class ObtainThaliaAuthToken(ObtainAuthToken): class ObtainThaliaAuthToken(ObtainAuthToken):
...@@ -147,6 +148,7 @@ def profile(request, pk=None): ...@@ -147,6 +148,7 @@ def profile(request, pk=None):
# Group the memberships under the committees for easier template rendering # Group the memberships under the committees for easier template rendering
achievements = member_achievements(member) achievements = member_achievements(member)
societies = member_societies(member)
membership = member.current_membership membership = member.current_membership
membership_type = _("Unknown membership history") membership_type = _("Unknown membership history")
...@@ -162,6 +164,7 @@ def profile(request, pk=None): ...@@ -162,6 +164,7 @@ def profile(request, pk=None):
return render(request, 'members/profile.html', return render(request, 'members/profile.html',
{ {
'achievements': achievements, 'achievements': achievements,
'societies': societies,
'member': member, 'member': member,
'membership_type': membership_type, 'membership_type': membership_type,
}) })
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment