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

Added filtering for members in overview and added member profile pages without achievements

parent 045b6466
......@@ -74,6 +74,12 @@ class Member(models.Model):
return None
return self.membership_set.latest('since')
@property
def earliest_membership(self):
if not self.membership_set.exists():
return None
return self.membership_set.earliest('since')
@property
def membership_set(self):
return self.user.membership_set
......@@ -267,6 +273,16 @@ class Member(models.Model):
return self.get_full_name() or self.user.username
display_name.short_description = _('Display name')
def short_display_name(self):
pref = self.display_name_preference
if pref == 'nickname' or pref == 'nicklast':
return self.nickname
elif pref == 'initials':
return '{} {}'.format(self.initials, self.user.last_name)
else:
return self.user.first_name
return
def get_full_name(self):
return self.user.get_full_name()
......
......@@ -9,6 +9,7 @@
<h2>{% blocktrans %}Ever wondered what the name of that person in the back row of the lecture room is? Or maybe you're
just looking for a group member's email address? There is a high probability that this person is a member of Thalia,
and thus you can use this directory to find him or her.{% endblocktrans %}</h2>
<div class="portfolio member-directory">
<form method="get" action="{% url 'members:index' %}">
......@@ -26,19 +27,19 @@
</form>
<div class="portfolio-filter tabs-wrapper tabs-centered clearfix">
<ul class="link-tabs">
<li {% if not filter %} class="current"{% endif %}><a href="{% url 'members:index' %}">{% trans "All members" %}</a></li>
<li {% if not filter or filter == "all" %} class="current"{% endif %}><a href="{% url 'members:index' %}?filter=all{% if keywords %}&keywords={{ keywords }}{% endif %}{% if page %}&page={{ page }}{% endif %}">{% trans "All members" %}</a></li>
{% for year in year_range %}
<li {% if filter == year|stringformat:"i" %} class="current"{% endif %}><a href="{% url 'members:index' %}?filter={{ year }}">{{ year }}</a></li>
<li {% if filter == year|stringformat:"i" %} class="current"{% endif %}><a href="{% url 'members:index' %}?filter={{ year }}{% if keywords %}&keywords={{ keywords }}{% endif %}{% if page %}&page={{ page }}{% endif %}">{{ year }}</a></li>
{% endfor %}
<li {% if filter == "old" %} class="current"{% endif %}><a href="{% url 'members:index' %}?filter=old">{% trans "Older" %}</a></li>
<li {% if filter == "honor" %} class="current"{% endif %}><a href="{% url 'members:index' %}?filter=honor">{% trans "Honorary Members" %}</a></li>
<li {% if filter == "ex" %} class="current"{% endif %}><a href="{% url 'members:index' %}?filter=ex">{% trans "Former Members" %}</a></li>
<li {% if filter == "old" %} class="current"{% endif %}><a href="{% url 'members:index' %}?filter=old{% if keywords %}&keywords={{ keywords }}{% endif %}{% if page %}&page={{ page }}{% endif %}">{% trans "Older" %}</a></li>
<li {% if filter == "honor" %} class="current"{% endif %}><a href="{% url 'members:index' %}?filter=honor{% if keywords %}&keywords={{ keywords }}{% endif %}{% if page %}&page={{ page }}{% endif %}">{% trans "Honorary Members" %}</a></li>
<li {% if filter == "ex" %} class="current"{% endif %}><a href="{% url 'members:index' %}?filter=ex{% if keywords %}&keywords={{ keywords }}{% endif %}{% if page %}&page={{ page }}{% endif %}">{% trans "Former Members" %}</a></li>
</ul>
</div>
{% if not members %}
<div class="alert alert-info1">
{% trans "There are no members" %}
<div class="alert alert-success2">
{% trans "No members found" %}
<button class="close" type="button"><span class="alert-icon-close"></span></button>
</div>
{% endif %}
......@@ -46,15 +47,19 @@
<ul class="member-directory portfolio-posts row">
{% for member in members %}
<li class="post member-item span3 has-overlay">
<a href="{% url 'members:detail' id=member.id %}">
<a href="{% url 'members:profile' pk=member.pk %}">
<div class="post-inner">
<div class="inner-img">
<img src="{{ member.photo.image.url }}" />
<img src="{% if not member.photo %}/static/images/gravatarmissing.png{% else %}{{ member.photo.url }}{% endif %}" />
</div>
<div class="post-overlay">
<div class="post-overlay-meta">
<h2>{{ member.display_name }}</h2>
<p>Lid sinds: {{ member.starting_year }}</p>
{% if member.current_membership %}
<p>{% trans "Member since" %}: {{ member.earliest_membership.since.year }}</p>
{% else %}
<p>{% trans "Member till" %}: {{ member.latest_membership.since.year }}</p>
{% endif %}
</div>
</div>
<div class="post-body avatar-subtitle">
......@@ -68,24 +73,33 @@
</div>
<div class='clearfix'></div>
<div class="pagination" style="float: none;text-align: center;">
<span class="step-links">
<div class="pagination-wrapper row">
<ul class="pagination">
{% if members.has_previous %}
<a href="{% url 'members:index' %}?filter={{ filter }}&keywords={{ keywords }}&page={{ members.previous_page_number }}">&laquo;</a>
{% else %}
<a style='visibility: hidden;'>&laquo;</a>
<li>
<a class="page-prev" href="{% url 'members:index' %}?page={{ members.previous_page_number }}{% if filter %}&filter={{ filter }}{% endif %}{% if keywords %}&keywords={{ keywords }}{% endif %}">Previous</a>
</li>
{% endif %}
<span class="current">
{{ members.number }} / {{ members.paginator.num_pages }}
</span>
{% for page in page_range %}
{% if page == members.number %}
<li class="current">
<span class="page-number">
{{ page }}
</span>
</li>
{% else %}
<li><a href="{% url 'members:index' %}?page={{ page }}{% if filter %}&filter={{ filter }}{% endif %}{% if keywords %}&keywords={{ keywords }}{% endif %}" class="page-number button">{{ page }}</a></li>
{% endif %}
{% endfor %}
{% if members.has_next %}
<a href="{% url 'members:index' %}?filter={{ filter }}&keywords={{ keywords }}&page={{ members.next_page_number }}">&raquo;</a>
{% else %}
<a style='visibility: hidden;'>&raquo;</a>
<li>
<a class="page-next" href="{% url 'members:index' %}?page={{ members.next_page_number }}{% if filter %}&filter={{ filter }}{% endif %}{% if keywords %}&keywords={{ keywords }}{% endif %}">{% trans "Next" %}</a>
</li>
{% endif %}
</span>
</ul>
</div>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Profile" %} - {% trans "Members" %} - {{ block.super }}{% endblock %}
{% block body %}
<h1>
{{ member.display_name }}
<span class="title-meta clearfix">
<span><a href="{% url 'members:index' %}" class="back"></a></span>
</span>
</h1>
<div class="clearfix"></div>
<div class="type-portfolio type-portfolio-half clearfix user-page">
<div class="row">
<div class="span8">
<img src="{% if not member.photo %}/static/images/gravatarmissing.png{% else %}{{ member.photo.url }}{% endif %}" alt="{{ member.username }}" />
</div>
<div class="span4 row">
<h4>{% trans "About" %} {{ member.short_display_name }}</h4>
{% if not member.profile_description %}
<i>{% trans "This member has not written a description yet." %}</i>
{% else %}
{{ member.profile_description }}
{% endif %}
<hr class="separator">
<h4>{% trans "Personal information" %}</h4>
<ul class="post-meta">
<li><span>{% trans "Starting year" %}: </span> {{ member.starting_year }}<br></li>
{% if member.is_active %}
<li><span>{% trans "Member since" %}: </span> {{ member.earliest_membership.since.year }}</li>
<li><span>{% trans "Membership type" %}: </span> {{ member.current_membership.get_type_display }}</li>
{% else %}
<li><span>{% trans "Member till" %}: </span> {{ member.latest_membership.since.year }}</li>
{% endif %}
<li><span>{% trans "Study programme" %}: </span> {{ member.get_programme_display }}<br></li>
{% if member.website %}
<li><span>{% trans "Website" %}: </span> {{ member.website }}</li>
{% endif %}
{% if member.show_birthday %}
<li><span>{% trans "Birthday" %}: </span> {{ member.birthday }}</li>
{% endif %}
</ul>
{% comment "This below is for achievements, there are examples for different types of achievements from the old site and an assumption on how it can work" %}
<hr class="separator">
<h4>{% trans "Achievements for Thalia" %}</h4>
<ul class="post-meta">
{% for achievement in member.achievements %}
<li style="margin-bottom:10px;">
<span>{{ achievement.name }}</span>
<br>
<i>{{ achievement.from }} - {{ achievement.till }}</i>
<br>
</li>
{% endfor %}
<li style="margin-bottom:10px;">
<span>Huisstijlcommissie</span>
<br>
<i>2014-10-01 - 2016-02-01</i>
<ul>
<li><span style="text-transform:inherit;">Voorzitter: </span><i>2015-06-18 - 2016-02-10</i>
</li>
</ul>
</li>
<li style="margin-bottom:10px;">
<span>Mediacommissie</span>
<br>
<i>2014-09-17 - heden</i>
<ul>
<li><span style="text-transform:inherit;">Voorzitter: </span><i>2015-09-14 - 2015-09-14</i>
</li>
</ul>
</li>
<li style="margin-bottom:10px;">
<span>Mentor introductie 2016</span>
</li>
</ul>
{% endcomment %}
</div>
</div>
<!-- /portfolio single content -->
</div>
{% endblock %}
\ No newline at end of file
......@@ -5,6 +5,6 @@ from . import views
urlpatterns = [
url('^become-a-member-document/(?P<pk>[0-9]*)', views.get_become_a_member_document, name='become-a-member-document'),
url('^(?P<id>[0-9]*)', views.detail, name='detail'),
url('^', views.index, name='index'),
url('^profile/(?P<pk>[0-9]*)$', views.profile, name='profile'),
url('^$', views.index, name='index'),
]
......@@ -3,17 +3,45 @@ from django.shortcuts import get_object_or_404, render
from django.utils.text import slugify
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from . import models
from .models import Member
from .models import BecomeAMemberDocument
import os
from sendfile import sendfile
def index(request):
members = models.Member.objects.all()
query_filter = '' if request.GET.get('filter') is None else request.GET.get('filter')
keywords = '' if request.GET.get('keywords') is None else request.GET.get('keywords')
paginator = Paginator(members, 12)
page = request.GET.get('page')
page = 1 if page is None or not page.isdigit() else int(page)
start_year = date.today().year - 4
# If language is English show one year less, since the width is smaller than needed for the translations to fit
if request.LANGUAGE_CODE == 'en':
start_year += 1
year_range = reversed(range(start_year, date.today().year + 1))
members = Member.objects.all()
if query_filter and query_filter.isdigit() and not (
query_filter == 'ex' or query_filter == 'honor' or query_filter == 'old'):
members = [obj for obj in members if
obj.current_membership and obj.current_membership.since.year == int(query_filter)]
elif query_filter == 'old':
members = [obj for obj in members if obj.current_membership and obj.current_membership.since.year < start_year]
elif query_filter == 'ex':
members = [obj for obj in members if not obj.current_membership]
elif query_filter == 'honor':
members = [obj for obj in members if obj.current_membership and obj.current_membership.type == 'honorary']
else:
members = [obj for obj in members if obj.current_membership]
if keywords:
members = [obj for obj in members if keywords in obj.nickname.lower() or keywords in obj.user.first_name.lower() or keywords in obj.user.last_name.lower() or keywords in obj.user.username.lower()]
paginator = Paginator(members, 24)
try:
members = paginator.page(page)
except PageNotAnInteger:
......@@ -23,27 +51,31 @@ def index(request):
# If page is out of range (e.g. 9999), deliver last page of results.
members = paginator.page(paginator.num_pages)
query_filter = request.GET.get('filter')
year_range = reversed(range(date.today().year - 4, date.today().year + 1))
page_range = range(1, paginator.num_pages + 1)
if paginator.num_pages > 7:
if page > 3:
page_range = range(page - 2, paginator.num_pages if page + 3 > paginator.num_pages else page + 3)
while page_range.stop - page_range.start < 5:
page_range = range(page_range.start - 1, page_range.stop)
else:
page_range = range(1, 6)
return render(request, 'members/index.html', {'members': members, 'filter': query_filter, 'year_range': year_range})
return render(request, 'members/index.html', {'members': members, 'filter': query_filter, 'year_range': year_range, 'page_range': page_range, 'keywords': keywords})
def detail(request, id):
members = models.Member.objects.all()
filter = request.GET.get('filter')
year_range = reversed(range(date.today().year - 4, date.today().year + 1))
def profile(request, pk):
member = get_object_or_404(Member, pk=int(pk))
return render(request, 'members/index.html', {'members': members, 'filter': filter, 'year_range': year_range})
return render(request, 'members/profile.html', {'member': member})
def become_a_member(request):
context = {'documents': models.BecomeAMemberDocument.objects.all()}
context = {'documents': BecomeAMemberDocument.objects.all()}
return render(request, 'singlepages/become_a_member.html', context)
def get_become_a_member_document(request, pk):
document = get_object_or_404(models.BecomeAMemberDocument, pk=int(pk))
document = get_object_or_404(BecomeAMemberDocument, pk=int(pk))
ext = os.path.splitext(document.file.path)[1]
return sendfile(request, document.file.path, attachment=True,
attachment_filename=slugify(document.name) + ext)
Markdown is supported
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