Commit 6c5b30a7 authored by Stauros Kroustouris's avatar Stauros Kroustouris

all locations api

parent 03d1eb1d
......@@ -4,6 +4,7 @@ from pops.views import api
urlpatterns = patterns(
'',
url(r'^locations/$', api.location, name='location'),
url(r'^locations/(?P<location>[\w|\W]+)/$', api.location, name='location'),
url(r'^(?P<city>[\w|\W]+)/$', api.pops, name='pops'),
url(r'^$', api.pops, name='pops'),
......
......@@ -2,7 +2,7 @@
import json
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from network.models import PeerIfces, PeerSite
from network.models import PeerIfces, PeerSite, Location
from utils import (
get_all_pops,
get_pops_by_city,
......@@ -208,9 +208,21 @@ def pops(request, city=None):
)
def location(request, location):
return HttpResponse(
json.dumps(location_details(location)),
mimetype='application/json',
content_type='application/json; charset=utf-8'
)
def location(request, location=None):
if location:
return HttpResponse(
json.dumps(location_details(location)),
mimetype='application/json',
content_type='application/json; charset=utf-8'
)
else:
result = []
for l in Location.objects.all():
result.append({'id': l.location_id, 'name': l.name})
return HttpResponse(
json.dumps(result),
mimetype='application/json',
content_type='application/json; charset=utf-8'
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment