Commit 2117a728 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Merge branch 'feature/add_registration_indication' into 'master'

Voegt een indicatie toe voor evenementen of men aangemeld is

Closes #123

See merge request !371
parents e8b71a97 2db8460e
......@@ -2,7 +2,7 @@ from django.urls import reverse
from django.utils import timezone
from rest_framework import serializers
from events.models import Event
from events.models import Event, Registration
class CalenderJSSerializer(serializers.ModelSerializer):
......@@ -10,7 +10,8 @@ class CalenderJSSerializer(serializers.ModelSerializer):
fields = (
'start', 'end', 'all_day', 'is_birthday',
'url', 'title', 'description',
'backgroundColor', 'textColor', 'blank'
'backgroundColor', 'textColor', 'blank',
'registered'
)
start = serializers.SerializerMethodField('_start')
......@@ -23,6 +24,7 @@ class CalenderJSSerializer(serializers.ModelSerializer):
backgroundColor = serializers.SerializerMethodField('_background_color')
textColor = serializers.SerializerMethodField('_text_color')
blank = serializers.SerializerMethodField('_target_blank')
registered = serializers.SerializerMethodField('_registered')
def _start(self, instance):
return timezone.localtime(instance.start)
......@@ -54,6 +56,9 @@ class CalenderJSSerializer(serializers.ModelSerializer):
def _target_blank(self, instance):
return False
def _registered(self, instance):
return None
class EventSerializer(CalenderJSSerializer):
class Meta(CalenderJSSerializer.Meta):
......@@ -61,3 +66,20 @@ class EventSerializer(CalenderJSSerializer):
def _url(self, instance):
return reverse('events:event', kwargs={'event_id': instance.id})
def _registered(self, instance):
try:
if not self.context['user'].member:
return None
except AttributeError:
return None
try:
registration = Registration.objects.get(
event=instance,
member=self.context['user'].member
)
except (Registration.DoesNotExist, AttributeError):
return False
return registration.is_registered()
......@@ -29,5 +29,6 @@ class EventViewset(viewsets.ViewSet):
published=True
)
serializer = EventSerializer(queryset, many=True)
serializer = EventSerializer(queryset, many=True,
context={'user': request.user})
return Response(serializer.data)
......@@ -135,6 +135,13 @@ class Event(models.Model, metaclass=ModelTranslateMeta):
self.max_participants <= self.registration_set.filter(
date_cancelled=None).count())
def is_member_registered(self, member):
if not self.registration_required():
return None
registrations = self.registration_set.filter(member=member)
return len(registrations) == 1 and registrations[0].is_registered()
@property
def status(self):
now = timezone.now()
......
.registration-unsaved-changes {
color: #E62272;
}
\ No newline at end of file
......@@ -39,6 +39,11 @@ ListView = View.extend({ // make a subclass of View
li.append('<div class="toggle-content">' + e.description + '<br><br><a href="' + e.url + '">> Naar de evenementpagina</a></div>');
}
}
if (e.registered) {
li.append('<div class="event-indication-has-registration"></div>');
} else if (e.registered !== null) {
li.append('<div class="event-indication-no-registration"></div>');
}
ul.append(li);
}
// This originates from theme_thimbus/themes/thimbus/assets/js/scripts_dev.js,
......
<div class="blog">
<ul class="row">
{% for event in events %}
{% for next_event in upcoming %}
<li class="post span6 has-overlay event">
<a href="{{ event.get_absolute_url }}">
<a href="{{ next_event.event.get_absolute_url }}">
<div class="post-inner">
<div class="post-body"><h2>{{ event.title }}</h2>
<div class="post-body"><h2>{{ next_event.event.title }}</h2>
{% if next_event.current_user_registration is not None %}
{% if next_event.current_user_registration %}
<div class="event-indication-no-registration"></div>
{% else %}
<div class="event-indication-has-registration"></div>
{% endif %}
{% endif %}
<div class="post-date circle">
<div class="circle-border"></div>
<div class="circle-inner">{{ event.start.day }}<span>{{ event.start|date:"M" }}</span></div>
<div class="circle-inner">{{ next_event.event.start.day }}<span>{{ next_event.event.start|date:"M" }}</span></div>
</div>
<div class="post-excerpt">
<p>{{ event.description|striptags|safe }}</p>
<p>{{ next_event.event.description|striptags|safe }}</p>
</div>
</div>
</div>
......@@ -18,4 +27,4 @@
</li>
{% endfor %}
</ul>
</div>
\ No newline at end of file
</div>
......@@ -6,10 +6,23 @@ from events.models import Event
register = template.Library()
@register.inclusion_tag('events/cards.html')
def show_cards():
@register.inclusion_tag('events/cards.html', takes_context=True)
def show_cards(context):
upcoming_events = Event.objects.filter(
published=True,
end__gte=timezone.now()
).order_by('end')
return {'events': upcoming_events[:4]}
try:
upcoming = [{
'event': x,
'current_user_registration': x.is_member_registered(
context['user'].member)
} for x in upcoming_events[:4]]
except AttributeError:
upcoming = [{
'event': x,
'current_user_registration': None
} for x in upcoming_events[:4]]
return {'upcoming': upcoming}
......@@ -4974,6 +4974,26 @@ ul.rslides > li {
transition: all 0.2s ease-in-out;
}
.event-indication-no-registration, .event-indication-has-registration {
float: right;
position: absolute;
right: 24px;
top: calc(50% - 5px);
border-radius: 10px;
width: 10px;
height: 10px;
}
.event-indication-has-registration {
background: #468847;
box-shadow: 0 0 5px #468847;
}
.event-indication-no-registration {
background: #d9534f;
box-shadow: 0 0 5px #d9534f;
}
.loginForm {
text-align: center;
}
......
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