예제 #1
0
def get_bundle(request):
    if 'locale' not in request.GET or 'product' not in request.GET:
        return HttpResponseBadRequest(BAD_REQUEST, mimetype='application/json')

    locale = request.GET['locale']
    product = request.GET['product']
    if locale.lower() not in settings.LANGUAGES_DICT:
        return HttpResponseNotFound(INVALID_LOCALE,
                                    mimetype='application/json')

    name = redis_bundle_name(locale, product)
    try:
        redis = redis_client('default')
    except RedisError:
        return HttpResponse('not available yet', status=503)
    else:
        bundle = redis.hget(name, 'bundle')
        bundle_hash = redis.hget(name, 'hash')

    if bundle is None:
        return HttpResponseNotFound(NOT_FOUND, mimetype='application/json')

    response = HttpResponse(bundle, mimetype='application/json')
    response['Content-Length'] = len(bundle)
    response['X-Content-Hash'] = bundle_hash
    response['Access-Control-Expose-Headers'] = \
        'Content-Length, X-Content-Hash'

    return response
예제 #2
0
def bundle_meta(request):
    """This view is responsible for update checking."""
    if 'locale' not in request.GET or 'product' not in request.GET:
        return HttpResponseBadRequest(BAD_REQUEST, mimetype='application/json')

    locale = request.GET['locale']
    product = request.GET['product']

    name = redis_bundle_name(locale, product)
    try:
        redis = redis_client('default')
    except RedisError:
        return HttpResponse('{"error": "no bundles available"}',
                            mimetype='application/json',
                            status=503)

    bundle_hash = redis.hget(name, 'hash')

    if bundle_hash:
        u = {'hash': bundle_hash}
        return HttpResponse(json.dumps(u), mimetype='application/json')
    else:
        return HttpResponseNotFound(NOT_FOUND, mimetype='application/json')