def decide(request): you = User(request.user.username, request.user.password) result = API.places_decide(you, request.GET['latitude'], request.GET['longitude']) if not result: logout(request) return HttpResponseResult(reverse('single.decide')) reasons = [] for reason in result['reasons']: if reason.startswith('like:'): reasons.append('You like %s.' % settings.FOOD_STYLES[reason[5:]]) elif reason == 'distance': reasons.append("It's nearby.") elif reason == 'great_rating': reasons.append("It has a great rating of %.1f stars on Yelp." % result['stars']) elif reason == 'good_rating': reasons.append('It has a good rating of %.1f stars on Yelp.' % result['stars']) elif reason == 'notrecent': reasons.append("We haven't suggested this to you in a while.") data = { 'decision': result['business']['name'], 'reasons': reasons, 'latitude': result['business']['location']['coordinate']['latitude'], 'longitude': result['business']['location']['coordinate']['longitude'], 'address': result['business']['location']['display_address'], 'phone': result['business']['display_phone']} return jingo.render(request, 'single/decide.html', data)
def home(request): # create data = {} # You'd add data here that you're sending to the template. you = User(request.user.username, request.user.password) group = API.group_create(you) if not group: logout(request) return HttpResponseRedirect(reverse('group.home')) group_id = group['group_id'] return HttpResponseRedirect(reverse('group.get_info', args=[group_id]))
def home(request): you = User(request.user.username, request.user.password) response = API.verify_token(you) if (not response or "result" not in response or response["result"] != "okay"): logout(request) return HttpResponseRedirect(reverse('single.home')) data = {} # You'd add data here that you're sending to the template. return jingo.render(request, 'single/home.html', data)
def get_questions(request): you = User(request.user.username, request.user.password) response = API.taste_query(you, request.POST['latitude'], request.POST['longitude']) if not response: logout(request) return HttpResponseRedirect(reverse('single.get_questions')) if response['result'] != 'okay': return HttpResponse(json.dumps(response)) clean_names = [settings.FOOD_STYLES[i] for i in response['tastes']] response['tastes_pretty'] = clean_names[:response['to_ask']] return HttpResponse(json.dumps(response))
def authenticate(self, assertion=None, host='munchylunchy.com', port=80): result = API.verify_user(assertion=assertion) logging.error(str(result)) if result['result'] == 'okay': email = result['email'] token = result['token'] try: user = User.objects.get(username=email) user.password = token user.save() except User.DoesNotExist: user = User(username=email, password=token) user.save() return user logging.error("user login failed: %s" % repr(result)) return None
def dashboard(request, group_id): you = User(request.user.username, request.user.password) if 'latitude' in request.GET: latitude = request.GET['latitude'] else: latitude = '0' if 'longitude' in request.GET: longitude = request.GET['longitude'] else: longitude = '0' data = API.group_register(you, group_id, latitude, longitude) if not data or data['registered'] == 'new': return HttpResponseRedirect(reverse('group.get_info', args=[group_id])) elif data['registered'] == 'yes': data['groupid'] = group_id return jingo.render(request, 'group/dashboard.html', data) return HttpResponseBadRequest()
def set_likes(request): you = User(request.user.username, request.user.password) result = API.taste_set(you, request.POST['taste'], request.POST['likes'] == 'yep') return HttpResponse(result)
def async_list(request, group_id): data = {} you = User(request.user.username, request.user.password) restaurants = API.group_poll(you, group_id) return HttpResponse(json.dumps(restaurants))