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,11 +120,20 @@ 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)
messages.add_message(request, messages.SUCCESS, message=_("We'll see you there!"))
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())
def comment_event(request, event_id):

View file

@ -102,33 +102,41 @@
<h2>{{ event.name }}
</h2>
<p class="text-muted">Hosted by <a href="{% url "show-team" team.id %}">{{ team.name }}</a></p>
{% if can_edit_team or is_email_confirmed %}
<a href="{% url 'invite-attendees' event.id %}" class="btn btn-danger btn-sm"><i class="fa fa-envelope"></i> Invite</a>
{% endif %}
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}
<a href="https://twitter.com/intent/tweet?text=I'm+having+a+get+together!%0D{{event.name|urlencode}}&original_referer={{event.get_full_url|urlencode}}&url={{event.get_full_url|urlencode}}&hashtags=gettogether" data-size="large" class="btn btn-twitter btn-sm"><i class="fa fa-twitter"></i> Tweet</a>
{% endif %}
{% if settings.SOCIAL_AUTH_FACEBOOK_KEY %}
<a href="#" onClick="shareFacebook();" class="btn btn-facebook btn-sm"><i class="fa fa-facebook-official"></i> Share</a>
{% endif %}
{% if settings.SOCIAL_AUTH_LINKEDIN_KEY %}
<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 %}
<a href="{% url 'attend-event' event.id %}" class="btn btn-success btn-sm"><i class="fa fa-check-square-o"></i> Attend</a>
{% endif %}
{% if can_edit_event %}
<div class="btn-group dropdown">
<button class="btn btn-sm btn-secondary dropdown-toggle" type="button" id="editMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Edit
</button>
<div class="dropdown-menu" aria-labelledby="editMenuButton">
<a href="{% url 'edit-event' event.id %}" class="dropdown-item">Event Details</a>
<a href="{% url 'schedule-event-talks' event.id %}" class="dropdown-item">Manage Talks</a>
</div>
{% if can_edit_team or is_email_confirmed %}
<a href="{% url 'invite-attendees' event.id %}" class="btn btn-danger btn-sm"><i class="fa fa-envelope"></i> Invite</a>
{% endif %}
{% if settings.SOCIAL_AUTH_TWITTER_KEY %}
<a href="https://twitter.com/intent/tweet?text=I'm+having+a+get+together!%0D{{event.name|urlencode}}&original_referer={{event.get_full_url|urlencode}}&url={{event.get_full_url|urlencode}}&hashtags=gettogether" data-size="large" class="btn btn-twitter btn-sm"><i class="fa fa-twitter"></i> Tweet</a>
{% endif %}
{% if settings.SOCIAL_AUTH_FACEBOOK_KEY %}
<a href="#" onClick="shareFacebook();" class="btn btn-facebook btn-sm"><i class="fa fa-facebook-official"></i> Share</a>
{% endif %}
{% if settings.SOCIAL_AUTH_LINKEDIN_KEY %}
<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 %}
<hr/>
{% endif %}
{% if can_edit_event %}
<div class="btn-group dropdown">
<button class="btn btn-sm btn-secondary dropdown-toggle" type="button" id="editMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Edit
</button>
<div class="dropdown-menu" aria-labelledby="editMenuButton">
<a href="{% url 'edit-event' event.id %}" class="dropdown-item">Event Details</a>
<a href="{% url 'schedule-event-talks' event.id %}" class="dropdown-item">Manage Talks</a>
</div>
</div>
{% endif %}
<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),