Commit c7ab33c4 authored by Wietse Kuipers's avatar Wietse Kuipers

Adds a event_permissions attribute and checks

Allows to ban users from attending events in a discrete manner
parent 52b0b9c1
......@@ -87,7 +87,7 @@
<tr>
<td></td>
<td>
{% if request.user.is_authenticated and request.user.member is not None and request.user.member.current_membership is not None %}
{% if request.user.is_authenticated and request.user.member is not None and request.user.member.current_membership is not None and request.user.member.can_attend_events %}
{% if event.status == event.REGISTRATION_OPEN or event.status == event.REGISTRATION_OPEN_NO_CANCEL %}
{% if registration is not None and registration.date_cancelled is None and event.has_fields %}
<a class="btn btn-style1" href="{% url 'events:registration' event.id 'update' %}">{% trans "Update registration" %}</a>
......
......@@ -183,7 +183,8 @@ def registration(request, event_id, action=None):
)
if (event.status != Event.REGISTRATION_NOT_NEEDED and
request.user.member.current_membership is not None):
request.user.member.current_membership is not None and
request.user.member.can_attend_events):
try:
obj = Registration.objects.get(
event=event,
......@@ -214,6 +215,8 @@ def registration(request, event_id, action=None):
else:
obj.date = timezone.now()
obj.date_cancelled = None
elif not obj.member.can_attend_events:
error_message = _("You may not register")
else:
error_message = _("You were already registered.")
......@@ -229,28 +232,31 @@ def registration(request, event_id, action=None):
elif action == 'cancel':
if (obj is not None and
obj.date_cancelled is None):
# Prepare email to send to the first person on the waiting list
first_waiting = (Registration.objects
.filter(event=event, date_cancelled=None)
.order_by('date')[event.max_participants])
first_waiting_member = first_waiting.member
text_template = get_template('events/email.txt')
with translation.override(first_waiting_member.language):
subject = _("[THALIA] Notification about your "
"registration for '{}'").format(event.title)
text_message = text_template.render(Context({
'event': event,
'registration': first_waiting,
'member': first_waiting_member
}))
waiting_list_notification = EmailMessage(
subject,
text_message,
to=[first_waiting_member.user.email]
)
if event.max_participants is not None:
# Prepare email to send to the first person on the waiting
# list
first_waiting = (Registration.objects
.filter(event=event, date_cancelled=None)
.order_by('date')[event.max_participants])
first_waiting_member = first_waiting.member
text_template = get_template('events/email.txt')
with translation.override(first_waiting_member.language):
subject = _("[THALIA] Notification about your "
"registration for '{}'").format(
event.title)
text_message = text_template.render(Context({
'event': event,
'registration': first_waiting,
'member': first_waiting_member
}))
waiting_list_notification = EmailMessage(
subject,
text_message,
to=[first_waiting_member.user.email]
)
# Note that this doesn't remove the values for the
# information fields that the user entered upon registering.
......@@ -269,8 +275,8 @@ def registration(request, event_id, action=None):
form_field_values = form.field_values()
for field in form_field_values:
if (field['field'].type ==
RegistrationInformationField.INTEGER_FIELD
and field['value'] is None):
RegistrationInformationField.INTEGER_FIELD and
field['value'] is None):
field['value'] = 0
field['field'].set_value_for(obj,
field['value'])
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2016-11-09 20:00
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('members', '0012_auto_20161104_2119'),
]
operations = [
migrations.AddField(
model_name='member',
name='blacklisted',
field=models.CharField(choices=[('all', 'All events'), ('no_events', 'User may not attend events'), ('no_drinks', 'User may not attend drinks'), ('nothing', 'User may not attend anything')], default='all', max_length=9, verbose_name='Which events can this member attend'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2016-11-09 20:28
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('members', '0013_member_blacklisted'),
]
operations = [
migrations.RenameField(
model_name='member',
old_name='blacklisted',
new_name='event_permissions',
),
]
......@@ -252,6 +252,21 @@ class Member(models.Model):
blank=True,
)
event_permissions = models.CharField(
max_length=9,
verbose_name=_('Which events can this member attend'),
choices=(('all', _('All events')),
('no_events', _('User may not attend events')),
('no_drinks', _('User may not attend drinks')),
('nothing', _('User may not attend anything'))),
default='all',
)
@property
def can_attend_events(self):
return (self.event_permissions == 'all' or
self.event_permissions == 'no_drinks')
# --- Communication preference ----
language = models.CharField(
......
Markdown is supported
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