diff --git a/events/forms.py b/events/forms.py index 618d638..5693395 100644 --- a/events/forms.py +++ b/events/forms.py @@ -2,7 +2,7 @@ from django.utils.safestring import mark_safe from django.forms import ModelForm, Field from django.forms.widgets import TextInput, Select, Media from .models.profiles import Team -from .models.events import Event +from .models.events import Event, Place class LookupMedia(Media): def render(self): @@ -76,4 +76,11 @@ class NewTeamEventForm(ModelForm): 'place': Lookup(source='/api/places/', label='name'), } +class NewPlaceForm(ModelForm): + class Meta: + model = Place + fields = ['name', 'address', 'city', 'longitude', 'latitude', 'place_url', 'tz'] + widgets = { + 'city': Lookup(source='/api/cities/', label='name'), + } diff --git a/events/management/commands/load_cities.py b/events/management/commands/load_cities.py index e9e7740..16cb6df 100644 --- a/events/management/commands/load_cities.py +++ b/events/management/commands/load_cities.py @@ -43,7 +43,7 @@ class Command(BaseCommand): for city_line in cities_file.readlines(): city = city_line.split("\t") if len(city) == 19: - if city[FEATURE_CODE] == "PPL" or city[FEATURE_CODE] == "PPLA": + if city[FEATURE_CODE].startswith("PPL"): country = COUNTRY_CACHE.get(city[COUNTRY_CODE]) spr = SPR_CACHE.get("%s.%s"%(city[COUNTRY_CODE], city[ADMIN1])) if country is not None and spr is not None: diff --git a/events/templates/events/place_form.html b/events/templates/events/place_form.html new file mode 100644 index 0000000..a23a8a7 --- /dev/null +++ b/events/templates/events/place_form.html @@ -0,0 +1,3 @@ + +{{ place_form }} +
diff --git a/events/templates/events/place_list.html b/events/templates/events/place_list.html new file mode 100644 index 0000000..399ac39 --- /dev/null +++ b/events/templates/events/place_list.html @@ -0,0 +1,15 @@ + +{% if places_list %} + + {% for place in places_list %} + + + + + + {% endfor %} +
{{ place.name }}{{ team.address|default:'' }}{{ team.city.name|default:'' }}
+{% else %} +

No places available.

+{% endif %} + diff --git a/get_together/templates/get_together/base.html b/get_together/templates/get_together/base.html index a825d47..58800c2 100644 --- a/get_together/templates/get_together/base.html +++ b/get_together/templates/get_together/base.html @@ -39,7 +39,7 @@ body { Teams diff --git a/get_together/templates/get_together/create_place.html b/get_together/templates/get_together/create_place.html new file mode 100644 index 0000000..6c64518 --- /dev/null +++ b/get_together/templates/get_together/create_place.html @@ -0,0 +1,30 @@ +{% extends "get_together/base.html" %} + +{% block content %} +

Choose your meeting place

+
+{% csrf_token %} +
+{% include "events/place_form.html" %} +
+ +
+
+{% endblock %} + +{% block javascript %} + +{% endblock %} diff --git a/get_together/templates/get_together/places.html b/get_together/templates/get_together/places.html new file mode 100644 index 0000000..2b04104 --- /dev/null +++ b/get_together/templates/get_together/places.html @@ -0,0 +1,13 @@ +{% extends "get_together/base.html" %} + +{% block content %} +{% include "events/place_list.html" %} + +{% if request.user.is_authenticated %} +
+
+ +
+{% endif %} +{% endblock %} + diff --git a/get_together/urls.py b/get_together/urls.py index 06aff2a..c2cde78 100644 --- a/get_together/urls.py +++ b/get_together/urls.py @@ -34,5 +34,8 @@ urlpatterns = [ path('team//create-event/', views.create_event, name='create-event'), path('events///', views.show_event, name='show-event'), + path('places/', views.places_list, name='places'), + path('create-place/', views.create_place, name='create-place'), + path('oauth/', include('social_django.urls', namespace='social')), ] diff --git a/get_together/views.py b/get_together/views.py index 13bd596..231baff 100644 --- a/get_together/views.py +++ b/get_together/views.py @@ -2,9 +2,9 @@ from django.shortcuts import render, redirect from django.http import HttpResponse, JsonResponse from events.models.profiles import Team -from events.forms import TeamForm, NewTeamForm, TeamEventForm, NewTeamEventForm +from events.forms import TeamForm, NewTeamForm, TeamEventForm, NewTeamEventForm, NewPlaceForm -from events.models.events import Event +from events.models.events import Event, Place import datetime import simplejson @@ -95,6 +95,34 @@ def create_event(request, team_id): else: return redirect('home') +def places_list(request, *args, **kwargs): + places = Place.objects.all() + context = { + 'places_list': places, + } + return render(request, 'get_together/places.html', context) + +def create_place(request): + if request.method == 'GET': + form = NewPlaceForm() + + context = { + 'place_form': form, + } + return render(request, 'get_together/create_place.html', context) + elif request.method == 'POST': + form = NewPlaceForm(request.POST) + if form.is_valid: + new_place = form.save() + return redirect('places') + else: + context = { + 'place_form': form, + } + return render(request, 'get_together/create_place.html', context) + else: + return redirect('home') + def show_event(request, event_id, event_slug): event = Event.objects.get(id=event_id) context = {