Exemplo n.º 1
0
def place_search(campus_id):
    query = request.args.get('q')
    skip = int(request.args.get('skip', 0))
    limit = int(request.args.get('limit', 20))
    data = []

    if not query:
        places = Place.objects(campus_id=campus_id)
    else:
        places = Place.objects(campus_id=campus_id, names__in=[query])

    places = places.skip(skip).limit(limit)

    for place in places:
        data.append({
            'id': str(place.id),
            'names': place.names,
            'location': {
                'latitude': place.location[0],
                'longitude': place.location[1]
            }
        })

    result = {
        'data': data,
        'paging': {}
    }

    if skip > 0:
        url = list(parse.urlparse(request.url))
        query = dict(parse.parse_qs(url[4]))
        query['skip'] = skip - limit
        query['limit'] = limit
        if query['skip'] < 0:
            query['skip'] = 0
        url[4] = parse.urlencode(query)
        result['paging']['previous'] = parse.urlunparse(url)

    if len(data) >= limit:
        url = list(parse.urlparse(request.url))
        query = dict(parse.parse_qs(url[4]))
        query['skip'] = skip + len(data)
        query['limit'] = limit
        url[4] = parse.urlencode(query)
        result['paging']['next'] = parse.urlunparse(url)

    return jsonify(result)
Exemplo n.º 2
0
def lecture_detail(year, term, code):
    lecture = Lecture.get_lecture(year, term, code)
    from opencampus.module.place.models import Place
    places = Place.objects(campus_id=request.campus.id, names__in=[time_info.place for time_info in lecture.timetable])
    return render_template('module/lecture/detail/information.html', year=year, term=term, code=code,
                           lecture=lecture, places=places)