Add ability to add Places
This commit is contained in:
parent
a803c8d96d
commit
e769c79257
9 changed files with 104 additions and 5 deletions
|
@ -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'),
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
3
events/templates/events/place_form.html
Normal file
3
events/templates/events/place_form.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<table>
|
||||
{{ place_form }}
|
||||
</table>
|
15
events/templates/events/place_list.html
Normal file
15
events/templates/events/place_list.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
|
||||
{% if places_list %}
|
||||
<table border="0" width="960px">
|
||||
{% for place in places_list %}
|
||||
<tr>
|
||||
<td>{{ place.name }}</td>
|
||||
<td>{{ team.address|default:'' }}</td>
|
||||
<td>{{ team.city.name|default:'' }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<p>No places available.</p>
|
||||
{% endif %}
|
||||
|
|
@ -39,7 +39,7 @@ body {
|
|||
<a class="nav-link" href="{% url 'teams' %}">Teams</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link disabled" href="#">Places</a>
|
||||
<a class="nav-link" href="{% url 'places' %}">Places</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
30
get_together/templates/get_together/create_place.html
Normal file
30
get_together/templates/get_together/create_place.html
Normal file
|
@ -0,0 +1,30 @@
|
|||
{% extends "get_together/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Choose your meeting place</h2>
|
||||
<form action="{% url "create-place" %}" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
{% include "events/place_form.html" %}
|
||||
<br />
|
||||
<button type="submit" class="btn btn-primary">Save your Place</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block javascript %}
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$("#city_search").keyup(function() {
|
||||
var searchText = this.value;
|
||||
$.getJSON("/api/cities/?q="+searchText, function(data) {
|
||||
var selectField = $("#city_select");
|
||||
selectField.empty();
|
||||
$.each(data, function(){
|
||||
selectField.append('<option value="'+ this.id +'">'+ this.name+ '</option>')
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
13
get_together/templates/get_together/places.html
Normal file
13
get_together/templates/get_together/places.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
{% extends "get_together/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% include "events/place_list.html" %}
|
||||
|
||||
{% if request.user.is_authenticated %}
|
||||
<br/>
|
||||
<form action="{% url 'create-place' %}" method="get">
|
||||
<button type="submit" class="btn btn-primary">Add your Place</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
@ -34,5 +34,8 @@ urlpatterns = [
|
|||
path('team/<int:team_id>/create-event/', views.create_event, name='create-event'),
|
||||
path('events/<int:event_id>/<str:event_slug>/', 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')),
|
||||
]
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue