Add ability to mark yourself as attending an event

This commit is contained in:
Michael Hall 2018-01-23 23:52:42 -05:00
parent b29eaf5457
commit a3a636f5c0
9 changed files with 60 additions and 6 deletions

View file

@ -43,5 +43,6 @@ class EventAdmin(admin.ModelAdmin):
admin.site.register(Event, EventAdmin) admin.site.register(Event, EventAdmin)
admin.site.register(Member) admin.site.register(Member)
admin.site.register(Attendee)

View file

@ -147,5 +147,17 @@ class Attendee(models.Model):
event = models.ForeignKey(Event, on_delete=models.CASCADE) event = models.ForeignKey(Event, on_delete=models.CASCADE)
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE) user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
role = models.SmallIntegerField(_("Role"), choices=ROLES, default=NORMAL, db_index=True) role = models.SmallIntegerField(_("Role"), choices=ROLES, default=NORMAL, db_index=True)
status = models.SmallIntegerField(_("Attending?"), choices=STATUSES, db_index=True) status = models.SmallIntegerField(_("Attending?"), choices=STATUSES, default=YES, db_index=True)
joined_date = models.DateTimeField(default=datetime.datetime.now) joined_date = models.DateTimeField(default=datetime.datetime.now)
@property
def role_name(self):
return Attendee.ROLES[self.role][1]
@property
def status_name(self):
return Attendee.STATUSES[self.status+1][1]
def __str__(self):
return "%s at %s" % (self.user, self.event)

View file

@ -0,0 +1,15 @@
{% if attendee_list %}
<table border="0" width="310px">
{% for attendee in attendee_list %}
<tr>
<td>{{ attendee.user }}</td>
<td>{{ attendee.status_name }}</td>
<td>{% if attendee.role > 0 %}{{ attendee.role_name }}{% endif %}</td>
</tr>
{% endfor %}
</table>
{% else %}
<p>No attendees yet.</p>
{% endif %}

View file

@ -4,9 +4,8 @@
{% for event in events_list %} {% for event in events_list %}
<tr> <tr>
<td><a href="{% url 'show-event' event.id event.slug %}">{{ event.name }}</a></td> <td><a href="{% url 'show-event' event.id event.slug %}">{{ event.name }}</a></td>
<td><a href="{% url 'show-team' event.team.id %}">{{ event.team.name }}</a></td>
<td>{{ event.start_time }}</td>
<td>{{ event.place }}</td> <td>{{ event.place }}</td>
<td>{{ event.start_time }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View file

@ -7,7 +7,7 @@ from rest_framework.decorators import api_view, throttle_classes
from rest_framework.response import Response from rest_framework.response import Response
from .models.search import Searchable, SearchableSerializer from .models.search import Searchable, SearchableSerializer
from .models.events import Event, Place, PlaceSerializer from .models.events import Event, Place, PlaceSerializer, Attendee
from .models.locale import Country ,CountrySerializer, SPR, SPRSerializer, City, CitySerializer from .models.locale import Country ,CountrySerializer, SPR, SPRSerializer, City, CitySerializer
from .models.profiles import Team, UserProfile, Member from .models.profiles import Team, UserProfile, Member
@ -98,3 +98,15 @@ def leave_team(request, team_id):
messages.add_message(request, messages.SUCCESS, message=_('You are no longer on this team.')) messages.add_message(request, messages.SUCCESS, message=_('You are no longer on this team.'))
return redirect('show-team', team_id=team_id) return redirect('show-team', team_id=team_id)
def attend_event(request, event_id):
event = Event.objects.get(id=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!"))
return redirect(event.get_absolute_url())

View file

@ -5,7 +5,17 @@
<h4>Hosted by <a href="{% url "show-team" team.id %}">{{ team.name }}</a></h4> <h4>Hosted by <a href="{% url "show-team" team.id %}">{{ team.name }}</a></h4>
{% include "events/event_details.html" %} {% include "events/event_details.html" %}
<br/>
<h4>Attendees ({{attendee_list.count}})</h4>
{% include "events/attendee_list.html" with attendee_list=attendee_list %}
<br/>
{% if not is_attending %}
<form action="{% url 'attend-event' event.id %}" method="get">
<button type="submit" class="btn btn-success">Attend</button>
</form>
{% endif %}
{% if can_edit_event %} {% if can_edit_event %}
<form action="{% url 'edit-event' event.id %}" method="get"> <form action="{% url 'edit-event' event.id %}" method="get">
<button type="submit" class="btn btn-secondary">Edit Event</button> <button type="submit" class="btn btn-secondary">Edit Event</button>

View file

@ -9,6 +9,8 @@
<h4>Upcoming Events</h4> <h4>Upcoming Events</h4>
{% include "events/event_list.html" %} {% include "events/event_list.html" %}
<br/>
{% if can_create_event %} {% if can_create_event %}
<br /> <br />
<form action="{% url 'create-event' team.id %}" method="get"> <form action="{% url 'create-event' team.id %}" method="get">

View file

@ -40,6 +40,7 @@ urlpatterns = [
path('team/<int:team_id>/+leave/', event_views.leave_team, name='leave-team'), path('team/<int:team_id>/+leave/', event_views.leave_team, name='leave-team'),
path('team/<int:team_id>/+create-event/', views.create_event, name='create-event'), path('team/<int:team_id>/+create-event/', views.create_event, name='create-event'),
path('events/<int:event_id>/+edit/', views.edit_event, name='edit-event'), path('events/<int:event_id>/+edit/', views.edit_event, name='edit-event'),
path('events/<int:event_id>/+attend/', event_views.attend_event, name='attend-event'),
path('events/<int:event_id>/<str:event_slug>/', views.show_event, name='show-event'), path('events/<int:event_id>/<str:event_slug>/', views.show_event, name='show-event'),
path('places/', views.places_list, name='places'), path('places/', views.places_list, name='places'),

View file

@ -7,7 +7,7 @@ from django.http import HttpResponse, JsonResponse
from events.models.profiles import Team, UserProfile, Member from events.models.profiles import Team, UserProfile, Member
from events.forms import TeamForm, NewTeamForm, TeamEventForm, NewTeamEventForm, NewPlaceForm from events.forms import TeamForm, NewTeamForm, TeamEventForm, NewTeamEventForm, NewPlaceForm
from events.models.events import Event, Place from events.models.events import Event, Place, Attendee
import datetime import datetime
import simplejson import simplejson
@ -97,7 +97,7 @@ def teams_list(request, *args, **kwargs):
def show_team(request, team_id, *args, **kwargs): def show_team(request, team_id, *args, **kwargs):
team = Team.objects.get(id=team_id) team = Team.objects.get(id=team_id)
team_events = Event.objects.filter(team=team) team_events = Event.objects.filter(team=team, end_time__gt=datetime.datetime.now()).order_by('start_time')
context = { context = {
'team': team, 'team': team,
'events_list': team_events, 'events_list': team_events,
@ -202,6 +202,8 @@ def show_event(request, event_id, event_slug):
context = { context = {
'team': event.team, 'team': event.team,
'event': event, 'event': event,
'is_attending': request.user.profile in event.attendees.all(),
'attendee_list': Attendee.objects.filter(event=event),
'can_edit_event': request.user.profile.can_edit_event(event), 'can_edit_event': request.user.profile.can_edit_event(event),
} }
return render(request, 'get_together/show_event.html', context) return render(request, 'get_together/show_event.html', context)