diff --git a/apps/activity/forms.py b/apps/activity/forms.py
index 533ff7d1..4a13c230 100644
--- a/apps/activity/forms.py
+++ b/apps/activity/forms.py
@@ -1,6 +1,6 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
-from datetime import timedelta
+from datetime import timedelta, datetime
from django import forms
from django.contrib.contenttypes.models import ContentType
@@ -41,6 +41,9 @@ class GuestForm(forms.ModelForm):
def clean(self):
cleaned_data = super().clean()
+ if self.activity.date_start > datetime.now():
+ self.add_error("inviter", _("You can't invite someone once the activity is started."))
+
one_year = timedelta(days=365)
qs = Guest.objects.filter(
diff --git a/apps/activity/models.py b/apps/activity/models.py
index feae60d7..b17a9f6e 100644
--- a/apps/activity/models.py
+++ b/apps/activity/models.py
@@ -1,6 +1,6 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
-from datetime import timedelta
+from datetime import timedelta, datetime
from django.contrib.auth.models import User
from django.db import models
@@ -212,21 +212,25 @@ class Guest(models.Model):
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
one_year = timedelta(days=365)
- qs = Guest.objects.filter(
- first_name=self.first_name,
- last_name=self.last_name,
- activity__date_start__gte=self.activity.date_start - one_year,
- )
- if len(qs) >= 5:
- raise ValidationError(_("This person has been already invited 5 times this year."))
+ if not force_insert:
+ if self.activity.date_start > datetime.now():
+ raise ValidationError(_("You can't invite someone once the activity is started."))
- qs = qs.filter(activity=self.activity)
- if qs.exists():
- raise ValidationError(_("This person is already invited."))
+ qs = Guest.objects.filter(
+ first_name=self.first_name,
+ last_name=self.last_name,
+ activity__date_start__gte=self.activity.date_start - one_year,
+ )
+ if len(qs) >= 5:
+ raise ValidationError(_("This person has been already invited 5 times this year."))
- qs = Guest.objects.filter(inviter=self.inviter, activity=self.activity)
- if len(qs) >= 3:
- raise ValidationError(_("You can't invite more than 3 people to this activity."))
+ qs = qs.filter(activity=self.activity)
+ if qs.exists():
+ raise ValidationError(_("This person is already invited."))
+
+ qs = Guest.objects.filter(inviter=self.inviter, activity=self.activity)
+ if len(qs) >= 3:
+ raise ValidationError(_("You can't invite more than 3 people to this activity."))
return super().save(force_insert, force_update, using, update_fields)
diff --git a/apps/activity/views.py b/apps/activity/views.py
index 5df3493c..feb7591d 100644
--- a/apps/activity/views.py
+++ b/apps/activity/views.py
@@ -1,6 +1,6 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
-from datetime import datetime
+from datetime import datetime, timezone
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.contenttypes.models import ContentType
@@ -61,6 +61,8 @@ class ActivityDetailView(LoginRequiredMixin, DetailView):
.filter(PermissionBackend.filter_queryset(self.request.user, Guest, "view")))
ctx["guests"] = table
+ ctx["activity_started"] = datetime.now(timezone.utc) > self.object.date_start
+
return ctx
diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py
index d74d9147..89e2b31a 100644
--- a/apps/note/models/notes.py
+++ b/apps/note/models/notes.py
@@ -176,35 +176,6 @@ class NoteSpecial(Note):
return self.special_type
-class NoteCommon(Note):
- """
- A :model:`note.Note` for special accounts, where real money enter or leave the system
- - bank check
- - credit card
- - bank transfer
- - cash
- - refund
- This Type of Note is not associated to a :model:`auth.User` or :model:`member.Club` .
- """
- note_name = models.CharField(
- max_length=255,
- unique=True,
- )
-
- club = models.ForeignKey(
- Club,
- on_delete=models.PROTECT,
- verbose_name=_("club"),
- )
-
- class Meta:
- verbose_name = _("common note")
- verbose_name_plural = _("common notes")
-
- def __str__(self):
- return self.note_name
-
-
class Alias(models.Model):
"""
points toward a :model:`note.NoteUser` or :model;`note.NoteClub` instance.
diff --git a/templates/activity/activity_detail.html b/templates/activity/activity_detail.html
index 07c10a15..0ed3c719 100644
--- a/templates/activity/activity_detail.html
+++ b/templates/activity/activity_detail.html
@@ -66,7 +66,7 @@
{% if "view_"|has_perm:activity %}
{% trans "edit"|capfirst %}
{% endif %}
- {% if activity.activity_type.can_invite %}
+ {% if activity.activity_type.can_invite and not activity_started %}
{% trans "Invite" %}
{% endif %}