def containerview(request):
    """ Returns a list of all containers in current account. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    if not storage_url or not auth_token:
        return redirect(login)

    try:
        account_stat, containers = client.get_account(storage_url, auth_token)
    except client.ClientException as exc:
        traceback.print_exc()
        if exc.http_status == 403:
            account_stat = {}
            containers = []
            base_url = get_base_url(request)
            msg = 'Container listing failed. You can manually choose a known '
            msg += 'container by appending the name to the URL, for example: '
            msg += '<a href="%s/objects/containername">' % base_url
            msg += '%s/objects/containername</a>' % base_url
            messages.add_message(request, messages.ERROR, msg)
        else:
            return redirect(login)

    account_stat = replace_hyphens(account_stat)

    return render_to_response('containerview.html', {
        'account_stat': account_stat,
        'containers': containers,
        'session': request.session,
    }, context_instance=RequestContext(request))
def containerview(request):
    """ Returns a list of all containers in current account. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    try:
        account_stat, containers = client.get_account(storage_url, auth_token)
    except client.ClientException as exc:
        if exc.http_status == 403:
            account_stat = {}
            containers = []
            base_url = get_base_url(request)
            msg = 'Container listing failed. You can manually choose a known '
            msg += 'container by appending the name to the URL, for example: '
            msg += '<a href="%s/objects/containername">' % base_url
            msg += '%s/objects/containername</a>' % base_url
            messages.add_message(request, messages.ERROR, msg)
        else:
            return redirect(login)

    account_stat = replace_hyphens(account_stat)

    return render(
        request, 'containerview.html', {
            'account_stat': account_stat,
            'containers': containers,
            'session': request.session
        })
Exemple #3
0
    def test_replace_hyphens(self):
        fake_dict = {
            'content-length': '147',
            'content-type': 'application/json'
        }
        expected = {
            'content_length': '147',
            'content_type': 'application/json'
        }
        modified = utils.replace_hyphens(fake_dict)

        self.assertEqual(modified, expected)
Exemple #4
0
def containerview(request):
    """ Returns a list of all containers in current account. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    try:
        account_stat, containers = client.get_account(storage_url, auth_token)
    except client.ClientException:
        return redirect(login)

    account_stat = replace_hyphens(account_stat)

    return render_to_response('containerview.html', {
        'account_stat': account_stat,
        'containers': containers,
        'session': request.session,
    }, context_instance=RequestContext(request))
Exemple #5
0
def containerview(request):
    """ Returns a list of all containers in current account. """

    storage_url = request.session.get('storage_url', '')
    auth_token = request.session.get('auth_token', '')

    try:
        account_stat, containers = client.get_account(storage_url, auth_token)
    except client.ClientException:
        return redirect(login)

    account_stat = replace_hyphens(account_stat)

    return render_to_response('containerview.html', {
        'account_stat': account_stat,
        'containers': containers,
        'session': request.session,
    }, context_instance=RequestContext(request))
Exemple #6
0
def containerview(request):
    """ Returns a list of all containers in current account. """

    storage_url = request.session.get('storage_url', settings.STORAGE_URL)
    auth_token = request.session.get('auth_token', 'demo')
    request.session['cloud'] = getcloud(request)
    request.session['showimagemap'] = settings.SHOW_IMAGEMAP

    try:
        account_stat, containers = client.get_account(storage_url, auth_token)
    except client.ClientException as exc:
        account_stat = {}
        containers = []
        if exc.http_status == 403:
            base_url = get_base_url(request)
            msg = 'Container listing failed. You can manually choose a known '
            msg += 'container by appending the name to the URL, for example: '
            msg += '<a href="%s/objects/containername">' % base_url
            msg += '%s/objects/containername</a>' % base_url
            messages.add_message(request, messages.ERROR, msg)
        elif exc.http_status == 302:
            msg = 'Bucket listing failed with 302. \n '
            msg += exc.msg
            messages.add_message(request, messages.ERROR, msg)
        else:
            msg = 'Bucket listing failed with %s. ' % exc.http_status
            msg += 'A 503 error could mean volume is not set.\n '
            msg += exc.msg
            messages.add_message(request, messages.ERROR, msg)
            return redirect(login)

    account_stat = replace_hyphens(account_stat)

    return render_to_response('containerview.html', {
        'account_stat': account_stat,
        'containers': containers,
        'session': request.session,
    }, context_instance=RequestContext(request))