Exemple #1
0
def SearchView(request):

    chain = SearchFilterChain(request)

    search_args = {}

    for key in request.GET:
        if not chain.filters_key(key):
            search_args[key] = request.GET.getlist(key)

    search_args = chain.filter_args(search_args)

    json = Spot(None, request=request).search(search_args)
    json = simplejson.dumps(json)

    return HttpResponse(json, content_type='application/json')
Exemple #2
0
def SearchView(request):

    # Required settings for the client

    if not hasattr(settings, 'SS_WEB_SERVER_HOST'):
        raise(Exception("Required setting missing: SS_WEB_SERVER_HOST"))
    if not hasattr(settings, 'SS_WEB_OAUTH_KEY'):
        raise(Exception("Required setting missing: SS_WEB_OAUTH_KEY"))
    if not hasattr(settings, 'SS_WEB_OAUTH_SECRET'):
        raise(Exception("Required setting missing: SS_WEB_OAUTH_SECRET"))

    chain = SearchFilterChain(request)

    consumer = oauth2.Consumer(
                            key=settings.SS_WEB_OAUTH_KEY,
                            secret=settings.SS_WEB_OAUTH_SECRET
                            )
    client = oauth2.Client(consumer)

    search_args = {}

    for key in request.GET:
        if not chain.filters_key(key):
            search_args[key] = request.GET.getlist(key)

    search_args = chain.filter_args(search_args)

    json = get_space_search_json(client, search_args)
    json = simplejson.loads(json)
    i18n_json = []
    for space in json:
        string_val = ''
        for x in range(0, len(space['type'])):
            if x is 0:
                string_val = _(space['type'][x])
            else:
                string_val = string_val + ', ' + _(space['type'][x])
        space['type'] = string_val
        i18n_json.append(space)
    json = simplejson.dumps(i18n_json)
    response = HttpResponse(json)

    response["Content-type"] = "application/json"

    return response
Exemple #3
0
def SearchView(request):

    # Required settings for the client

    if not hasattr(settings, 'SS_WEB_SERVER_HOST'):
        raise(Exception("Required setting missing: SS_WEB_SERVER_HOST"))
    if not hasattr(settings, 'SS_WEB_OAUTH_KEY'):
        raise(Exception("Required setting missing: SS_WEB_OAUTH_KEY"))
    if not hasattr(settings, 'SS_WEB_OAUTH_SECRET'):
        raise(Exception("Required setting missing: SS_WEB_OAUTH_SECRET"))

    chain = SearchFilterChain(request)

    consumer = oauth2.Consumer(key=settings.SS_WEB_OAUTH_KEY, secret=settings.SS_WEB_OAUTH_SECRET)
    client = oauth2.Client(consumer)

    search_args = {}

    for key in request.GET:
        if not chain.filters_key(key):
            search_args[key] = request.GET.getlist(key)

    search_args = chain.filter_args(search_args)

    json = get_space_search_json(client, search_args)
    json = simplejson.loads(json)
    i18n_json = []
    for space in json:
        string_val = ''
        for x in range(0, len(space['type'])):
            if x is 0:
                string_val = _(space['type'][x])
            else:
                string_val = string_val + ', ' + _(space['type'][x])
        space['type'] = string_val
        i18n_json.append(space)
    json = simplejson.dumps(i18n_json)
    response = HttpResponse(json)

    response["Content-type"] = "application/json"

    return response
Exemple #4
0
def fetch_open_now_for_campus(
                            request, campus, use_cache=True,
                            fill_cache=False, cache_period=FIVE_MINUTE_CACHE):
    if campus is None:
        # Default to zooming in on the UW Seattle campus
        center_latitude = '47.655003'
        center_longitude = '-122.306864'
        zoom_level = '15'
        distance = '500'

    else:
        location = settings.SS_LOCATIONS[campus]
        center_latitude = location['CENTER_LATITUDE']
        center_longitude = location['CENTER_LONGITUDE']
        zoom_level = location['ZOOM_LEVEL']

        if 'DISTANCE' in location:
            distance = location['DISTANCE']
        else:
            distance = '500'

    # SPOT-1832. Making the distance far enough that center of campus to
    # furthest spot from the center can be found
    distance = 1000
    consumer = oauth2.Consumer(
                            key=settings.SS_WEB_OAUTH_KEY,
                            secret=settings.SS_WEB_OAUTH_SECRET)
    client = oauth2.Client(consumer)

    chain = SearchFilterChain(request)
    search_url_args = []
    search_url_args = chain.url_args(request)
    search_url_args.append({'center_latitude': center_latitude})
    search_url_args.append({'center_longitude': center_longitude})
    search_url_args.append({'open_now': '1'})
    search_url_args.append({'distance': distance})
    search_url_args.append({'limit': '0'})

    return get_space_json(
                        client, search_url_args, use_cache,
                        fill_cache, cache_period)