mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
Guests can't be invited since the activity is started
This commit is contained in:
parent
fb5796d35e
commit
fcb4da2db3
@ -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(
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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.
|
||||
|
@ -66,7 +66,7 @@
|
||||
{% if "view_"|has_perm:activity %}
|
||||
<a class="btn btn-primary btn-sm my-1" href="{% url 'activity:activity_update' pk=activity.pk %}"> {% trans "edit"|capfirst %}</a>
|
||||
{% endif %}
|
||||
{% if activity.activity_type.can_invite %}
|
||||
{% if activity.activity_type.can_invite and not activity_started %}
|
||||
<a class="btn btn-primary btn-sm my-1" href="{% url 'activity:activity_invite' pk=activity.pk %}"> {% trans "Invite" %}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user