Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

Commit

Permalink
PILOT-42 | refactor, fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hoatle committed Sep 1, 2015
1 parent d8a00d1 commit a4d385e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
10 changes: 7 additions & 3 deletions app/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
"""common class for REST API"""

from .auth import token_authenticated, http_authenticated, session_authenticated, authenticated

from .base import (make_empty_response, Resource, TokenRequiredResource,
AdminRoleRequiredResource, jwt_authenticate, jwt_encode_payload,
jwt_decode_token, jwt_load_user, jwt_make_payload)

from .utils import marshal

from .decorators import (anonymous_required, token_auth_required, http_auth_required,
session_auth_required, auth_required, permissions_accepted,
permissions_required, roles_required, roles_accepted, one_of, paginated,
marshal_with, marshal_with_data_envelope, extract_args)
from .base import (make_empty_response, Resource, TokenRequiredResource,
AdminRoleRequiredResource, jwt_authenticate, jwt_encode_payload,
jwt_decode_token, jwt_load_user, jwt_make_payload, marshal)
12 changes: 0 additions & 12 deletions app/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,6 @@ def build_route_name(cls, method_name):
return super(Resource, cls).build_route_name(method_name)


def marshal(data, schema=None, envelope=None):
"""Marshal data with marshmallow"""
if schema:
result = schema.dump(data) # TODO(hoatle): handle error?
data = result.data

if envelope:
return {envelope: data}
else:
return data


class TokenRequiredResource(Resource):
"""The base resource class that requires token authentication"""

Expand Down
2 changes: 1 addition & 1 deletion app/api/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ..pagination import OffsetPagination
from . import (authenticated, token_authenticated, http_authenticated,
session_authenticated)
from .utils import extract_filters
from .utils import extract_filters, marshal


def anonymous_required(func):
Expand Down
12 changes: 12 additions & 0 deletions app/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ def extract_filters(args):
args = extract_dict(args, ignored_keys=filter_dict.keys())

return filters, args


def marshal(data, schema=None, envelope=None):
"""Marshal data with marshmallow"""
if schema:
result = schema.dump(data) # TODO(hoatle): handle error?
data = result.data

if envelope:
return {envelope: data}
else:
return data

0 comments on commit a4d385e

Please sign in to comment.