Commit 76c3a20b authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'fix/members-constraints' into 'master'

Add constraints to the members app

See merge request !658
parents 306d4d4c 66fbed06
......@@ -83,6 +83,30 @@ class UserCreationForm(BaseUserCreationForm):
class UserChangeForm(BaseUserChangeForm):
first_name = forms.CharField(
label=_('First name'),
required=True,
widget=forms.TextInput(attrs={
'class': 'vTextField',
'maxlength': 30
})
)
last_name = forms.CharField(
label=_('Last name'),
required=True,
widget=forms.TextInput(attrs={
'class': 'vTextField',
'maxlength': 150
})
)
email = forms.CharField(
label=_('Email address'),
required=True,
widget=forms.EmailInput(attrs={
'class': 'vTextField',
'maxlength': 254
})
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-11-22 15:49+0100\n"
"PO-Revision-Date: 2017-10-18 21:32+0200\n"
"POT-Creation-Date: 2018-01-12 12:40+0100\n"
"PO-Revision-Date: 2018-01-12 12:40+0100\n"
"Last-Translator: Sébastiaan Versteeg <se_bastiaan@outlook.com>\n"
"Language-Team: \n"
"Language: nl\n"
......@@ -38,11 +38,11 @@ msgstr "< 18"
msgid "Unknown"
msgstr "Onbekend"
#: admin.py:112 admin.py:131
#: admin.py:112 admin.py:131 forms.py:87
msgid "First name"
msgstr "Voornaam"
#: admin.py:112 admin.py:131
#: admin.py:112 admin.py:131 forms.py:94
msgid "Last name"
msgstr "Achternaam"
......@@ -114,6 +114,10 @@ msgstr "Stuur welkomste-mails"
msgid "This email will include the generated password"
msgstr "Deze e-mail zal het gegenereerde wachtwoord bevatten"
#: forms.py:101
msgid "Email address"
msgstr "E-mailadres"
#: models.py:109
msgid "Is this user currently active"
msgstr "Is deze user op dit moment actief"
......@@ -126,7 +130,7 @@ msgstr "Informatica"
msgid "Information Sciences"
msgstr "Informatiekunde"
#: models.py:158 templates/members/profile.html:40
#: models.py:158 templates/members/profile.html:44
msgid "Study programme"
msgstr "Studie"
......@@ -182,7 +186,7 @@ msgstr "Telefoonnummer noodcontact"
msgid "The phone number for the emergency contact"
msgstr "Het telefoonummer van de noodcontact"
#: models.py:248 templates/members/profile.html:47
#: models.py:248 templates/members/profile.html:52
msgid "Birthday"
msgstr "Verjaardag"
......@@ -198,7 +202,7 @@ msgstr ""
"Toon je verjaardag aan andere leden op je profielpagina en in de "
"verjaardagskalender"
#: models.py:262 templates/members/profile.html:43
#: models.py:262 templates/members/profile.html:48
msgid "Website"
msgstr "Website"
......@@ -336,42 +340,54 @@ msgid "You need to enter a nickname to use it as display name"
msgstr ""
"Je moet een bijnaam invoeren voordat je deze kunt gebruiken als weergavenaam"
#: models.py:447
#: models.py:413
msgid "A birthday cannot be in the future."
msgstr "Een verjaardag kan niet in de toekomst liggen."
#: models.py:450
msgid "Member"
msgstr "Lid"
#: models.py:448
#: models.py:451
msgid "Supporter"
msgstr "Begunstiger"
#: models.py:449
#: models.py:452
msgid "Honorary Member"
msgstr "Erelid"
#: models.py:454 templates/members/profile.html:37
#: models.py:457 templates/members/profile.html:37
msgid "Membership type"
msgstr "Lidtype"
#: models.py:462
#: models.py:463
msgid "User"
msgstr "Gebruiker"
#: models.py:466
#: models.py:467
msgid "Membership since"
msgstr "Lid sinds"
#: models.py:467
#: models.py:468
msgid "The date the member started holding this membership."
msgstr "De datum waarop het lid dit lidmaatschap is begonnen."
#: models.py:472
#: models.py:473
msgid "Membership until"
msgstr "Lid tot"
#: models.py:473
#: models.py:474
msgid "The date the member stops holding this membership."
msgstr "De datum waarop het lid dit lidmaatschap beëindigd."
#: models.py:485
msgid "End date can't be before start date"
msgstr "De einddatum kan niet eerder zijn dan de startdatum"
#: models.py:499 models.py:501
msgid "A membership already exists for that period"
msgstr "Er bestaat al een lidmaatschap voor deze periode"
#: templates/admin/members/change_list.html:6
msgid "Export IBANs for Direct Debit"
msgstr "Exporteer IBANs voor automatische incasso"
......@@ -718,7 +734,7 @@ msgstr "Oud-leden"
msgid "No members found"
msgstr "Geen leden gevonden"
#: templates/members/index.html:67 templates/members/profile.html:38
#: templates/members/index.html:67 templates/members/profile.html:40
msgid "Cohort"
msgstr "Cohort"
......@@ -742,15 +758,15 @@ msgstr "Dit lid heeft nog geen beschrijving geschreven."
msgid "Personal information"
msgstr "Persoonlijke gegevens"
#: templates/members/profile.html:53
#: templates/members/profile.html:58
msgid "Achievements for Thalia"
msgstr "Verdiensten voor Thalia"
#: templates/members/profile.html:63
#: templates/members/profile.html:68
msgid "Chair"
msgstr "Voorzitter"
#: templates/members/profile.html:65
#: templates/members/profile.html:70
msgid "today"
msgstr "heden"
......@@ -778,3 +794,9 @@ msgstr "Oud-lid"
#: views.py:131
msgid "Former supporter"
msgstr "Oud-begunstiger"
#~ msgid "first name"
#~ msgstr "voornaam"
#~ msgid "last name"
#~ msgstr "achternaam"
......@@ -402,13 +402,20 @@ class Profile(models.Model):
def clean(self):
super().clean()
errors = {}
if self.display_name_preference in ('nickname', 'fullnick',
'nicklast'):
if not self.nickname:
errors.update(
{'nickname': _('You need to enter a nickname to use it as '
'display name')})
raise ValidationError(errors)
if self.birthday and self.birthday > timezone.now().date():
errors.update(
{'birthday': _('A birthday cannot be in the future.')})
if errors:
raise ValidationError(errors)
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
......@@ -454,8 +461,6 @@ class Membership(models.Model):
verbose_name=_('Membership type'),
)
# Preferably this would have been a foreign key to Member instead,
# but the UserAdmin requires that this is a foreign key to User.
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
......@@ -475,6 +480,34 @@ class Membership(models.Model):
null=True,
)
def clean(self):
super().clean()
errors = {}
if self.until and (not self.since or self.until < self.since):
raise ValidationError(
{'until': _("End date can't be before start date")})
if self.since is not None:
memberships = self.user.membership_set.all()
for membership in memberships:
if membership.pk == self.pk:
continue
if ((membership.until is None and (
self.until is None or self.until > membership.since)) or
(self.until is None and self.since < membership.until) or
(self.until and membership.until and
self.since < membership.until and
self.until > membership.since)):
errors.update({
'since': _('A membership already '
'exists for that period'),
'until': _('A membership already '
'exists for that period')})
if errors:
raise ValidationError(errors)
def is_active(self):
return not self.until or self.until > timezone.now().date()
......
Supports Markdown
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