Commit a11b7ea5 authored by Tom van Bussel's avatar Tom van Bussel
Browse files

Merge branch 'feature/activemembers-documentation' into 'master'

Add and change documentation in the activemembers package

Closes #572

See merge request !810
parents 74c78402 0c8ef662
"""Registers admin interfaces for the activemembers module"""
import csv
import datetime
......@@ -30,6 +31,7 @@ class CommitteeMembershipInlineFormSet(forms.BaseInlineFormSet):
class CommitteeMembershipInline(admin.StackedInline):
"""Inline for committee memberships"""
model = models.CommitteeMembership
formset = CommitteeMembershipInlineFormSet
can_delete = False
......@@ -56,6 +58,7 @@ class CommitteeForm(forms.ModelForm):
class CommitteeAdmin(TranslatedModelAdmin):
"""Manage the committees"""
inlines = (CommitteeMembershipInline,)
form = CommitteeForm
list_display = ('name', 'since', 'until', 'active', 'email')
......@@ -81,6 +84,7 @@ class CommitteeAdmin(TranslatedModelAdmin):
class BoardAdmin(TranslatedModelAdmin):
"""Manage the board"""
inlines = (CommitteeMembershipInline,)
form = CommitteeForm
exclude = ('is_board',)
......@@ -91,6 +95,7 @@ class BoardAdmin(TranslatedModelAdmin):
class BoardFilter(admin.SimpleListFilter):
"""Filter memberships on board-only"""
title = _('board memberships')
parameter_name = 'board'
......@@ -110,6 +115,7 @@ class BoardFilter(admin.SimpleListFilter):
class LectureYearFilter(admin.SimpleListFilter):
"""Filter the memberships on those started or ended in a lecture year"""
title = _('lecture year')
parameter_name = 'lecture_year'
......@@ -134,6 +140,7 @@ class LectureYearFilter(admin.SimpleListFilter):
class CommitteeMembershipAdmin(TranslatedModelAdmin):
"""Manage the committee memberships"""
form = CommitteeMembershipForm
list_display = ('member', 'committee', 'since', 'until', 'chair', 'role')
list_filter = ('committee', BoardFilter, LectureYearFilter)
......@@ -185,4 +192,5 @@ class CommitteeMembershipAdmin(TranslatedModelAdmin):
class MentorshipAdmin(admin.ModelAdmin):
"""Manage the mentorships"""
list_select_related = ('member',)
"""Configuration for the activemembers package"""
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _
class ActiveMembersConfig(AppConfig):
"""AppConfig for the activemembers package"""
name = 'activemembers'
verbose_name = _('Active members')
"""The forms defined by the activemembers module"""
from django import forms
from activemembers.models import CommitteeMembership
......@@ -5,6 +6,7 @@ from members.models import Member
class CommitteeMembershipForm(forms.ModelForm):
"""Custom form for committee memberships that orders the members"""
member = forms.ModelChoiceField(
"""The models defined by the activemembers package"""
import datetime
import logging
......@@ -44,7 +45,7 @@ class ActiveCommitteeManager(models.Manager):
class Committee(models.Model, metaclass=ModelTranslateMeta):
"""A committee"""
"""Describes a committee"""
unfiltered_objects = UnfilteredSortedManager()
objects = CommitteeManager()
......@@ -115,7 +116,6 @@ class Committee(models.Model, metaclass=ModelTranslateMeta):
def clean(self):
if ((self.contact_email is not None and
self.contact_mailinglist is not None) or
(self.contact_email is None and
......@@ -142,6 +142,10 @@ class Committee(models.Model, metaclass=ModelTranslateMeta):
class BoardManager(models.Manager):
Custom manager that filters out
instances of Committee that are not boards
use_in_migrations = True
......@@ -180,7 +184,6 @@ class Board(Committee):
def validate_unique(self, *args, **kwargs):
""" Check uniqueness"""
super().validate_unique(*args, **kwargs)
boards = Board.objects.all()
if self.since is not None:
......@@ -199,14 +202,16 @@ class Board(Committee):
class ActiveMembershipManager(models.Manager):
"""Get only active memberships"""
Customs manager that gets the currently active committee memberships
def get_queryset(self):
"""Get the currently active committee memberships"""
return super().get_queryset().exclude(
class CommitteeMembership(models.Model, metaclass=ModelTranslateMeta):
"""Describes a committee membership"""
objects = models.Manager()
active_memberships = ActiveMembershipManager()
......@@ -253,7 +258,7 @@ class CommitteeMembership(models.Model, metaclass=ModelTranslateMeta):
def initial_connected_membership(self):
""" Find the oldest membership directly connected to the current one"""
"""Find the oldest membership directly connected to the current one"""
qs = CommitteeMembership.objects.filter(
......@@ -270,7 +275,6 @@ class CommitteeMembership(models.Model, metaclass=ModelTranslateMeta):
return self.until is None or self.until >
def clean(self):
if self.until and (not self.since or self.until < self.since):
raise ValidationError(
{'until': _("End date can't be before start date")})
......@@ -296,7 +300,6 @@ class CommitteeMembership(models.Model, metaclass=ModelTranslateMeta):
def validate_unique(self, *args, **kwargs):
""" Check uniqueness"""
super().validate_unique(*args, **kwargs)
# Check if a committee has more than one chair
if self.chair:
......@@ -354,6 +357,7 @@ class CommitteeMembership(models.Model, metaclass=ModelTranslateMeta):
class Mentorship(models.Model):
"""Describe a mentorship during the orientation"""
member = models.ForeignKey(
Activemembers URL Configuration
"""The routes defined by the activemembers package"""
from django.conf.urls import url
from . import views
......@@ -11,7 +8,7 @@ app_name = "activemembers"
urlpatterns = [
url(r'committees/$', views.committee_index, name='committees'),
url(r'^committees/(?P<id>\d+)/$', views.committee_detail, name='committee'),
url(r'^committees/(?P<pk>\d+)/$', views.committee_detail, name='committee'),
url(r'^boards/$', views.board_index, name='boards'),
url(r'^board/(?P<since>\d{4})$', views.board_detail, name='board'),
url(r'^board/(?P<since>\d{4})-(?P<until>\d{4})$', views.board_detail, name='board'),
......@@ -6,8 +6,11 @@ from .models import Board, Committee, CommitteeMembership
def committee_index(request):
"""Overview of committees"""
View that renders the committee overview page
:param request: the request object
:return: response containing the HTML
committees = Committee.active_committees.all().order_by(
......@@ -15,9 +18,14 @@ def committee_index(request):
{'committees': committees})
def committee_detail(request, id):
"""View the details of a committee"""
committee = get_object_or_404(Committee, pk=id)
def committee_detail(request, pk):
View that renders the page of one selected committee
:param request: the request object
:param pk: pk of the selected committee
committee = get_object_or_404(Committee, pk=pk)
members = []
memberships = (CommitteeMembership
......@@ -39,6 +47,11 @@ def committee_detail(request, id):
def board_index(request):
View that renders the board overview page
:param request: the request object
:return: response containing the HTML
current_year = datetime_to_lectureyear(
board = get_object_or_404(
Board, since__year=current_year, until__year=current_year+1)
......@@ -51,7 +64,13 @@ def board_index(request):
def board_detail(request, since, until=None):
"""View the details of a board"""
View that renders the board for a specific lecture year
:param request: the request object
:param since: xxxx in xxxx-yyyy of the lecture year
:param until: yyyy in xxxx-yyyy of the lecture year
:return: response containing the HTML
if not until: # try to correct /board/2016 to /2016-2017
return redirect(reverse('activemembers:board',
kwargs={'since': since,
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