예제 #1
0
def mosaic_detail(request, mosaic_id):

    r = init_redis()
    mosaic_cache = r.get('mosaic:{}'.format(mosaic_id))
    if mosaic_cache:
        return JsonResponse(json.loads(mosaic_cache))

    s3_conn = S3Connection(
        aws_access_key_id=settings.S3_ACCESS_KEY,
        aws_secret_access_key=settings.S3_SECRET_KEY,
        host=settings.S3_HOST,
        port=settings.S3_PORT,
        calling_format=
        'boto.s3.connection.ProtocolIndependentOrdinaryCallingFormat',
        is_secure=settings.S3_HTTPS)

    bucket_small = s3_conn.get_bucket('mosaic-outsmall', validate=False)
    bucket_large = s3_conn.get_bucket('mosaic-outlarge', validate=False)

    try:
        key_small = bucket_small.get_key(mosaic_id)
        key_large = bucket_large.get_key(mosaic_id)
    except boto.exception.S3ResponseError:
        return JsonResponse({'error': 'Could not obtain mosaic'}, status=500)

    url_small = s3_conn.generate_url(1000 * 60 * 60 * 24 * 365,
                                     'GET',
                                     bucket='mosaic-outsmall',
                                     key=mosaic_id)
    url_large = s3_conn.generate_url(1000 * 60 * 60 * 24 * 365,
                                     'GET',
                                     bucket='mosaic-outlarge',
                                     key=mosaic_id)

    username = key_small.get_metadata('username')
    if not username:
        username = '******'

    mosaic = dict()
    mosaic['id'] = mosaic_id
    mosaic['url_small'] = '{}:{}'.format(settings.S3_HTTP_PROTOCOL, url_small)
    mosaic['url_large'] = '{}:{}'.format(settings.S3_HTTP_PROTOCOL, url_large)
    mosaic['username'] = username
    mosaic['date'] = key_large.last_modified

    r.set('mosaic:{}'.format(mosaic_id), json.dumps(mosaic))

    return JsonResponse(mosaic)
예제 #2
0
def mosaic_list(request):

    r = init_redis()
    mosaic_cache = r.get('mosaic:all')
    if mosaic_cache:
        return JsonResponse(json.loads(mosaic_cache))

    s3_conn = S3Connection(aws_access_key_id=settings.S3_ACCESS_KEY,
                           aws_secret_access_key=settings.S3_SECRET_KEY,
                           host=settings.S3_HOST,
                           port=settings.S3_PORT,
                           calling_format='boto.s3.connection.ProtocolIndependentOrdinaryCallingFormat',
                           is_secure=settings.S3_HTTPS)
    try:
        bucket_small = s3_conn.get_bucket('mosaic-outsmall')
        bucket_large = s3_conn.get_bucket('mosaic-outlarge')
    except boto.exception.S3ResponseError, e:
        return JsonResponse({'error': 'Could not connect to object store'}, status=500)
예제 #3
0
파일: views.py 프로젝트: Lujoel/mosaicme
def mosaic_detail(request, mosaic_id):

    r = init_redis()
    mosaic_cache = r.get('mosaic:{}'.format(mosaic_id))
    if mosaic_cache:
        return JsonResponse(json.loads(mosaic_cache))

    s3_conn = S3Connection(aws_access_key_id=settings.S3_ACCESS_KEY,
                           aws_secret_access_key=settings.S3_SECRET_KEY,
                           host=settings.S3_HOST,
                           port=settings.S3_PORT,
                           calling_format='boto.s3.connection.ProtocolIndependentOrdinaryCallingFormat',
                           is_secure=settings.S3_HTTPS)

    bucket_small = s3_conn.get_bucket('mosaic-outsmall', validate=False)
    bucket_large = s3_conn.get_bucket('mosaic-outlarge', validate=False)

    try:
        key_small = bucket_small.get_key(mosaic_id)
        key_large = bucket_large.get_key(mosaic_id)
    except boto.exception.S3ResponseError:
        return JsonResponse({'error': 'Could not obtain mosaic'}, status=500)

    url_small = s3_conn.generate_url(1000*60*60*24*365, 'GET', bucket='mosaic-outsmall', key=mosaic_id)
    url_large = s3_conn.generate_url(1000*60*60*24*365, 'GET', bucket='mosaic-outlarge', key=mosaic_id)

    username = key_small.get_metadata('username')
    if not username:
        username = '******'

    mosaic = dict()
    mosaic['id'] = mosaic_id
    mosaic['url_small'] = '{}:{}'.format(settings.S3_HTTP_PROTOCOL, url_small)
    mosaic['url_large'] = '{}:{}'.format(settings.S3_HTTP_PROTOCOL, url_large)
    mosaic['username'] = username
    mosaic['date'] = key_large.last_modified

    r.set('mosaic:{}'.format(mosaic_id), json.dumps(mosaic))

    return JsonResponse(mosaic)