diff --git a/events/admin.py b/events/admin.py index 4aa87f2..40de86d 100644 --- a/events/admin.py +++ b/events/admin.py @@ -43,5 +43,6 @@ class EventAdmin(admin.ModelAdmin): admin.site.register(Event, EventAdmin) admin.site.register(Member) +admin.site.register(Attendee) diff --git a/events/models/events.py b/events/models/events.py index cc33d23..584bfb4 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -147,5 +147,17 @@ class Attendee(models.Model): event = models.ForeignKey(Event, on_delete=models.CASCADE) user = models.ForeignKey(UserProfile, on_delete=models.CASCADE) 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) + + @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) + diff --git a/events/templates/events/attendee_list.html b/events/templates/events/attendee_list.html new file mode 100644 index 0000000..aaf09f6 --- /dev/null +++ b/events/templates/events/attendee_list.html @@ -0,0 +1,15 @@ + +{% if attendee_list %} + + {% for attendee in attendee_list %} + + + + + + {% endfor %} +
{{ attendee.user }}{{ attendee.status_name }}{% if attendee.role > 0 %}{{ attendee.role_name }}{% endif %}
+{% else %} +

No attendees yet.

+{% endif %} + diff --git a/events/templates/events/event_list.html b/events/templates/events/event_list.html index 55df1aa..5418df1 100644 --- a/events/templates/events/event_list.html +++ b/events/templates/events/event_list.html @@ -4,9 +4,8 @@ {% for event in events_list %} {{ event.name }} - {{ event.team.name }} - {{ event.start_time }} {{ event.place }} + {{ event.start_time }} {% endfor %} diff --git a/events/views.py b/events/views.py index 1eb83a0..6491d10 100644 --- a/events/views.py +++ b/events/views.py @@ -7,7 +7,7 @@ from rest_framework.decorators import api_view, throttle_classes from rest_framework.response import Response 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.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.')) 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()) + diff --git a/get_together/templates/get_together/show_event.html b/get_together/templates/get_together/show_event.html index bf4c7d4..26b97f4 100644 --- a/get_together/templates/get_together/show_event.html +++ b/get_together/templates/get_together/show_event.html @@ -5,7 +5,17 @@

Hosted by {{ team.name }}

{% include "events/event_details.html" %} +
+

Attendees ({{attendee_list.count}})

+{% include "events/attendee_list.html" with attendee_list=attendee_list %} +
+ +{% if not is_attending %} +
+ +
+{% endif %} {% if can_edit_event %}
diff --git a/get_together/templates/get_together/show_team.html b/get_together/templates/get_together/show_team.html index 502357f..30bd2e1 100644 --- a/get_together/templates/get_together/show_team.html +++ b/get_together/templates/get_together/show_team.html @@ -9,6 +9,8 @@

Upcoming Events

{% include "events/event_list.html" %} +
+ {% if can_create_event %}
diff --git a/get_together/urls.py b/get_together/urls.py index 71a5444..bf86a28 100644 --- a/get_together/urls.py +++ b/get_together/urls.py @@ -40,6 +40,7 @@ urlpatterns = [ path('team//+leave/', event_views.leave_team, name='leave-team'), path('team//+create-event/', views.create_event, name='create-event'), path('events//+edit/', views.edit_event, name='edit-event'), + path('events//+attend/', event_views.attend_event, name='attend-event'), path('events///', views.show_event, name='show-event'), path('places/', views.places_list, name='places'), diff --git a/get_together/views.py b/get_together/views.py index d91a421..07034c2 100644 --- a/get_together/views.py +++ b/get_together/views.py @@ -7,7 +7,7 @@ from django.http import HttpResponse, JsonResponse from events.models.profiles import Team, UserProfile, Member 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 simplejson @@ -97,7 +97,7 @@ def teams_list(request, *args, **kwargs): def show_team(request, team_id, *args, **kwargs): 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 = { 'team': team, 'events_list': team_events, @@ -202,6 +202,8 @@ def show_event(request, event_id, event_slug): context = { 'team': event.team, '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), } return render(request, 'get_together/show_event.html', context)