예제 #1
1
def list(request):
    """
	List changelog
	"""
    kind = None

    limit = 10
    offset = 0

    if request.method == "GET":
        if "limit" in request.GET:
            limit = int(request.GET["limit"])
        if "offset" in request.GET:
            offset = int(request.GET["offset"])
            if offset < 0:
                offset = 0
        if "kind" in request.GET:
            kind = request.GET["kind"]

    if kind is not None:
        gql = db.GqlQuery("SELECT * from gogogo_changelog WHERE model_kind = :1 ORDER BY commit_date DESC ", kind)
    else:
        gql = db.GqlQuery("SELECT * from gogogo_changelog ORDER BY commit_date DESC ")

    query = gql.fetch(limit, offset)

    result = []

    count = 0
    for row in query:
        count += 1
        entity = createEntity(row)
        # entity['id'] = row.key().id_or_name()
        entity["type"] = Changelog.get_type_name(entity["type"])
        entity["entry_name"] = unicode(row.reference)
        result.append(entity)

    prev_offset = offset - limit
    if prev_offset < 0:
        prev_offset = 0

    return render_to_response(
        request,
        "gogogo/db/changelog/list.html",
        {
            "result": result,
            "offset": offset + limit,
            "prev_offset": prev_offset,
            "show_next": count == limit,
            "show_prev": offset != 0,
            "kind": kind,
        },
    )
예제 #2
0
파일: stop.py 프로젝트: gogogo/gogogo-hk
def markerwin(request,id):
	"""
	Generate marker window
	"""
	
	cache_key = "gogogo__stop_markerwin_%s" % id #Prefix of memecache key
	
	cache = memcache.get(cache_key)

	if cache == None:

		stop = getCachedEntityOr404(Stop,key_name=id)

		cache = {}
		cache['stop'] = stop
		
		trip_list = []	
	
		
		if  stop['parent_station'] == None:
			station_key = stop['instance'].key()
		else:
			#station_key = db.Key.from_path(Stop.kind(),stop['parent_station'])
			#logging.info(station_key)
			#parent_station = getCachedEntityOr404(Stop,key = station_key)
			station_key = stop['instance'].parent_station.key()
			cache['parent_station'] = createEntity(stop['instance'].parent_station)
		
		q = Trip.all().filter("stop_list = " , station_key)
		for row in q:
			trip = createEntity(row)
			
			trip['route_id'] = trip['instance'].route.key().id_or_name()
			
			trip['agency_id'] = trip['instance'].route.agency.key().id_or_name()
			trip_list.append(trip)
						
		cache['trip_list'] = trip_list
				
		memcache.add(cache_key, cache, _default_cache_time)
		
	stop = trEntity(cache['stop'],request)
	trip_list = [trEntity(trip,request) for trip in cache['trip_list']   ]
	
	parent_station = None
	if 'parent_station' in cache:
		parent_station = trEntity(cache['parent_station'],request)
		
	t = loader.get_template('gogogo/api/stop-markerwin.html')
	c = Context(
	{
        'stop': stop,
        'parent_station' : parent_station,
        'trip_list' : trip_list
	})
    		
	return HttpResponse(t.render(c))
예제 #3
0
파일: report.py 프로젝트: gogogo/gogogo-hk
def list(request):
	"""
	List report
	"""
	kind = None
	
	limit = 10
	offset = 0

	if request.method == "GET":
		if "limit" in request.GET:
			limit = int(request.GET['limit'])
		if "offset" in request.GET:
			offset = int(request.GET['offset'])
			if offset < 0 :
				offset = 0
		if "kind" in request.GET:
			kind = request.GET['kind']
	
	if kind is not None:
		gql = db.GqlQuery("SELECT * from gogogo_report WHERE model_kind = :1 ORDER BY commit_date DESC ",kind)
	else:
		gql = db.GqlQuery("SELECT * from gogogo_report ORDER BY commit_date DESC ")		

	query = gql.fetch(limit,offset)
		
	result = []

	count = 0
	for row in query :
		count+=1
		entity = createEntity(row)
		entity['id'] = row.key().id()
		result.append(entity)
	
	prev_offset = offset - limit
	if prev_offset < 0 :
		prev_offset = 0
	
	return render_to_response( 
		request,
		'gogogo/db/report/list.html',
			{ "result" : result,
			  "offset" : offset + limit,
			  "prev_offset" : prev_offset,
			  "show_next" : count == limit,
			  "show_prev" : offset != 0,
			  "kind" : kind
		   })			
예제 #4
0
파일: stop.py 프로젝트: gogogo/gogogo-hk
def search(request,lat0,lng0,lat1,lng1):
    """
        Search stop (api/stop/search)
        Deprecated
        
    """
    lat0 = float(lat0)
    lng0 = float(lng0)
    lat1 = float(lat1)
    lng1 = float(lng1)

    sw = LatLng(lat0,lng0)
    ne = LatLng(lat1,lng1)
    bounds = LatLngBounds(sw,ne)
        
    #TODO: Check the distance. Prevent to dump the database that will spend too much bandwidth
    hash0 = str(Geohash( (sw.lng,sw.lat) ))
    hash1 = str(Geohash( (ne.lng,ne.lat) ))

    lang = MLStringProperty.get_current_lang(request)

    cache_key = "gogogo_stop_search_%d_%s_%s" % (lang,hash0,hash1)

    cache = memcache.get(cache_key)

    if cache == None:
        result = []

        query = Stop.all().filter("geohash >=" , hash0).filter("geohash <=" , hash1)
        
        for stop in query:
            pt = latlngFromGeoPt(stop.latlng)
            if bounds.containsLatLng(pt):
                entity = createEntity(stop)
                entity = trEntity(entity,request)
                del entity['instance']
                del entity['geohash']
                result.append(entity)
        
        cache = {}
        cache['result'] = result	
        memcache.add(cache_key, cache, _default_cache_time)

    result = cache['result']

    return ApiResponse(data=result)