Permalink
Browse files

Fixing conflicts mergering with Axte branch

  • Loading branch information...
2 parents e3169be + cb8d7f6 commit 30726428e4bfa47b4b992d0d4e9a77126c31f7d4 @pablorecio committed Dec 17, 2011
Showing with 29 additions and 19 deletions.
  1. +1 −1 fivesquares/foursquareapi/forms.py
  2. +26 −8 fivesquares/foursquareapi/utils.py
  3. +2 −10 fivesquares/foursquareapi/views.py
View
2 fivesquares/foursquareapi/forms.py
@@ -11,7 +11,7 @@
class BasicQueryForm(forms.Form):
position = forms.CharField()
main_categories = forms.MultipleChoiceField(
- choices=[], widget=forms.CheckboxSelectMultiple())
+ choices=[], widget=forms.CheckboxSelectMultiple(), required=False)
def __init__(self, *args, **kwargs):
super(BasicQueryForm, self).__init__(*args, **kwargs)
View
34 fivesquares/foursquareapi/utils.py
@@ -1,9 +1,30 @@
-import urllib2
import json
+import urllib2
+from datetime import datetime
+from urllib import urlencode
+from django.conf import settings
-def get_ordered_venues(url):
- return order_data(get_venues(url))
+
+def get_ordered_venues(ll, categories=None):
+ request_data = {
+ 'll': ll,
+ 'oauth_token': settings.OAUTH_FOURSQUARE,
+ 'v': datetime.now().strftime("%Y%m%d"),
+ }
+ url = '%s/venues/search?%s' % (
+ settings.BASE_FOURSQUARE_URL, urlencode(request_data))
+ venues = []
+ aux = url
+ if(categories != None):
+ for item in categories:
+ url = aux
+ url = url + '&limit=15&categoryId=' + item
+ venues += get_venues(url)
+
+ else:
+ venues += get_venues(url)
+ return sorted(venues, key=lambda venues: venues['distance'])
def get_venues(url):
@@ -15,8 +36,9 @@ def get_venues(url):
for item in data['response']['venues']:
address = 'address' in item['location'] and item['location']['address'] or ''
phone = 'phone' in item['contact'] and item['contact']['phone'] or ''
+ category = len(item['categories']) > 0 and item['categories'][0]['name'] or ''
venue = {'name': item['name'],
- 'category': item['categories'][0]['name'],
+ 'category': category,
'address': address,
'phone': phone,
'distance': item['location']['distance'],
@@ -25,7 +47,3 @@ def get_venues(url):
venues.append(venue)
return venues
-
-
-def order_data(elements):
- return sorted(elements, key=lambda item: item['distance'])
View
12 fivesquares/foursquareapi/views.py
@@ -1,5 +1,4 @@
# Create your views here.
-
from datetime import datetime
from urllib import urlencode
@@ -8,21 +7,14 @@
from django.template import RequestContext
from foursquareapi.forms import BasicQueryForm
-from foursquareapi.utils import get_ordered_data
+from foursquareapi.utils import get_ordered_venues
def home(request):
venues = []
if request.method == 'POST':
form = BasicQueryForm(request.POST)
- request_data = {
- 'oauth_token': settings.OAUTH_FOURSQUARE,
- 'll': form.data['position'],
- 'v': datetime.now().strftime("%Y%m%d"),
- }
- url = '%s/venues/search?%s' % (
- settings.BASE_FOURSQUARE_URL, urlencode(request_data))
- venues = get_ordered_data(url)
+ venues = get_ordered_venues(form.data['position'])
else:
form = BasicQueryForm()

0 comments on commit 3072642

Please sign in to comment.