mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
use google convention for docstrings
This commit is contained in:
@ -44,9 +44,7 @@ class ClubEditForm(forms.ModelForm):
|
||||
|
||||
|
||||
class MailingForm(forms.Form):
|
||||
"""
|
||||
Form handling mailing lists right
|
||||
"""
|
||||
"""Form handling mailing lists right."""
|
||||
|
||||
ACTION_NEW_MAILING = 1
|
||||
ACTION_NEW_SUBSCRIPTION = 2
|
||||
@ -105,16 +103,12 @@ class MailingForm(forms.Form):
|
||||
)
|
||||
|
||||
def check_required(self, cleaned_data, field):
|
||||
"""
|
||||
If the given field doesn't exist or has no value, add a required error on it
|
||||
"""
|
||||
"""If the given field doesn't exist or has no value, add a required error on it."""
|
||||
if not cleaned_data.get(field, None):
|
||||
self.add_error(field, _("This field is required"))
|
||||
|
||||
def clean_subscription_users(self):
|
||||
"""
|
||||
Convert given users into real users and check their validity
|
||||
"""
|
||||
"""Convert given users into real users and check their validity."""
|
||||
cleaned_data = super().clean()
|
||||
users = []
|
||||
for user in cleaned_data["subscription_users"]:
|
||||
@ -177,9 +171,7 @@ class SellingsForm(forms.Form):
|
||||
|
||||
|
||||
class ClubMemberForm(forms.Form):
|
||||
"""
|
||||
Form handling the members of a club
|
||||
"""
|
||||
"""Form handling the members of a club."""
|
||||
|
||||
error_css_class = "error"
|
||||
required_css_class = "required"
|
||||
@ -236,9 +228,9 @@ class ClubMemberForm(forms.Form):
|
||||
self.fields.pop("start_date")
|
||||
|
||||
def clean_users(self):
|
||||
"""
|
||||
Check that the user is not trying to add an user already in the club
|
||||
Also check that the user is valid and has a valid subscription
|
||||
"""Check that the user is not trying to add an user already in the club.
|
||||
|
||||
Also check that the user is valid and has a valid subscription.
|
||||
"""
|
||||
cleaned_data = super().clean()
|
||||
users = []
|
||||
@ -260,9 +252,7 @@ class ClubMemberForm(forms.Form):
|
||||
return users
|
||||
|
||||
def clean(self):
|
||||
"""
|
||||
Check user rights for adding an user
|
||||
"""
|
||||
"""Check user rights for adding an user."""
|
||||
cleaned_data = super().clean()
|
||||
|
||||
if "start_date" in cleaned_data and not cleaned_data["start_date"]:
|
||||
|
@ -21,7 +21,7 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
from typing import Optional
|
||||
from __future__ import annotations
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import validators
|
||||
@ -46,9 +46,7 @@ def get_default_owner_group():
|
||||
|
||||
|
||||
class Club(models.Model):
|
||||
"""
|
||||
The Club class, made as a tree to allow nice tidy organization
|
||||
"""
|
||||
"""The Club class, made as a tree to allow nice tidy organization."""
|
||||
|
||||
id = models.AutoField(primary_key=True, db_index=True)
|
||||
name = models.CharField(_("name"), max_length=64)
|
||||
@ -141,7 +139,7 @@ class Club(models.Model):
|
||||
).first()
|
||||
|
||||
def check_loop(self):
|
||||
"""Raise a validation error when a loop is found within the parent list"""
|
||||
"""Raise a validation error when a loop is found within the parent list."""
|
||||
objs = []
|
||||
cur = self
|
||||
while cur.parent is not None:
|
||||
@ -223,9 +221,7 @@ class Club(models.Model):
|
||||
return self.name
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be super edited by the given user
|
||||
"""
|
||||
"""Method to see if that object can be super edited by the given user."""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return user.is_board_member
|
||||
@ -234,24 +230,21 @@ class Club(models.Model):
|
||||
return "https://%s%s" % (settings.SITH_URL, self.logo.url)
|
||||
|
||||
def can_be_edited_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be edited by the given user
|
||||
"""
|
||||
"""Method to see if that object can be edited by the given user."""
|
||||
return self.has_rights_in_club(user)
|
||||
|
||||
def can_be_viewed_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be seen by the given user
|
||||
"""
|
||||
"""Method to see if that object can be seen by the given user."""
|
||||
sub = User.objects.filter(pk=user.pk).first()
|
||||
if sub is None:
|
||||
return False
|
||||
return sub.was_subscribed
|
||||
|
||||
def get_membership_for(self, user: User) -> Optional["Membership"]:
|
||||
"""
|
||||
Return the current membership the given user.
|
||||
The result is cached.
|
||||
def get_membership_for(self, user: User) -> Membership | None:
|
||||
"""Return the current membership the given user.
|
||||
|
||||
Note:
|
||||
The result is cached.
|
||||
"""
|
||||
if user.is_anonymous:
|
||||
return None
|
||||
@ -273,15 +266,12 @@ class Club(models.Model):
|
||||
|
||||
class MembershipQuerySet(models.QuerySet):
|
||||
def ongoing(self) -> "MembershipQuerySet":
|
||||
"""
|
||||
Filter all memberships which are not finished yet
|
||||
"""
|
||||
"""Filter all memberships which are not finished yet."""
|
||||
# noinspection PyTypeChecker
|
||||
return self.filter(Q(end_date=None) | Q(end_date__gte=timezone.now()))
|
||||
|
||||
def board(self) -> "MembershipQuerySet":
|
||||
"""
|
||||
Filter all memberships where the user is/was in the board.
|
||||
"""Filter all memberships where the user is/was in the board.
|
||||
|
||||
Be aware that users who were in the board in the past
|
||||
are included, even if there are no more members.
|
||||
@ -293,9 +283,9 @@ class MembershipQuerySet(models.QuerySet):
|
||||
return self.filter(role__gt=settings.SITH_MAXIMUM_FREE_ROLE)
|
||||
|
||||
def update(self, **kwargs):
|
||||
"""
|
||||
Work just like the default Django's update() method,
|
||||
but add a cache refresh for the elements of the queryset.
|
||||
"""Refresh the cache for the elements of the queryset.
|
||||
|
||||
Besides that, does the same job as a regular update method.
|
||||
|
||||
Be aware that this adds a db query to retrieve the updated objects
|
||||
"""
|
||||
@ -315,8 +305,7 @@ class MembershipQuerySet(models.QuerySet):
|
||||
)
|
||||
|
||||
def delete(self):
|
||||
"""
|
||||
Work just like the default Django's delete() method,
|
||||
"""Work just like the default Django's delete() method,
|
||||
but add a cache invalidation for the elements of the queryset
|
||||
before the deletion.
|
||||
|
||||
@ -332,8 +321,7 @@ class MembershipQuerySet(models.QuerySet):
|
||||
|
||||
|
||||
class Membership(models.Model):
|
||||
"""
|
||||
The Membership class makes the connection between User and Clubs
|
||||
"""The Membership class makes the connection between User and Clubs.
|
||||
|
||||
Both Users and Clubs can have many Membership objects:
|
||||
- a user can be a member of many clubs at a time
|
||||
@ -390,17 +378,13 @@ class Membership(models.Model):
|
||||
return reverse("club:club_members", kwargs={"club_id": self.club_id})
|
||||
|
||||
def is_owned_by(self, user):
|
||||
"""
|
||||
Method to see if that object can be super edited by the given user
|
||||
"""
|
||||
"""Method to see if that object can be super edited by the given user."""
|
||||
if user.is_anonymous:
|
||||
return False
|
||||
return user.is_board_member
|
||||
|
||||
def can_be_edited_by(self, user: User) -> bool:
|
||||
"""
|
||||
Check if that object can be edited by the given user
|
||||
"""
|
||||
"""Check if that object can be edited by the given user."""
|
||||
if user.is_root or user.is_board_member:
|
||||
return True
|
||||
membership = self.club.get_membership_for(user)
|
||||
@ -414,9 +398,10 @@ class Membership(models.Model):
|
||||
|
||||
|
||||
class Mailing(models.Model):
|
||||
"""
|
||||
This class correspond to a mailing list
|
||||
Remember that mailing lists should be validated by UTBM
|
||||
"""A Mailing list for a club.
|
||||
|
||||
Warning:
|
||||
Remember that mailing lists should be validated by UTBM.
|
||||
"""
|
||||
|
||||
club = models.ForeignKey(
|
||||
@ -508,9 +493,7 @@ class Mailing(models.Model):
|
||||
|
||||
|
||||
class MailingSubscription(models.Model):
|
||||
"""
|
||||
This class makes the link between user and mailing list
|
||||
"""
|
||||
"""Link between user and mailing list."""
|
||||
|
||||
mailing = models.ForeignKey(
|
||||
Mailing,
|
||||
|
126
club/tests.py
126
club/tests.py
@ -29,8 +29,8 @@ from sith.settings import SITH_BAR_MANAGER, SITH_MAIN_CLUB_ID
|
||||
|
||||
|
||||
class ClubTest(TestCase):
|
||||
"""
|
||||
Set up data for test cases related to clubs and membership
|
||||
"""Set up data for test cases related to clubs and membership.
|
||||
|
||||
The generated dataset is the one created by the populate command,
|
||||
plus the following modifications :
|
||||
|
||||
@ -94,8 +94,7 @@ class ClubTest(TestCase):
|
||||
|
||||
class MembershipQuerySetTest(ClubTest):
|
||||
def test_ongoing(self):
|
||||
"""
|
||||
Test that the ongoing queryset method returns the memberships that
|
||||
"""Test that the ongoing queryset method returns the memberships that
|
||||
are not ended.
|
||||
"""
|
||||
current_members = list(self.club.members.ongoing().order_by("id"))
|
||||
@ -108,9 +107,8 @@ class MembershipQuerySetTest(ClubTest):
|
||||
assert current_members == expected
|
||||
|
||||
def test_board(self):
|
||||
"""
|
||||
Test that the board queryset method returns the memberships
|
||||
of user in the club board
|
||||
"""Test that the board queryset method returns the memberships
|
||||
of user in the club board.
|
||||
"""
|
||||
board_members = list(self.club.members.board().order_by("id"))
|
||||
expected = [
|
||||
@ -123,9 +121,8 @@ class MembershipQuerySetTest(ClubTest):
|
||||
assert board_members == expected
|
||||
|
||||
def test_ongoing_board(self):
|
||||
"""
|
||||
Test that combining ongoing and board returns users
|
||||
who are currently board members of the club
|
||||
"""Test that combining ongoing and board returns users
|
||||
who are currently board members of the club.
|
||||
"""
|
||||
members = list(self.club.members.ongoing().board().order_by("id"))
|
||||
expected = [
|
||||
@ -136,9 +133,7 @@ class MembershipQuerySetTest(ClubTest):
|
||||
assert members == expected
|
||||
|
||||
def test_update_invalidate_cache(self):
|
||||
"""
|
||||
Test that the `update` queryset method properly invalidate cache
|
||||
"""
|
||||
"""Test that the `update` queryset method properly invalidate cache."""
|
||||
mem_skia = self.skia.memberships.get(club=self.club)
|
||||
cache.set(f"membership_{mem_skia.club_id}_{mem_skia.user_id}", mem_skia)
|
||||
self.skia.memberships.update(end_date=localtime(now()).date())
|
||||
@ -157,10 +152,7 @@ class MembershipQuerySetTest(ClubTest):
|
||||
assert new_mem.role == 5
|
||||
|
||||
def test_delete_invalidate_cache(self):
|
||||
"""
|
||||
Test that the `delete` queryset properly invalidate cache
|
||||
"""
|
||||
|
||||
"""Test that the `delete` queryset properly invalidate cache."""
|
||||
mem_skia = self.skia.memberships.get(club=self.club)
|
||||
mem_comptable = self.comptable.memberships.get(club=self.club)
|
||||
cache.set(f"membership_{mem_skia.club_id}_{mem_skia.user_id}", mem_skia)
|
||||
@ -180,9 +172,7 @@ class MembershipQuerySetTest(ClubTest):
|
||||
|
||||
class ClubModelTest(ClubTest):
|
||||
def assert_membership_started_today(self, user: User, role: int):
|
||||
"""
|
||||
Assert that the given membership is active and started today
|
||||
"""
|
||||
"""Assert that the given membership is active and started today."""
|
||||
membership = user.memberships.ongoing().filter(club=self.club).first()
|
||||
assert membership is not None
|
||||
assert localtime(now()).date() == membership.start_date
|
||||
@ -195,17 +185,14 @@ class ClubModelTest(ClubTest):
|
||||
assert user.is_in_group(name=board_group)
|
||||
|
||||
def assert_membership_ended_today(self, user: User):
|
||||
"""
|
||||
Assert that the given user have a membership which ended today
|
||||
"""
|
||||
"""Assert that the given user have a membership which ended today."""
|
||||
today = localtime(now()).date()
|
||||
assert user.memberships.filter(club=self.club, end_date=today).exists()
|
||||
assert self.club.get_membership_for(user) is None
|
||||
|
||||
def test_access_unauthorized(self):
|
||||
"""
|
||||
Test that users who never subscribed and anonymous users
|
||||
cannot see the page
|
||||
"""Test that users who never subscribed and anonymous users
|
||||
cannot see the page.
|
||||
"""
|
||||
response = self.client.post(self.members_url)
|
||||
assert response.status_code == 403
|
||||
@ -215,8 +202,7 @@ class ClubModelTest(ClubTest):
|
||||
assert response.status_code == 403
|
||||
|
||||
def test_display(self):
|
||||
"""
|
||||
Test that a GET request return a page where the requested
|
||||
"""Test that a GET request return a page where the requested
|
||||
information are displayed.
|
||||
"""
|
||||
self.client.force_login(self.skia)
|
||||
@ -251,9 +237,7 @@ class ClubModelTest(ClubTest):
|
||||
self.assertInHTML(expected_html, response.content.decode())
|
||||
|
||||
def test_root_add_one_club_member(self):
|
||||
"""
|
||||
Test that root users can add members to clubs, one at a time
|
||||
"""
|
||||
"""Test that root users can add members to clubs, one at a time."""
|
||||
self.client.force_login(self.root)
|
||||
response = self.client.post(
|
||||
self.members_url,
|
||||
@ -264,9 +248,7 @@ class ClubModelTest(ClubTest):
|
||||
self.assert_membership_started_today(self.subscriber, role=3)
|
||||
|
||||
def test_root_add_multiple_club_member(self):
|
||||
"""
|
||||
Test that root users can add multiple members at once to clubs
|
||||
"""
|
||||
"""Test that root users can add multiple members at once to clubs."""
|
||||
self.client.force_login(self.root)
|
||||
response = self.client.post(
|
||||
self.members_url,
|
||||
@ -281,8 +263,7 @@ class ClubModelTest(ClubTest):
|
||||
self.assert_membership_started_today(self.krophil, role=3)
|
||||
|
||||
def test_add_unauthorized_members(self):
|
||||
"""
|
||||
Test that users who are not currently subscribed
|
||||
"""Test that users who are not currently subscribed
|
||||
cannot be members of clubs.
|
||||
"""
|
||||
self.client.force_login(self.root)
|
||||
@ -302,9 +283,8 @@ class ClubModelTest(ClubTest):
|
||||
assert '<ul class="errorlist"><li>' in response.content.decode()
|
||||
|
||||
def test_add_members_already_members(self):
|
||||
"""
|
||||
Test that users who are already members of a club
|
||||
cannot be added again to this club
|
||||
"""Test that users who are already members of a club
|
||||
cannot be added again to this club.
|
||||
"""
|
||||
self.client.force_login(self.root)
|
||||
current_membership = self.skia.memberships.ongoing().get(club=self.club)
|
||||
@ -320,8 +300,7 @@ class ClubModelTest(ClubTest):
|
||||
assert self.club.get_membership_for(self.skia) == new_membership
|
||||
|
||||
def test_add_not_existing_users(self):
|
||||
"""
|
||||
Test that not existing users cannot be added in clubs.
|
||||
"""Test that not existing users cannot be added in clubs.
|
||||
If one user in the request is invalid, no membership creation at all
|
||||
can take place.
|
||||
"""
|
||||
@ -349,9 +328,7 @@ class ClubModelTest(ClubTest):
|
||||
assert self.club.members.count() == nb_memberships
|
||||
|
||||
def test_president_add_members(self):
|
||||
"""
|
||||
Test that the president of the club can add members
|
||||
"""
|
||||
"""Test that the president of the club can add members."""
|
||||
president = self.club.members.get(role=10).user
|
||||
nb_club_membership = self.club.members.count()
|
||||
nb_subscriber_memberships = self.subscriber.memberships.count()
|
||||
@ -368,8 +345,7 @@ class ClubModelTest(ClubTest):
|
||||
self.assert_membership_started_today(self.subscriber, role=9)
|
||||
|
||||
def test_add_member_greater_role(self):
|
||||
"""
|
||||
Test that a member of the club member cannot create
|
||||
"""Test that a member of the club member cannot create
|
||||
a membership with a greater role than its own.
|
||||
"""
|
||||
self.client.force_login(self.skia)
|
||||
@ -388,9 +364,7 @@ class ClubModelTest(ClubTest):
|
||||
assert not self.subscriber.memberships.filter(club=self.club).exists()
|
||||
|
||||
def test_add_member_without_role(self):
|
||||
"""
|
||||
Test that trying to add members without specifying their role fails
|
||||
"""
|
||||
"""Test that trying to add members without specifying their role fails."""
|
||||
self.client.force_login(self.root)
|
||||
response = self.client.post(
|
||||
self.members_url,
|
||||
@ -402,9 +376,7 @@ class ClubModelTest(ClubTest):
|
||||
)
|
||||
|
||||
def test_end_membership_self(self):
|
||||
"""
|
||||
Test that a member can end its own membership
|
||||
"""
|
||||
"""Test that a member can end its own membership."""
|
||||
self.client.force_login(self.skia)
|
||||
self.client.post(
|
||||
self.members_url,
|
||||
@ -414,9 +386,8 @@ class ClubModelTest(ClubTest):
|
||||
self.assert_membership_ended_today(self.skia)
|
||||
|
||||
def test_end_membership_lower_role(self):
|
||||
"""
|
||||
Test that board members of the club can end memberships
|
||||
of users with lower roles
|
||||
"""Test that board members of the club can end memberships
|
||||
of users with lower roles.
|
||||
"""
|
||||
# remainder : skia has role 3, comptable has role 10, richard has role 1
|
||||
self.client.force_login(self.skia)
|
||||
@ -429,9 +400,8 @@ class ClubModelTest(ClubTest):
|
||||
self.assert_membership_ended_today(self.richard)
|
||||
|
||||
def test_end_membership_higher_role(self):
|
||||
"""
|
||||
Test that board members of the club cannot end memberships
|
||||
of users with higher roles
|
||||
"""Test that board members of the club cannot end memberships
|
||||
of users with higher roles.
|
||||
"""
|
||||
membership = self.comptable.memberships.filter(club=self.club).first()
|
||||
self.client.force_login(self.skia)
|
||||
@ -448,9 +418,8 @@ class ClubModelTest(ClubTest):
|
||||
assert membership.end_date is None
|
||||
|
||||
def test_end_membership_as_main_club_board(self):
|
||||
"""
|
||||
Test that board members of the main club can end the membership
|
||||
of anyone
|
||||
"""Test that board members of the main club can end the membership
|
||||
of anyone.
|
||||
"""
|
||||
# make subscriber a board member
|
||||
self.subscriber.memberships.all().delete()
|
||||
@ -467,9 +436,7 @@ class ClubModelTest(ClubTest):
|
||||
assert self.club.members.ongoing().count() == nb_memberships - 1
|
||||
|
||||
def test_end_membership_as_root(self):
|
||||
"""
|
||||
Test that root users can end the membership of anyone
|
||||
"""
|
||||
"""Test that root users can end the membership of anyone."""
|
||||
nb_memberships = self.club.members.count()
|
||||
self.client.force_login(self.root)
|
||||
response = self.client.post(
|
||||
@ -482,9 +449,7 @@ class ClubModelTest(ClubTest):
|
||||
assert self.club.members.count() == nb_memberships
|
||||
|
||||
def test_end_membership_as_foreigner(self):
|
||||
"""
|
||||
Test that users who are not in this club cannot end its memberships
|
||||
"""
|
||||
"""Test that users who are not in this club cannot end its memberships."""
|
||||
nb_memberships = self.club.members.count()
|
||||
membership = self.richard.memberships.filter(club=self.club).first()
|
||||
self.client.force_login(self.subscriber)
|
||||
@ -498,9 +463,8 @@ class ClubModelTest(ClubTest):
|
||||
assert membership == new_mem
|
||||
|
||||
def test_delete_remove_from_meta_group(self):
|
||||
"""
|
||||
Test that when a club is deleted, all its members are removed from the
|
||||
associated metagroup
|
||||
"""Test that when a club is deleted, all its members are removed from the
|
||||
associated metagroup.
|
||||
"""
|
||||
memberships = self.club.members.select_related("user")
|
||||
users = [membership.user for membership in memberships]
|
||||
@ -511,9 +475,7 @@ class ClubModelTest(ClubTest):
|
||||
assert not user.is_in_group(name=meta_group)
|
||||
|
||||
def test_add_to_meta_group(self):
|
||||
"""
|
||||
Test that when a membership begins, the user is added to the meta group
|
||||
"""
|
||||
"""Test that when a membership begins, the user is added to the meta group."""
|
||||
group_members = self.club.unix_name + settings.SITH_MEMBER_SUFFIX
|
||||
board_members = self.club.unix_name + settings.SITH_BOARD_SUFFIX
|
||||
assert not self.subscriber.is_in_group(name=group_members)
|
||||
@ -523,9 +485,7 @@ class ClubModelTest(ClubTest):
|
||||
assert self.subscriber.is_in_group(name=board_members)
|
||||
|
||||
def test_remove_from_meta_group(self):
|
||||
"""
|
||||
Test that when a membership ends, the user is removed from meta group
|
||||
"""
|
||||
"""Test that when a membership ends, the user is removed from meta group."""
|
||||
group_members = self.club.unix_name + settings.SITH_MEMBER_SUFFIX
|
||||
board_members = self.club.unix_name + settings.SITH_BOARD_SUFFIX
|
||||
assert self.comptable.is_in_group(name=group_members)
|
||||
@ -535,9 +495,7 @@ class ClubModelTest(ClubTest):
|
||||
assert not self.comptable.is_in_group(name=board_members)
|
||||
|
||||
def test_club_owner(self):
|
||||
"""
|
||||
Test that a club is owned only by board members of the main club
|
||||
"""
|
||||
"""Test that a club is owned only by board members of the main club."""
|
||||
anonymous = AnonymousUser()
|
||||
assert not self.club.is_owned_by(anonymous)
|
||||
assert not self.club.is_owned_by(self.subscriber)
|
||||
@ -549,7 +507,7 @@ class ClubModelTest(ClubTest):
|
||||
|
||||
|
||||
class MailingFormTest(TestCase):
|
||||
"""Perform validation tests for MailingForm"""
|
||||
"""Perform validation tests for MailingForm."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
@ -865,9 +823,7 @@ class MailingFormTest(TestCase):
|
||||
|
||||
|
||||
class ClubSellingViewTest(TestCase):
|
||||
"""
|
||||
Perform basics tests to ensure that the page is available
|
||||
"""
|
||||
"""Perform basics tests to ensure that the page is available."""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
@ -875,9 +831,7 @@ class ClubSellingViewTest(TestCase):
|
||||
cls.skia = User.objects.get(username="skia")
|
||||
|
||||
def test_page_not_internal_error(self):
|
||||
"""
|
||||
Test that the page does not return and internal error
|
||||
"""
|
||||
"""Test that the page does not return and internal error."""
|
||||
self.client.force_login(self.skia)
|
||||
response = self.client.get(
|
||||
reverse("club:club_sellings", kwargs={"club_id": self.ae.id})
|
||||
|
@ -175,18 +175,14 @@ class ClubTabsMixin(TabedViewMixin):
|
||||
|
||||
|
||||
class ClubListView(ListView):
|
||||
"""
|
||||
List the Clubs
|
||||
"""
|
||||
"""List the Clubs."""
|
||||
|
||||
model = Club
|
||||
template_name = "club/club_list.jinja"
|
||||
|
||||
|
||||
class ClubView(ClubTabsMixin, DetailView):
|
||||
"""
|
||||
Front page of a Club
|
||||
"""
|
||||
"""Front page of a Club."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
@ -201,9 +197,7 @@ class ClubView(ClubTabsMixin, DetailView):
|
||||
|
||||
|
||||
class ClubRevView(ClubView):
|
||||
"""
|
||||
Display a specific page revision
|
||||
"""
|
||||
"""Display a specific page revision."""
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
@ -235,9 +229,7 @@ class ClubPageEditView(ClubTabsMixin, PageEditViewBase):
|
||||
|
||||
|
||||
class ClubPageHistView(ClubTabsMixin, CanViewMixin, DetailView):
|
||||
"""
|
||||
Modification hostory of the page
|
||||
"""
|
||||
"""Modification hostory of the page."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
@ -246,9 +238,7 @@ class ClubPageHistView(ClubTabsMixin, CanViewMixin, DetailView):
|
||||
|
||||
|
||||
class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
|
||||
"""
|
||||
Tools page of a Club
|
||||
"""
|
||||
"""Tools page of a Club."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
@ -257,9 +247,7 @@ class ClubToolsView(ClubTabsMixin, CanEditMixin, DetailView):
|
||||
|
||||
|
||||
class ClubMembersView(ClubTabsMixin, CanViewMixin, DetailFormView):
|
||||
"""
|
||||
View of a club's members
|
||||
"""
|
||||
"""View of a club's members."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
@ -280,9 +268,7 @@ class ClubMembersView(ClubTabsMixin, CanViewMixin, DetailFormView):
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
"""
|
||||
Check user rights
|
||||
"""
|
||||
"""Check user rights."""
|
||||
resp = super().form_valid(form)
|
||||
|
||||
data = form.clean()
|
||||
@ -307,9 +293,7 @@ class ClubMembersView(ClubTabsMixin, CanViewMixin, DetailFormView):
|
||||
|
||||
|
||||
class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
||||
"""
|
||||
Old members of a club
|
||||
"""
|
||||
"""Old members of a club."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
@ -318,9 +302,7 @@ class ClubOldMembersView(ClubTabsMixin, CanViewMixin, DetailView):
|
||||
|
||||
|
||||
class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailFormView):
|
||||
"""
|
||||
Sellings of a club
|
||||
"""
|
||||
"""Sellings of a club."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
@ -396,12 +378,10 @@ class ClubSellingView(ClubTabsMixin, CanEditMixin, DetailFormView):
|
||||
|
||||
|
||||
class ClubSellingCSVView(ClubSellingView):
|
||||
"""
|
||||
Generate sellings in csv for a given period
|
||||
"""
|
||||
"""Generate sellings in csv for a given period."""
|
||||
|
||||
class StreamWriter:
|
||||
"""Implements a file-like interface for streaming the CSV"""
|
||||
"""Implements a file-like interface for streaming the CSV."""
|
||||
|
||||
def write(self, value):
|
||||
"""Write the value by returning it, instead of storing in a buffer."""
|
||||
@ -475,9 +455,7 @@ class ClubSellingCSVView(ClubSellingView):
|
||||
|
||||
|
||||
class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
|
||||
"""
|
||||
Edit a Club's main informations (for the club's members)
|
||||
"""
|
||||
"""Edit a Club's main informations (for the club's members)."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
@ -487,9 +465,7 @@ class ClubEditView(ClubTabsMixin, CanEditMixin, UpdateView):
|
||||
|
||||
|
||||
class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
||||
"""
|
||||
Edit the properties of a Club object (for the Sith admins)
|
||||
"""
|
||||
"""Edit the properties of a Club object (for the Sith admins)."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
@ -499,9 +475,7 @@ class ClubEditPropView(ClubTabsMixin, CanEditPropMixin, UpdateView):
|
||||
|
||||
|
||||
class ClubCreateView(CanCreateMixin, CreateView):
|
||||
"""
|
||||
Create a club (for the Sith admin)
|
||||
"""
|
||||
"""Create a club (for the Sith admin)."""
|
||||
|
||||
model = Club
|
||||
pk_url_kwarg = "club_id"
|
||||
@ -510,9 +484,7 @@ class ClubCreateView(CanCreateMixin, CreateView):
|
||||
|
||||
|
||||
class MembershipSetOldView(CanEditMixin, DetailView):
|
||||
"""
|
||||
Set a membership as beeing old
|
||||
"""
|
||||
"""Set a membership as beeing old."""
|
||||
|
||||
model = Membership
|
||||
pk_url_kwarg = "membership_id"
|
||||
@ -541,9 +513,7 @@ class MembershipSetOldView(CanEditMixin, DetailView):
|
||||
|
||||
|
||||
class MembershipDeleteView(UserIsRootMixin, DeleteView):
|
||||
"""
|
||||
Delete a membership (for admins only)
|
||||
"""
|
||||
"""Delete a membership (for admins only)."""
|
||||
|
||||
model = Membership
|
||||
pk_url_kwarg = "membership_id"
|
||||
@ -563,9 +533,7 @@ class ClubStatView(TemplateView):
|
||||
|
||||
|
||||
class ClubMailingView(ClubTabsMixin, CanEditMixin, DetailFormView):
|
||||
"""
|
||||
A list of mailing for a given club
|
||||
"""
|
||||
"""A list of mailing for a given club."""
|
||||
|
||||
model = Club
|
||||
form_class = MailingForm
|
||||
@ -603,9 +571,7 @@ class ClubMailingView(ClubTabsMixin, CanEditMixin, DetailFormView):
|
||||
return kwargs
|
||||
|
||||
def add_new_mailing(self, cleaned_data) -> ValidationError | None:
|
||||
"""
|
||||
Create a new mailing list from the form
|
||||
"""
|
||||
"""Create a new mailing list from the form."""
|
||||
mailing = Mailing(
|
||||
club=self.get_object(),
|
||||
email=cleaned_data["mailing_email"],
|
||||
@ -620,9 +586,7 @@ class ClubMailingView(ClubTabsMixin, CanEditMixin, DetailFormView):
|
||||
return None
|
||||
|
||||
def add_new_subscription(self, cleaned_data) -> ValidationError | None:
|
||||
"""
|
||||
Add mailing subscriptions for each user given and/or for the specified email in form
|
||||
"""
|
||||
"""Add mailing subscriptions for each user given and/or for the specified email in form."""
|
||||
users_to_save = []
|
||||
|
||||
for user in cleaned_data["subscription_users"]:
|
||||
@ -656,9 +620,7 @@ class ClubMailingView(ClubTabsMixin, CanEditMixin, DetailFormView):
|
||||
return None
|
||||
|
||||
def remove_subscription(self, cleaned_data):
|
||||
"""
|
||||
Remove specified users from a mailing list
|
||||
"""
|
||||
"""Remove specified users from a mailing list."""
|
||||
fields = [
|
||||
cleaned_data[key]
|
||||
for key in cleaned_data.keys()
|
||||
@ -742,7 +704,7 @@ class MailingAutoGenerationView(View):
|
||||
|
||||
|
||||
class PosterListView(ClubTabsMixin, PosterListBaseView, CanViewMixin):
|
||||
"""List communication posters"""
|
||||
"""List communication posters."""
|
||||
|
||||
def get_object(self):
|
||||
return self.club
|
||||
@ -755,7 +717,7 @@ class PosterListView(ClubTabsMixin, PosterListBaseView, CanViewMixin):
|
||||
|
||||
|
||||
class PosterCreateView(PosterCreateBaseView, CanCreateMixin):
|
||||
"""Create communication poster"""
|
||||
"""Create communication poster."""
|
||||
|
||||
pk_url_kwarg = "club_id"
|
||||
|
||||
@ -770,7 +732,7 @@ class PosterCreateView(PosterCreateBaseView, CanCreateMixin):
|
||||
|
||||
|
||||
class PosterEditView(ClubTabsMixin, PosterEditBaseView, CanEditMixin):
|
||||
"""Edit communication poster"""
|
||||
"""Edit communication poster."""
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("club:poster_list", kwargs={"club_id": self.club.id})
|
||||
@ -782,7 +744,7 @@ class PosterEditView(ClubTabsMixin, PosterEditBaseView, CanEditMixin):
|
||||
|
||||
|
||||
class PosterDeleteView(PosterDeleteBaseView, ClubTabsMixin, CanEditMixin):
|
||||
"""Delete communication poster"""
|
||||
"""Delete communication poster."""
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy("club:poster_list", kwargs={"club_id": self.club.id})
|
||||
|
Reference in New Issue
Block a user