Add ability to mark yourself as attending an event
This commit is contained in:
parent
b29eaf5457
commit
a3a636f5c0
9 changed files with 60 additions and 6 deletions
|
@ -43,5 +43,6 @@ class EventAdmin(admin.ModelAdmin):
|
|||
admin.site.register(Event, EventAdmin)
|
||||
|
||||
admin.site.register(Member)
|
||||
admin.site.register(Attendee)
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
15
events/templates/events/attendee_list.html
Normal file
15
events/templates/events/attendee_list.html
Normal 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 %}
|
||||
|
|
@ -4,9 +4,8 @@
|
|||
{% for event in events_list %}
|
||||
<tr>
|
||||
<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.start_time }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -5,7 +5,17 @@
|
|||
|
||||
<h4>Hosted by <a href="{% url "show-team" team.id %}">{{ team.name }}</a></h4>
|
||||
{% 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 %}
|
||||
<form action="{% url 'edit-event' event.id %}" method="get">
|
||||
<button type="submit" class="btn btn-secondary">Edit Event</button>
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
<h4>Upcoming Events</h4>
|
||||
{% include "events/event_list.html" %}
|
||||
<br/>
|
||||
|
||||
{% if can_create_event %}
|
||||
<br />
|
||||
<form action="{% url 'create-event' team.id %}" method="get">
|
||||
|
|
|
@ -40,6 +40,7 @@ urlpatterns = [
|
|||
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('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('places/', views.places_list, name='places'),
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue