Allow a user to mark themselves as 'yes', 'no' or 'maybe' attending an event, and let them change that value later. Fixes #86

This commit is contained in:
Michael Hall 2018-05-12 15:53:07 -04:00
parent 376c06200b
commit 26404fdea6
3 changed files with 81 additions and 34 deletions

View file

@ -120,10 +120,19 @@ def attend_event(request, event_id):
if request.user.is_anonymous:
messages.add_message(request, messages.WARNING, message=_("You must be logged in to say you're attending."))
return redirect(event.get_absolute_url())
if request.user.profile in event.attendees.all():
messages.add_message(request, messages.INFO, message=_('You are already attending this event.'))
return redirect(event.get_absolute_url())
new_attendee = Attendee.objects.create(event=event, user=request.user.profile, role=Attendee.NORMAL, status=Attendee.YES)
try:
attendee = Attendee.objects.get(event=event, user=request.user.profile)
except:
attendee = Attendee(event=event, user=request.user.profile, role=Attendee.NORMAL)
attendee.status = Attendee.YES
if request.GET.get('response', None) == 'maybe':
attendee.status = Attendee.MAYBE
if request.GET.get('response', None) == 'no':
attendee.status = Attendee.NO
attendee.save()
if attendee.status == Attendee.YES:
messages.add_message(request, messages.SUCCESS, message=_("We'll see you there!"))
return redirect(event.get_absolute_url())

View file

@ -115,7 +115,16 @@
<a href="#" onClick="shareLinkedIn();" class="IN-widget btn btn-linkedin btn-sm"><i class="fa fa-linkedin"></i> Share</a>
{% endif %}
{% if not is_attending %}
<div class="btn-group">
<a href="{% url 'attend-event' event.id %}" class="btn btn-success btn-sm"><i class="fa fa-check-square-o"></i> Attend</a>
<button type="button" class="btn btn-success btn-sm dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Attendance options</span>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url 'attend-event' event.id %}?response=maybe">Maybe</a>
<a class="dropdown-item" href="{% url 'attend-event' event.id %}?response=no">No</a>
</div>
</div>
{% endif %}
{% if can_edit_event %}
<div class="btn-group dropdown">
@ -128,7 +137,6 @@
</div>
</div>
{% endif %}
<hr/>
<p>{{ event.summary|markdown }}</p>
@ -232,7 +240,7 @@
<div class="col-md-3">
<div class="container">
<div class="row">
<div class="col"><h4>Attendees ({{attendee_list.count}})</h4><hr/></div>
<div class="col"><h4>Attendees ({{attendee_count}})</h4><hr/></div>
</div>
{% for attendee in attendee_list %}
<div class="row mb-3">
@ -242,7 +250,36 @@
<div class="media-body">
<h6 class="mt-2 mb-0">
<a href="{% url 'show-profile' attendee.user.id %}" title="{{attendee.user}}'s profile">{{attendee.user}}</a>
<span class="badge badge-success align-top">{{ attendee.status_name }}</span></h6>
{% if attendee.user.user == request.user %}
{% if attendee.status == attendee.YES %}
<span class="badge badge-success dropdown-toggle align-top" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{ attendee.status_name }}</span>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url 'attend-event' event.id %}?response=maybe">Maybe</a>
<a class="dropdown-item" href="{% url 'attend-event' event.id %}?response=no">No</a>
</div>
{% elif attendee.status == attendee.MAYBE %}
<span class="badge badge-default dropdown-toggle align-top" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{ attendee.status_name }}</span>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url 'attend-event' event.id %}?response=yes">Yes</a>
<a class="dropdown-item" href="{% url 'attend-event' event.id %}?response=no">No</a>
</div>
{% elif attendee.status == attendee.NO %}
<span class="badge badge-danger dropdown-toggle align-top" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{ attendee.status_name }}</span>
<div class="dropdown-menu">
<a class="dropdown-item" href="{% url 'attend-event' event.id %}?response=yes">Yes</a>
<a class="dropdown-item" href="{% url 'attend-event' event.id %}?response=maybe">Maybe</a>
</div>
{% endif %}
{% else %}
{% if attendee.status == attendee.YES %}
<span class="badge badge-success align-top">{{ attendee.status_name }}</span>
{% elif attendee.status == attendee.MAYBE %}
<span class="badge badge-default align-top">{{ attendee.status_name }}</span>
{% elif attendee.status == attendee.NO %}
<span class="badge badge-danger align-top">{{ attendee.status_name }}</span>
{% endif %}
{% endif %}
</h6>
{% if attendee.role > 0 %}<small class="text-muted">{{ attendee.role_name }}</small>{% endif %}
</div>
</div>

View file

@ -69,7 +69,8 @@ def show_event(request, event_id, event_slug):
'event': event,
'comment_form': comment_form,
'is_attending': request.user.profile in event.attendees.all(),
'attendee_list': Attendee.objects.filter(event=event),
'attendee_list': Attendee.objects.filter(event=event).order_by('-status'),
'attendee_count': Attendee.objects.filter(event=event, status=Attendee.YES).count(),
'presentation_list': event.presentations.filter(status=Presentation.ACCEPTED).order_by('start_time'),
'pending_presentations': event.presentations.filter(status=Presentation.PROPOSED).count(),
'can_edit_event': request.user.profile.can_edit_event(event),