def catch(r, bmark): q = db.Query(Bmark) q.filter('name =', bmark) bm = q.get() q = db.Query(Stop) q.filter('bmark = ', bm) stops = [] error = None for row in q: stopInfo = nextbus.getTimeURL(row.url) if (stopInfo): stops.append(stopInfo) else: error = "Some stops could not be retreived" links = [ { 'url':'/nb/addstop/%s/_dflt' % (bmark), 'title':'add a stop' }, { 'url':'/catch/%s' % bmark, 'title':'reload'}] params = { 'bmark_name': bm.name, 'bmark_desc': bm.desc, 'stops': stops, 'links': links, 'error': error } return render_with_user('user/catch.html', params)
def home(r): re = nextbus.getDefaultRegion() agency = nextbus.getDefaultAgency() user = users.get_current_user() data = nextbus.getRoutes(agency) prefix = '/nb/catchstop/%s/%s' % (re, agency) instructions = 'pick a route' items = [] if not (data): pass for key, value in data: items.append({'url_piece': key, 'title': value}) t = loader.get_template('listoflinks.html') c = Context({ 'items':items, 'prefix': prefix }) items_t = t.render(c) if (user): q = db.Query(Bmark) q.filter('user = '******'url':'/addbmark', 'title':'add a bookmark' } ] param = { 'bmarks': bmarks, 'links': links, 'list': items_t } return render_with_user('user/home.html', param) else: return render_to_response('splash.html', { 'list': items_t });
def addStop(r, bmark, re=None, agency=None, route=None, direction=None, stop=None): error = '' if (stop is not None): url = nextbus.timeURL % (agency, route, direction, stop) q = db.Query(Bmark) q.filter('name = ', bmark) b = q.get() q = db.Query(Stop) q.filter('bmark = ', b) q.filter('url = ', url) stopObj = q.get() logging.info(stopObj) if (stopObj): logging.info("Stop Already Exists") error = "This stop has already been added" #it'll fall through to picking a stop again else: stopObj = Stop() stopObj.bmark = b stopObj.url = url stopObj.system = "nextbus" stopObj.put() #TODO: redirect to an edit page that doesnt involve the scrape return HttpResponseRedirect('/catch/%s' % (bmark)) if (direction is not None): data = nextbus.getStops(agency, route, direction) prefix = '/nb/addstop/%s/%s/%s/%s/%s'\ % (bmark, re, agency, route, direction) instructions = 'pick a stop' elif (route is not None): data = nextbus.getDirections(agency, route) prefix = '/nb/addstop/%s/%s/%s/%s' % (bmark, re, agency, route) instructions = 'pick a direction' elif (agency is not None): data = nextbus.getRoutes(agency) prefix = '/nb/addstop/%s/%s/%s' % (bmark, re, agency) instructions = 'pick a route' items = [] if not (data): #todo: throw 500 return False for key, value in data: items.append({'url_piece': key, 'title': value}) t = loader.get_template('listoflinks.html') c = Context({ 'items':items, 'prefix': prefix }) items_t = t.render(c) params = { 'prefix': prefix, 'instructions': instructions, 'list': items_t, 'error': error } return render_with_user('user/addstop.html', params)
def addBmark(r): if (r.method) == 'POST': form = AddBmarkForm(r.POST) if (form.is_valid()): bm = Bmark() bm.user = users.get_current_user() bm.name = form.cleaned_data['name'] bm.desc = form.cleaned_data['description'] bm.put() url = getDefaultSource()+'/addstop/'+bm.name+'/_dflt' return HttpResponseRedirect(url) else: form = AddBmarkForm() return render_with_user('user/addbmark.html', {'form':form})
def catchStop(r, re=None, agency=None, route=None, direction=None, stop=None): error = '' if (stop is not None): url = nextbus.timeURL % (agency, route, direction, stop) times = nextbus.getTimeURL(url) params = { 'times': times } return render_with_user('single.html', params) if (direction is not None): data = nextbus.getStops(agency, route, direction) prefix = '/nb/catchstop/%s/%s/%s/%s'\ % (re, agency, route, direction) instructions = 'pick a stop' elif (route is not None): data = nextbus.getDirections(agency, route) prefix = '/nb/catchstop/%s/%s/%s' % (re, agency, route) instructions = 'pick a direction' elif (agency is not None): data = nextbus.getRoutes(agency) prefix = '/nb/catchstop/%s/%s' % (re, agency) instructions = 'pick a route' items = [] if not (data): #todo: throw 500 return False for key, value in data: items.append({'url_piece': key, 'title': value}) t = loader.get_template('listoflinks.html') c = Context({ 'items':items, 'prefix': prefix }) items_t = t.render(c) params = { 'instructions': instructions, 'list':items_t, 'error': error } return render_with_user('user/addstop.html', params)
def deleteBmark(r, bmark, confirm=None): q = db.Query(Bmark) q.filter('name = ', bmark) q.filter('user = '******'/') else: resource = { 'type': 'bookmark', 'desc': bm.desc } params = { 'resource' : resource, 'confirm_url': (r.build_absolute_uri()+'/confirm'), 'cancel_url': '/' } return render_with_user('user/delete.html', params) else: return home(r)