diff --git a/club/models.py b/club/models.py index 00c9239d..d446c080 100644 --- a/club/models.py +++ b/club/models.py @@ -276,18 +276,6 @@ class Membership(models.Model): _("description"), max_length=128, null=False, blank=True ) - def clean(self): - sub = User.objects.filter(pk=self.user.pk).first() - if sub is None or not sub.is_subscribed: - raise ValidationError(_("User must be subscriber to take part to a club")) - if ( - Membership.objects.filter(user=self.user) - .filter(club=self.club) - .filter(end_date=None) - .exists() - ): - raise ValidationError(_("User is already member of that club")) - def __str__(self): return ( self.club.name @@ -304,12 +292,15 @@ class Membership(models.Model): """ return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) - def can_be_edited_by(self, user): + def can_be_edited_by(self, user, membership=None): """ Method to see if that object can be edited by the given user """ if user.memberships: - ms = user.memberships.filter(club=self.club, end_date=None).first() + if membership: # This is for optimisation purpose + ms = membership + else: + ms = user.memberships.filter(club=self.club, end_date=None).first() return (ms and ms.role >= self.role) or user.is_in_group( settings.SITH_MAIN_BOARD_GROUP ) diff --git a/club/templates/club/club_members.jinja b/club/templates/club/club_members.jinja index 5f68a9df..7c378a7d 100644 --- a/club/templates/club/club_members.jinja +++ b/club/templates/club/club_members.jinja @@ -1,35 +1,80 @@ {% extends "core/base.jinja" %} -{% from 'core/macros.jinja' import user_profile_link %} +{% from 'core/macros.jinja' import user_profile_link, select_all_checkbox %} {% block content %}

{% trans %}Club members{% endtrans %}

- - - - - - - - - {% for m in club.members.filter(end_date=None).order_by('-role').all() %} - - - - - - {% if m.can_be_edited_by(user) %} - - {% endif %} - - {% endfor %} - -
{% trans %}User{% endtrans %}{% trans %}Role{% endtrans %}{% trans %}Description{% endtrans %}{% trans %}Since{% endtrans %}
{{ user_profile_link(m.user) }}{{ settings.SITH_CLUB_ROLES[m.role] }}{{ m.description }}{{ m.start_date }}{% trans %}Mark as old{% endtrans %}
-
+ {% if members %} + {% csrf_token %} - {{ form.as_p() }} + {% set users_old = dict(form.users_old | groupby("choice_label")) %} + {% if users_old %} + {{ select_all_checkbox("users_old") }} +

+ {% endif %} + + + + + + + {% if users_old %} + + {% endif %} + + + {% for m in members %} + + + + + + {% if users_old %} + + {% endif %} + + {% endfor %} + +
{% trans %}User{% endtrans %}{% trans %}Role{% endtrans %}{% trans %}Description{% endtrans %}{% trans %}Since{% endtrans %}{% trans %}Mark as old{% endtrans %}
{{ user_profile_link(m.user) }}{{ settings.SITH_CLUB_ROLES[m.role] }}{{ m.description }}{{ m.start_date }} + {% set user_old = users_old[m.user.get_display_name()] %} + {% if user_old %} + {{ user_old[0].tag() }} + {% endif %} +
+ {{ form.users_old.errors }} + {% if users_old %} +

+ + {% endif %} +
+ {% else %} +

{% trans %}There are no members in this club.{% endtrans %}

+ {% endif %} +
+ {% csrf_token %} + {{ form.non_field_errors() }} +

+ {{ form.users.errors }} + + {{ form.users }} + {{ form.users.help_text }} +

+

+ {{ form.role.errors }} + + {{ form.role }} +

+ {% if form.start_date %} +

+ {{ form.start_date.errors }} + + {{ form.start_date }} +

+ {% endif %} +

+ {{ form.description.errors }} + + {{ form.description }} +

{% endblock %} - - - diff --git a/club/tests.py b/club/tests.py index c0409a9f..25f6e019 100644 --- a/club/tests.py +++ b/club/tests.py @@ -44,30 +44,54 @@ class ClubTest(TestCase): self.client.login(username="root", password="plop") self.client.post( reverse("club:club_members", kwargs={"club_id": self.bdf.id}), - {"user": self.skia.id, "start_date": "12/06/2016", "role": 3}, + {"users": self.skia.id, "start_date": "12/06/2016", "role": 3}, ) response = self.client.get( reverse("club:club_members", kwargs={"club_id": self.bdf.id}) ) self.assertTrue(response.status_code == 200) self.assertTrue( - "S' Kia\\n Responsable info" + "S' Kia\\n Responsable info" in str(response.content) ) + def test_create_add_multiple_user_to_club_from_root_ok(self): + self.client.login(username="root", password="plop") + self.client.post( + reverse("club:club_members", kwargs={"club_id": self.bdf.id}), + { + "users": "|%d|%d|" % (self.skia.id, self.rbatsbak.id), + "start_date": "12/06/2016", + "role": 3, + }, + ) + response = self.client.get( + reverse("club:club_members", kwargs={"club_id": self.bdf.id}) + ) + self.assertTrue(response.status_code == 200) + content = str(response.content) + self.assertTrue( + "S' Kia\\n Responsable info" + in content + ) + self.assertTrue( + "Richard Batsbak\\n Responsable info" + in content + ) + def test_create_add_user_to_club_from_root_fail_not_subscriber(self): self.client.login(username="root", password="plop") response = self.client.post( reverse("club:club_members", kwargs={"club_id": self.bdf.id}), - {"user": self.guy.id, "start_date": "12/06/2016", "role": 3}, + {"users": self.guy.id, "start_date": "12/06/2016", "role": 3}, ) self.assertTrue(response.status_code == 200) - self.assertTrue('