diff --git a/events/forms.py b/events/forms.py index 0c132e6..bcd0b8d 100644 --- a/events/forms.py +++ b/events/forms.py @@ -187,9 +187,8 @@ class TeamEventForm(forms.ModelForm): class NewTeamEventForm(forms.ModelForm): class Meta: model = Event - fields = ['name', 'start_time', 'end_time', 'summary', 'place'] + fields = ['name', 'start_time', 'end_time', 'summary'] widgets = { - 'place': Lookup(source='/api/places/', label='name'), 'start_time': DateTimeWidget, 'end_time': DateTimeWidget } diff --git a/events/templates/events/place_list.html b/events/templates/events/place_list.html index c3ab6da..d87b512 100644 --- a/events/templates/events/place_list.html +++ b/events/templates/events/place_list.html @@ -3,7 +3,7 @@ {% for place in places_list %} - + diff --git a/events/views.py b/events/views.py index 54588fa..8b3949e 100644 --- a/events/views.py +++ b/events/views.py @@ -74,6 +74,22 @@ def city_list(request, *args, **kwargs): serializer = CitySerializer(cities, many=True) return Response(serializer.data) +@api_view(['GET']) +def find_city(request): + cities = City.objects.all() + if "city" in request.GET: + cities = cities.filter(name=request.GET.get("city")) + if "spr" in request.GET: + cities = cities.filter(spr__name=request.GET.get("spr")) + if "country" in request.GET: + cities = cities.filter(spr__country__name=request.GET.get("country")) + try: + city = cities[0] + serializer = CitySerializer(city) + return Response(serializer.data) + except: + return Response({}) + def join_team(request, team_id): if request.user.is_anonymous: messages.add_message(request, messages.WARNING, message=_('You must be logged in to join a team.')) diff --git a/get_together/settings.py b/get_together/settings.py index fea1042..f3e8833 100644 --- a/get_together/settings.py +++ b/get_together/settings.py @@ -152,6 +152,7 @@ GOOGLE_ANALYTICS_ID=None SETTINGS_EXPORT = [ 'DEBUG', 'GOOGLE_ANALYTICS_ID', + 'GOOGLE_MAPS_API_KEY', 'SOCIAL_AUTH_GITHUB_KEY', 'SOCIAL_AUTH_GOOGLE_OAUTH2_KEY', ] diff --git a/get_together/templates/get_together/events/create_event.html b/get_together/templates/get_together/events/create_event.html index 7c63813..e5fdf22 100644 --- a/get_together/templates/get_together/events/create_event.html +++ b/get_together/templates/get_together/events/create_event.html @@ -11,7 +11,7 @@
{% include "events/event_form.html" %}
- +
{% endblock %} @@ -19,22 +19,6 @@ {% block javascript %} diff --git a/get_together/templates/get_together/places/show_place.html b/get_together/templates/get_together/places/show_place.html new file mode 100644 index 0000000..9d3a2b4 --- /dev/null +++ b/get_together/templates/get_together/places/show_place.html @@ -0,0 +1,68 @@ +{% extends "get_together/base.html" %} +{% load markup %} + +{% block styles %} + +{% endblock %} + +{% block content %} +
+
+
+

{{ place.name }} + {% if can_edit_place %} + Edit Place + {% endif %} +

+
{{ place.name }}{{ place.name }} {{ place.address|default:'' }} {{ place.city|default:'' }}
+ + + + + + {% if place.place_url %} + + + {% endif %} + +
Address:{{ place.address }}
City:{{ place.city }}
Website:{{ place.place_url }}
+ + + + + +
+
+
+

Events ({{event_list.count}})


+
+ {% for event in event_list %} +
+
+
{{event.name}}
+ {{ event.start_time }} +
+
+ {% endfor %} +
+
+ + +{% endblock %} + diff --git a/get_together/urls.py b/get_together/urls.py index a8288aa..453738e 100644 --- a/get_together/urls.py +++ b/get_together/urls.py @@ -32,6 +32,7 @@ urlpatterns = [ path('api/countries/', event_views.country_list), path('api/spr/', event_views.spr_list), path('api/cities/', event_views.city_list), + path('api/find_city/', event_views.find_city), path('profile/+edit', views.edit_profile, name='edit-profile'), @@ -48,9 +49,11 @@ urlpatterns = [ path('events//+edit/', views.edit_event, name='edit-event'), path('events//+attend/', event_views.attend_event, name='attend-event'), path('events//+delete/', views.delete_event, name='delete-event'), + path('events//+add_place/', views.add_place_to_event, name='add-place'), path('events///', views.show_event, name='show-event'), path('places/', views.places_list, name='places'), + path('places//', views.show_place, name='show-place'), path('+create-place/', views.create_place, name='create-place'), path('oauth/', include('social_django.urls', namespace='social')), diff --git a/get_together/views/events.py b/get_together/views/events.py index 21bbb08..f3534b4 100644 --- a/get_together/views/events.py +++ b/get_together/views/events.py @@ -6,7 +6,7 @@ from django.shortcuts import render, redirect from django.http import HttpResponse, JsonResponse from events.models.profiles import Team, UserProfile, Member -from events.forms import TeamEventForm, NewTeamEventForm, DeleteEventForm +from events.forms import TeamEventForm, NewTeamEventForm, DeleteEventForm, NewPlaceForm from events.models.events import Event, Place, Attendee @@ -52,7 +52,7 @@ def create_event(request, team_id): form.instance.team = team form.instance.created_by = request.user.profile new_event = form.save() - return redirect(new_event.get_absolute_url()) + return redirect('add-place', new_event.id) else: context = { 'team': team, @@ -62,6 +62,36 @@ def create_event(request, team_id): else: return redirect('home') +def add_place_to_event(request, event_id): + event = Event.objects.get(id=event_id) + if not request.user.profile.can_edit_event(event): + messages.add_message(request, messages.WARNING, message=_('You can not make changes to this event.')) + return redirect(event.get_absolute_url()) + + if request.method == 'GET': + form = NewPlaceForm() + + context = { + 'event': event, + 'place_form': form, + } + return render(request, 'get_together/places/create_place.html', context) + elif request.method == 'POST': + form = NewPlaceForm(request.POST) + if form.is_valid: + new_place = form.save() + event.place = new_place + event.save() + return redirect(event.get_absolute_url()) + else: + context = { + 'event': event, + 'place_form': form, + } + return render(request, 'get_together/places/create_place.html', context) + else: + return redirect('home') + def edit_event(request, event_id): event = Event.objects.get(id=event_id) diff --git a/get_together/views/places.py b/get_together/views/places.py index dc4b1bd..4b04d83 100644 --- a/get_together/views/places.py +++ b/get_together/views/places.py @@ -6,7 +6,7 @@ from django.shortcuts import render, redirect 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.forms import NewPlaceForm from events.models.events import Event, Place, Attendee @@ -21,6 +21,15 @@ def places_list(request, *args, **kwargs): } return render(request, 'get_together/places/list_places.html', context) +def show_place(request, place_id): + place = Place.objects.get(id=place_id) + context = { + 'place': place, + 'event_list': Event.objects.filter(place=place).order_by('-start_time'), + } + return render(request, 'get_together/places/show_place.html', context) + + def create_place(request): if request.method == 'GET': form = NewPlaceForm()