Commit 51f608ed authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

snf_django: Optionally use other default serialization than json

Pithos api default serialization for listing is text insted of json.
However the common api decorator if not specified otherwise used to
json as the default serialization.
So we introduced a new optional argument (defaults to json) to override
the default serialization for the api method.

Conflicts:
	snf-pithos-app/pithos/api/util.py
parent 86d2505e
......@@ -61,7 +61,8 @@ def get_token(request):
def api_method(http_method=None, token_required=True, user_required=True,
logger=None, format_allowed=True, astakos_url=None):
logger=None, format_allowed=True, astakos_url=None,
default_serialization="json"):
"""Decorator function for views that implement an API method."""
if not logger:
logger = log
......@@ -71,8 +72,8 @@ def api_method(http_method=None, token_required=True, user_required=True,
def wrapper(request, *args, **kwargs):
try:
# Get the requested serialization format
request.serialization = get_serialization(request,
format_allowed)
request.serialization = get_serialization(
request, format_allowed, default_serialization)
# Check HTTP method
if http_method and request.method != http_method:
......@@ -123,7 +124,7 @@ def api_method(http_method=None, token_required=True, user_required=True,
return decorator
def get_serialization(request, format_allowed=True):
def get_serialization(request, format_allowed=True, default_serialization="json"):
"""Return the serialization format requested.
Valid formats are 'json' and 'xml' and 'text'
......@@ -154,7 +155,7 @@ def get_serialization(request, format_allowed=True):
elif accept == "application/xml":
return "xml"
return "json"
return default_serialization
def update_response_headers(request, response):
......
......@@ -341,7 +341,8 @@ def account_update(request, v_account):
return HttpResponse(status=202)
@api_method('GET', format_allowed=True, user_required=True, logger=logger)
@api_method('GET', format_allowed=True, user_required=True, logger=logger,
default_serialization="text")
def container_list(request, v_account):
# Normal Response Codes: 200, 204
# Error Response Codes: internalServerError (500),
......@@ -587,7 +588,8 @@ def container_delete(request, v_account, v_container):
return HttpResponse(status=204)
@api_method('GET', format_allowed=True, user_required=True, logger=logger)
@api_method('GET', format_allowed=True, user_required=True, logger=logger,
default_serialization="text")
def object_list(request, v_account, v_container):
# Normal Response Codes: 200, 204
# Error Response Codes: internalServerError (500),
......
......@@ -1055,11 +1055,12 @@ def get_pithos_usage(token):
def api_method(http_method=None, user_required=True, logger=None,
format_allowed=False):
format_allowed=False, default_serialization="json"):
def decorator(func):
@api.api_method(http_method=http_method, user_required=user_required,
logger=logger, format_allowed=format_allowed,
astakos_url=ASTAKOS_BASE_URL)
astakos_url=ASTAKOS_BASE_URL,
default_serialization=default_serialization)
@wraps(func)
def wrapper(request, *args, **kwargs):
# The args variable may contain up to (account, container, object).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment