mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-11 04:07:39 +03:00
pep8/pyflakes cleanup
This commit is contained in:
parent
a851294d05
commit
dea4a45ec7
|
@ -9,7 +9,6 @@ The set of authentication methods which are used is then specified by setting th
|
||||||
|
|
||||||
from django.contrib.auth import authenticate
|
from django.contrib.auth import authenticate
|
||||||
from djangorestframework.compat import CsrfViewMiddleware
|
from djangorestframework.compat import CsrfViewMiddleware
|
||||||
from djangorestframework.utils import as_tuple
|
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
|
|
@ -68,7 +68,6 @@ class RequestMixin(object):
|
||||||
self._load_method_and_content_type()
|
self._load_method_and_content_type()
|
||||||
return self._method
|
return self._method
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def content_type(self):
|
def content_type(self):
|
||||||
"""
|
"""
|
||||||
|
@ -82,7 +81,6 @@ class RequestMixin(object):
|
||||||
self._load_method_and_content_type()
|
self._load_method_and_content_type()
|
||||||
return self._content_type
|
return self._content_type
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def DATA(self):
|
def DATA(self):
|
||||||
"""
|
"""
|
||||||
|
@ -95,7 +93,6 @@ class RequestMixin(object):
|
||||||
self._load_data_and_files()
|
self._load_data_and_files()
|
||||||
return self._data
|
return self._data
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def FILES(self):
|
def FILES(self):
|
||||||
"""
|
"""
|
||||||
|
@ -107,7 +104,6 @@ class RequestMixin(object):
|
||||||
self._load_data_and_files()
|
self._load_data_and_files()
|
||||||
return self._files
|
return self._files
|
||||||
|
|
||||||
|
|
||||||
def _load_data_and_files(self):
|
def _load_data_and_files(self):
|
||||||
"""
|
"""
|
||||||
Parse the request content into self.DATA and self.FILES.
|
Parse the request content into self.DATA and self.FILES.
|
||||||
|
@ -118,7 +114,6 @@ class RequestMixin(object):
|
||||||
if not hasattr(self, '_data'):
|
if not hasattr(self, '_data'):
|
||||||
(self._data, self._files) = self._parse(self._get_stream(), self._content_type)
|
(self._data, self._files) = self._parse(self._get_stream(), self._content_type)
|
||||||
|
|
||||||
|
|
||||||
def _load_method_and_content_type(self):
|
def _load_method_and_content_type(self):
|
||||||
"""
|
"""
|
||||||
Set the method and content_type, and then check if they've been overridden.
|
Set the method and content_type, and then check if they've been overridden.
|
||||||
|
@ -127,7 +122,6 @@ class RequestMixin(object):
|
||||||
self._content_type = self.request.META.get('HTTP_CONTENT_TYPE', self.request.META.get('CONTENT_TYPE', ''))
|
self._content_type = self.request.META.get('HTTP_CONTENT_TYPE', self.request.META.get('CONTENT_TYPE', ''))
|
||||||
self._perform_form_overloading()
|
self._perform_form_overloading()
|
||||||
|
|
||||||
|
|
||||||
def _get_stream(self):
|
def _get_stream(self):
|
||||||
"""
|
"""
|
||||||
Returns an object that may be used to stream the request content.
|
Returns an object that may be used to stream the request content.
|
||||||
|
@ -147,7 +141,6 @@ class RequestMixin(object):
|
||||||
return request
|
return request
|
||||||
return StringIO(request.raw_post_data)
|
return StringIO(request.raw_post_data)
|
||||||
|
|
||||||
|
|
||||||
def _perform_form_overloading(self):
|
def _perform_form_overloading(self):
|
||||||
"""
|
"""
|
||||||
If this is a form POST request, then we need to check if the method and content/content_type have been
|
If this is a form POST request, then we need to check if the method and content/content_type have been
|
||||||
|
@ -173,7 +166,6 @@ class RequestMixin(object):
|
||||||
stream = StringIO(self._data.pop(self._CONTENT_PARAM)[0])
|
stream = StringIO(self._data.pop(self._CONTENT_PARAM)[0])
|
||||||
(self._data, self._files) = self._parse(stream, self._content_type)
|
(self._data, self._files) = self._parse(stream, self._content_type)
|
||||||
|
|
||||||
|
|
||||||
def _parse(self, stream, content_type):
|
def _parse(self, stream, content_type):
|
||||||
"""
|
"""
|
||||||
Parse the request content.
|
Parse the request content.
|
||||||
|
@ -194,7 +186,6 @@ class RequestMixin(object):
|
||||||
{'error': 'Unsupported media type in request \'%s\'.' %
|
{'error': 'Unsupported media type in request \'%s\'.' %
|
||||||
content_type})
|
content_type})
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _parsed_media_types(self):
|
def _parsed_media_types(self):
|
||||||
"""
|
"""
|
||||||
|
@ -202,7 +193,6 @@ class RequestMixin(object):
|
||||||
"""
|
"""
|
||||||
return [parser.media_type for parser in self.parsers]
|
return [parser.media_type for parser in self.parsers]
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _default_parser(self):
|
def _default_parser(self):
|
||||||
"""
|
"""
|
||||||
|
@ -211,7 +201,6 @@ class RequestMixin(object):
|
||||||
return self.parsers[0]
|
return self.parsers[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
########## ResponseMixin ##########
|
########## ResponseMixin ##########
|
||||||
|
|
||||||
class ResponseMixin(object):
|
class ResponseMixin(object):
|
||||||
|
@ -233,7 +222,6 @@ class ResponseMixin(object):
|
||||||
Should be a tuple/list of classes as described in the :mod:`renderers` module.
|
Should be a tuple/list of classes as described in the :mod:`renderers` module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# TODO: wrap this behavior around dispatch(), ensuring it works
|
# TODO: wrap this behavior around dispatch(), ensuring it works
|
||||||
# out of the box with existing Django classes that use render_to_response.
|
# out of the box with existing Django classes that use render_to_response.
|
||||||
def render(self, response):
|
def render(self, response):
|
||||||
|
@ -266,7 +254,6 @@ class ResponseMixin(object):
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
def _determine_renderer(self, request):
|
def _determine_renderer(self, request):
|
||||||
"""
|
"""
|
||||||
Determines the appropriate renderer for the output, given the client's 'Accept' header,
|
Determines the appropriate renderer for the output, given the client's 'Accept' header,
|
||||||
|
@ -309,7 +296,6 @@ class ResponseMixin(object):
|
||||||
{'detail': 'Could not satisfy the client\'s Accept header',
|
{'detail': 'Could not satisfy the client\'s Accept header',
|
||||||
'available_types': self._rendered_media_types})
|
'available_types': self._rendered_media_types})
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _rendered_media_types(self):
|
def _rendered_media_types(self):
|
||||||
"""
|
"""
|
||||||
|
@ -353,7 +339,6 @@ class AuthMixin(object):
|
||||||
Should be a tuple/list of classes as described in the :mod:`permissions` module.
|
Should be a tuple/list of classes as described in the :mod:`permissions` module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user(self):
|
def user(self):
|
||||||
"""
|
"""
|
||||||
|
@ -364,7 +349,6 @@ class AuthMixin(object):
|
||||||
self._user = self._authenticate()
|
self._user = self._authenticate()
|
||||||
return self._user
|
return self._user
|
||||||
|
|
||||||
|
|
||||||
def _authenticate(self):
|
def _authenticate(self):
|
||||||
"""
|
"""
|
||||||
Attempt to authenticate the request using each authentication class in turn.
|
Attempt to authenticate the request using each authentication class in turn.
|
||||||
|
@ -377,7 +361,6 @@ class AuthMixin(object):
|
||||||
return user
|
return user
|
||||||
return AnonymousUser()
|
return AnonymousUser()
|
||||||
|
|
||||||
|
|
||||||
# TODO: wrap this behavior around dispatch()
|
# TODO: wrap this behavior around dispatch()
|
||||||
def _check_permissions(self):
|
def _check_permissions(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -115,6 +115,7 @@ if yaml:
|
||||||
else:
|
else:
|
||||||
YAMLParser = None
|
YAMLParser = None
|
||||||
|
|
||||||
|
|
||||||
class PlainTextParser(BaseParser):
|
class PlainTextParser(BaseParser):
|
||||||
"""
|
"""
|
||||||
Plain text parser.
|
Plain text parser.
|
||||||
|
@ -240,7 +241,8 @@ class XMLParser(BaseParser):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_PARSERS = ( JSONParser,
|
DEFAULT_PARSERS = (
|
||||||
|
JSONParser,
|
||||||
FormParser,
|
FormParser,
|
||||||
MultiPartParser,
|
MultiPartParser,
|
||||||
XMLParser
|
XMLParser
|
||||||
|
|
|
@ -226,7 +226,6 @@ class DocumentingTemplateRenderer(BaseRenderer):
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
def _get_form_instance(self, view, method):
|
def _get_form_instance(self, view, method):
|
||||||
"""
|
"""
|
||||||
Get a form, possibly bound to either the input or output data.
|
Get a form, possibly bound to either the input or output data.
|
||||||
|
@ -262,7 +261,6 @@ class DocumentingTemplateRenderer(BaseRenderer):
|
||||||
|
|
||||||
return form_instance
|
return form_instance
|
||||||
|
|
||||||
|
|
||||||
def _get_generic_content_form(self, view):
|
def _get_generic_content_form(self, view):
|
||||||
"""
|
"""
|
||||||
Returns a form that allows for arbitrary content types to be tunneled via standard HTML forms
|
Returns a form that allows for arbitrary content types to be tunneled via standard HTML forms
|
||||||
|
@ -298,7 +296,6 @@ class DocumentingTemplateRenderer(BaseRenderer):
|
||||||
# Okey doke, let's do it
|
# Okey doke, let's do it
|
||||||
return GenericContentForm(view)
|
return GenericContentForm(view)
|
||||||
|
|
||||||
|
|
||||||
def render(self, obj=None, media_type=None):
|
def render(self, obj=None, media_type=None):
|
||||||
"""
|
"""
|
||||||
Renders *obj* using the :attr:`template` set on the class.
|
Renders *obj* using the :attr:`template` set on the class.
|
||||||
|
@ -398,12 +395,14 @@ class DocumentingPlainTextRenderer(DocumentingTemplateRenderer):
|
||||||
template = 'renderer.txt'
|
template = 'renderer.txt'
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_RENDERERS = ( JSONRenderer,
|
DEFAULT_RENDERERS = (
|
||||||
|
JSONRenderer,
|
||||||
JSONPRenderer,
|
JSONPRenderer,
|
||||||
DocumentingHTMLRenderer,
|
DocumentingHTMLRenderer,
|
||||||
DocumentingXHTMLRenderer,
|
DocumentingXHTMLRenderer,
|
||||||
DocumentingPlainTextRenderer,
|
DocumentingPlainTextRenderer,
|
||||||
XMLRenderer )
|
XMLRenderer
|
||||||
|
)
|
||||||
|
|
||||||
if YAMLRenderer:
|
if YAMLRenderer:
|
||||||
DEFAULT_RENDERERS += (YAMLRenderer,)
|
DEFAULT_RENDERERS += (YAMLRenderer,)
|
||||||
|
|
|
@ -1,20 +1,11 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.urlresolvers import reverse, get_urlconf, get_resolver, NoReverseMatch
|
from django.core.urlresolvers import reverse, get_urlconf, get_resolver, NoReverseMatch
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.query import QuerySet
|
|
||||||
from django.db.models.fields.related import RelatedField
|
|
||||||
from django.utils.encoding import smart_unicode
|
|
||||||
|
|
||||||
from djangorestframework.response import ErrorResponse
|
from djangorestframework.response import ErrorResponse
|
||||||
from djangorestframework.serializer import Serializer, _SkipField
|
from djangorestframework.serializer import Serializer, _SkipField
|
||||||
from djangorestframework.utils import as_tuple
|
from djangorestframework.utils import as_tuple
|
||||||
|
|
||||||
import decimal
|
|
||||||
import inspect
|
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseResource(Serializer):
|
class BaseResource(Serializer):
|
||||||
"""
|
"""
|
||||||
|
@ -86,7 +77,6 @@ class FormResource(Resource):
|
||||||
expected fields are validated.
|
expected fields are validated.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def validate_request(self, data, files=None):
|
def validate_request(self, data, files=None):
|
||||||
"""
|
"""
|
||||||
Given some content as input return some cleaned, validated content.
|
Given some content as input return some cleaned, validated content.
|
||||||
|
@ -101,7 +91,6 @@ class FormResource(Resource):
|
||||||
"""
|
"""
|
||||||
return self._validate(data, files)
|
return self._validate(data, files)
|
||||||
|
|
||||||
|
|
||||||
def _validate(self, data, files, allowed_extra_fields=(), fake_data=None):
|
def _validate(self, data, files, allowed_extra_fields=(), fake_data=None):
|
||||||
"""
|
"""
|
||||||
Wrapped by validate to hide the extra flags that are used in the implementation.
|
Wrapped by validate to hide the extra flags that are used in the implementation.
|
||||||
|
@ -187,7 +176,6 @@ class FormResource(Resource):
|
||||||
# Return HTTP 400 response (BAD REQUEST)
|
# Return HTTP 400 response (BAD REQUEST)
|
||||||
raise ErrorResponse(400, detail)
|
raise ErrorResponse(400, detail)
|
||||||
|
|
||||||
|
|
||||||
def get_form_class(self, method=None):
|
def get_form_class(self, method=None):
|
||||||
"""
|
"""
|
||||||
Returns the form class used to validate this resource.
|
Returns the form class used to validate this resource.
|
||||||
|
@ -209,7 +197,6 @@ class FormResource(Resource):
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
|
|
||||||
def get_bound_form(self, data=None, files=None, method=None):
|
def get_bound_form(self, data=None, files=None, method=None):
|
||||||
"""
|
"""
|
||||||
Given some content return a Django form bound to that content.
|
Given some content return a Django form bound to that content.
|
||||||
|
@ -226,20 +213,6 @@ class FormResource(Resource):
|
||||||
return form()
|
return form()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#class _RegisterModelResource(type):
|
|
||||||
# """
|
|
||||||
# Auto register new ModelResource classes into ``_model_to_resource``
|
|
||||||
# """
|
|
||||||
# def __new__(cls, name, bases, dct):
|
|
||||||
# resource_cls = type.__new__(cls, name, bases, dct)
|
|
||||||
# model_cls = dct.get('model', None)
|
|
||||||
# if model_cls:
|
|
||||||
# _model_to_resource[model_cls] = resource_cls
|
|
||||||
# return resource_cls
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelResource(FormResource):
|
class ModelResource(FormResource):
|
||||||
"""
|
"""
|
||||||
Resource class that uses forms for validation and otherwise falls back to a model form if no form is set.
|
Resource class that uses forms for validation and otherwise falls back to a model form if no form is set.
|
||||||
|
@ -282,7 +255,6 @@ class ModelResource(FormResource):
|
||||||
The list of fields to exclude. This is only used if :attr:`fields` is not set.
|
The list of fields to exclude. This is only used if :attr:`fields` is not set.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
include = ('url',)
|
include = ('url',)
|
||||||
"""
|
"""
|
||||||
The list of extra fields to include. This is only used if :attr:`fields` is not set.
|
The list of extra fields to include. This is only used if :attr:`fields` is not set.
|
||||||
|
@ -298,7 +270,6 @@ class ModelResource(FormResource):
|
||||||
|
|
||||||
self.model = getattr(view, 'model', None) or self.model
|
self.model = getattr(view, 'model', None) or self.model
|
||||||
|
|
||||||
|
|
||||||
def validate_request(self, data, files=None):
|
def validate_request(self, data, files=None):
|
||||||
"""
|
"""
|
||||||
Given some content as input return some cleaned, validated content.
|
Given some content as input return some cleaned, validated content.
|
||||||
|
@ -315,7 +286,6 @@ class ModelResource(FormResource):
|
||||||
"""
|
"""
|
||||||
return self._validate(data, files, allowed_extra_fields=self._property_fields_set)
|
return self._validate(data, files, allowed_extra_fields=self._property_fields_set)
|
||||||
|
|
||||||
|
|
||||||
def get_bound_form(self, data=None, files=None, method=None):
|
def get_bound_form(self, data=None, files=None, method=None):
|
||||||
"""
|
"""
|
||||||
Given some content return a ``Form`` instance bound to that content.
|
Given some content return a ``Form`` instance bound to that content.
|
||||||
|
@ -348,7 +318,6 @@ class ModelResource(FormResource):
|
||||||
|
|
||||||
return form()
|
return form()
|
||||||
|
|
||||||
|
|
||||||
def url(self, instance):
|
def url(self, instance):
|
||||||
"""
|
"""
|
||||||
Attempts to reverse resolve the url of the given model *instance* for this resource.
|
Attempts to reverse resolve the url of the given model *instance* for this resource.
|
||||||
|
@ -390,7 +359,6 @@ class ModelResource(FormResource):
|
||||||
pass
|
pass
|
||||||
raise _SkipField
|
raise _SkipField
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _model_fields_set(self):
|
def _model_fields_set(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -11,6 +11,7 @@ __all__ = ('Response', 'ErrorResponse')
|
||||||
|
|
||||||
# TODO: remove raw_content/cleaned_content and just use content?
|
# TODO: remove raw_content/cleaned_content and just use content?
|
||||||
|
|
||||||
|
|
||||||
class Response(object):
|
class Response(object):
|
||||||
"""
|
"""
|
||||||
An HttpResponse that may include content that hasn't yet been serialized.
|
An HttpResponse that may include content that hasn't yet been serialized.
|
||||||
|
|
|
@ -3,10 +3,8 @@ Customizable serialization.
|
||||||
"""
|
"""
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from django.db.models.fields.related import RelatedField
|
|
||||||
from django.utils.encoding import smart_unicode, is_protected_type, smart_str
|
from django.utils.encoding import smart_unicode, is_protected_type, smart_str
|
||||||
|
|
||||||
import decimal
|
|
||||||
import inspect
|
import inspect
|
||||||
import types
|
import types
|
||||||
|
|
||||||
|
@ -24,12 +22,14 @@ def _field_to_tuple(field):
|
||||||
return (field[0], field[1])
|
return (field[0], field[1])
|
||||||
return (field, None)
|
return (field, None)
|
||||||
|
|
||||||
|
|
||||||
def _fields_to_list(fields):
|
def _fields_to_list(fields):
|
||||||
"""
|
"""
|
||||||
Return a list of field names.
|
Return a list of field names.
|
||||||
"""
|
"""
|
||||||
return [_field_to_tuple(field)[0] for field in fields or ()]
|
return [_field_to_tuple(field)[0] for field in fields or ()]
|
||||||
|
|
||||||
|
|
||||||
def _fields_to_dict(fields):
|
def _fields_to_dict(fields):
|
||||||
"""
|
"""
|
||||||
Return a `dict` of field name -> None, or tuple of fields, or Serializer class
|
Return a `dict` of field name -> None, or tuple of fields, or Serializer class
|
||||||
|
@ -104,13 +104,11 @@ class Serializer(object):
|
||||||
The maximum depth to serialize to, or `None`.
|
The maximum depth to serialize to, or `None`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, depth=None, stack=[], **kwargs):
|
def __init__(self, depth=None, stack=[], **kwargs):
|
||||||
if depth is not None:
|
if depth is not None:
|
||||||
self.depth = depth
|
self.depth = depth
|
||||||
self.stack = stack
|
self.stack = stack
|
||||||
|
|
||||||
|
|
||||||
def get_fields(self, obj):
|
def get_fields(self, obj):
|
||||||
"""
|
"""
|
||||||
Return the set of field names/keys to use for a model instance/dict.
|
Return the set of field names/keys to use for a model instance/dict.
|
||||||
|
@ -130,7 +128,6 @@ class Serializer(object):
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
|
|
||||||
def get_default_fields(self, obj):
|
def get_default_fields(self, obj):
|
||||||
"""
|
"""
|
||||||
Return the default list of field names/keys for a model instance/dict.
|
Return the default list of field names/keys for a model instance/dict.
|
||||||
|
@ -142,7 +139,6 @@ class Serializer(object):
|
||||||
else:
|
else:
|
||||||
return obj.keys()
|
return obj.keys()
|
||||||
|
|
||||||
|
|
||||||
def get_related_serializer(self, key):
|
def get_related_serializer(self, key):
|
||||||
info = _fields_to_dict(self.fields).get(key, None)
|
info = _fields_to_dict(self.fields).get(key, None)
|
||||||
|
|
||||||
|
@ -172,7 +168,6 @@ class Serializer(object):
|
||||||
# Otherwise use `related_serializer` or fall back to `Serializer`
|
# Otherwise use `related_serializer` or fall back to `Serializer`
|
||||||
return getattr(self, 'related_serializer') or Serializer
|
return getattr(self, 'related_serializer') or Serializer
|
||||||
|
|
||||||
|
|
||||||
def serialize_key(self, key):
|
def serialize_key(self, key):
|
||||||
"""
|
"""
|
||||||
Keys serialize to their string value,
|
Keys serialize to their string value,
|
||||||
|
@ -180,7 +175,6 @@ class Serializer(object):
|
||||||
"""
|
"""
|
||||||
return self.rename.get(smart_str(key), smart_str(key))
|
return self.rename.get(smart_str(key), smart_str(key))
|
||||||
|
|
||||||
|
|
||||||
def serialize_val(self, key, obj):
|
def serialize_val(self, key, obj):
|
||||||
"""
|
"""
|
||||||
Convert a model field or dict value into a serializable representation.
|
Convert a model field or dict value into a serializable representation.
|
||||||
|
@ -202,7 +196,6 @@ class Serializer(object):
|
||||||
|
|
||||||
return related_serializer(depth=depth, stack=stack).serialize(obj)
|
return related_serializer(depth=depth, stack=stack).serialize(obj)
|
||||||
|
|
||||||
|
|
||||||
def serialize_max_depth(self, obj):
|
def serialize_max_depth(self, obj):
|
||||||
"""
|
"""
|
||||||
Determine how objects should be serialized once `depth` is exceeded.
|
Determine how objects should be serialized once `depth` is exceeded.
|
||||||
|
@ -210,7 +203,6 @@ class Serializer(object):
|
||||||
"""
|
"""
|
||||||
raise _SkipField
|
raise _SkipField
|
||||||
|
|
||||||
|
|
||||||
def serialize_recursion(self, obj):
|
def serialize_recursion(self, obj):
|
||||||
"""
|
"""
|
||||||
Determine how objects should be serialized if recursion occurs.
|
Determine how objects should be serialized if recursion occurs.
|
||||||
|
@ -218,7 +210,6 @@ class Serializer(object):
|
||||||
"""
|
"""
|
||||||
raise _SkipField
|
raise _SkipField
|
||||||
|
|
||||||
|
|
||||||
def serialize_model(self, instance):
|
def serialize_model(self, instance):
|
||||||
"""
|
"""
|
||||||
Given a model instance or dict, serialize it to a dict..
|
Given a model instance or dict, serialize it to a dict..
|
||||||
|
@ -253,35 +244,30 @@ class Serializer(object):
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def serialize_iter(self, obj):
|
def serialize_iter(self, obj):
|
||||||
"""
|
"""
|
||||||
Convert iterables into a serializable representation.
|
Convert iterables into a serializable representation.
|
||||||
"""
|
"""
|
||||||
return [self.serialize(item) for item in obj]
|
return [self.serialize(item) for item in obj]
|
||||||
|
|
||||||
|
|
||||||
def serialize_func(self, obj):
|
def serialize_func(self, obj):
|
||||||
"""
|
"""
|
||||||
Convert no-arg methods and functions into a serializable representation.
|
Convert no-arg methods and functions into a serializable representation.
|
||||||
"""
|
"""
|
||||||
return self.serialize(obj())
|
return self.serialize(obj())
|
||||||
|
|
||||||
|
|
||||||
def serialize_manager(self, obj):
|
def serialize_manager(self, obj):
|
||||||
"""
|
"""
|
||||||
Convert a model manager into a serializable representation.
|
Convert a model manager into a serializable representation.
|
||||||
"""
|
"""
|
||||||
return self.serialize_iter(obj.all())
|
return self.serialize_iter(obj.all())
|
||||||
|
|
||||||
|
|
||||||
def serialize_fallback(self, obj):
|
def serialize_fallback(self, obj):
|
||||||
"""
|
"""
|
||||||
Convert any unhandled object into a serializable representation.
|
Convert any unhandled object into a serializable representation.
|
||||||
"""
|
"""
|
||||||
return smart_unicode(obj, strings_only=True)
|
return smart_unicode(obj, strings_only=True)
|
||||||
|
|
||||||
|
|
||||||
def serialize(self, obj):
|
def serialize(self, obj):
|
||||||
"""
|
"""
|
||||||
Convert any object into a serializable representation.
|
Convert any object into a serializable representation.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from django.core.urlresolvers import resolve
|
from django.core.urlresolvers import resolve
|
||||||
from djangorestframework.utils.description import get_name
|
from djangorestframework.utils.description import get_name
|
||||||
|
|
||||||
|
|
||||||
def get_breadcrumbs(url):
|
def get_breadcrumbs(url):
|
||||||
"""Given a url returns a list of breadcrumbs, which are each a tuple of (name, url)."""
|
"""Given a url returns a list of breadcrumbs, which are each a tuple of (name, url)."""
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ def get_name(view):
|
||||||
return re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', name).strip()
|
return re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', name).strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_description(view):
|
def get_description(view):
|
||||||
"""
|
"""
|
||||||
Provide a description for the view.
|
Provide a description for the view.
|
||||||
|
@ -63,7 +62,6 @@ def get_description(view):
|
||||||
if getattr(view, 'cls_instance', None):
|
if getattr(view, 'cls_instance', None):
|
||||||
view = view.cls_instance
|
view = view.cls_instance
|
||||||
|
|
||||||
|
|
||||||
# If this view has a resource that's been overridden, then use the resource's doctring
|
# If this view has a resource that's been overridden, then use the resource's doctring
|
||||||
if getattr(view, 'resource', None) not in (None, Resource, FormResource, ModelResource):
|
if getattr(view, 'resource', None) not in (None, Resource, FormResource, ModelResource):
|
||||||
doc = view.resource.__doc__
|
doc = view.resource.__doc__
|
||||||
|
@ -88,4 +86,3 @@ def get_description(view):
|
||||||
|
|
||||||
# otherwise return it as-is
|
# otherwise return it as-is
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
|
@ -103,29 +103,6 @@ class _MediaType(object):
|
||||||
return 2
|
return 2
|
||||||
return 3
|
return 3
|
||||||
|
|
||||||
#def quality(self):
|
|
||||||
# """
|
|
||||||
# Return a quality level for the media type.
|
|
||||||
# """
|
|
||||||
# try:
|
|
||||||
# return Decimal(self.params.get('q', '1.0'))
|
|
||||||
# except Exception:
|
|
||||||
# return Decimal(0)
|
|
||||||
|
|
||||||
#def score(self):
|
|
||||||
# """
|
|
||||||
# Return an overall score for a given media type given it's quality and precedence.
|
|
||||||
# """
|
|
||||||
# # NB. quality values should only have up to 3 decimal points
|
|
||||||
# # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9
|
|
||||||
# return self.quality * 10000 + self.precedence
|
|
||||||
|
|
||||||
#def as_tuple(self):
|
|
||||||
# return (self.main_type, self.sub_type, self.params)
|
|
||||||
|
|
||||||
#def __repr__(self):
|
|
||||||
# return "<MediaType %s>" % (self.as_tuple(),)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return unicode(self).encode('utf-8')
|
return unicode(self).encode('utf-8')
|
||||||
|
|
||||||
|
@ -134,4 +111,3 @@ class _MediaType(object):
|
||||||
for key, val in self.params.items():
|
for key, val in self.params.items():
|
||||||
ret += "; %s=%s" % (key, val)
|
ret += "; %s=%s" % (key, val)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,16 @@ from django.shortcuts import render_to_response
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
|
||||||
def deny_robots(request):
|
def deny_robots(request):
|
||||||
return HttpResponse('User-agent: *\nDisallow: /', mimetype='text/plain')
|
return HttpResponse('User-agent: *\nDisallow: /', mimetype='text/plain')
|
||||||
|
|
||||||
|
|
||||||
def favicon(request):
|
def favicon(request):
|
||||||
data = 'AAABAAEAEREAAAEAIADwBAAAFgAAACgAAAARAAAAIgAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAA//+AAP9/gAD+P4AA4AOAAMADgADAA4AAwAOAAMMBgACCAIAAAAGAAIBDgADAA4AAwAOAAMADgADAB4AA/H+AAP7/gAA='
|
||||||
return HttpResponse(base64.b64decode(data), mimetype='image/vnd.microsoft.icon')
|
return HttpResponse(base64.b64decode(data), mimetype='image/vnd.microsoft.icon')
|
||||||
|
|
||||||
|
|
||||||
# BLERGH
|
# BLERGH
|
||||||
# Replicate django.contrib.auth.views.login simply so we don't have get users to update TEMPLATE_CONTEXT_PROCESSORS
|
# Replicate django.contrib.auth.views.login simply so we don't have get users to update TEMPLATE_CONTEXT_PROCESSORS
|
||||||
# to add ADMIN_MEDIA_PREFIX to the RequestContext. I don't like this but really really want users to not have to
|
# to add ADMIN_MEDIA_PREFIX to the RequestContext. I don't like this but really really want users to not have to
|
||||||
|
|
|
@ -25,7 +25,6 @@ __all__ = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
|
class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
|
||||||
"""
|
"""
|
||||||
Handles incoming requests and maps them to REST operations.
|
Handles incoming requests and maps them to REST operations.
|
||||||
|
@ -185,18 +184,21 @@ class ModelView(View):
|
||||||
"""
|
"""
|
||||||
resource = resources.ModelResource
|
resource = resources.ModelResource
|
||||||
|
|
||||||
|
|
||||||
class InstanceModelView(InstanceMixin, ReadModelMixin, UpdateModelMixin, DeleteModelMixin, ModelView):
|
class InstanceModelView(InstanceMixin, ReadModelMixin, UpdateModelMixin, DeleteModelMixin, ModelView):
|
||||||
"""
|
"""
|
||||||
A view which provides default operations for read/update/delete against a model instance.
|
A view which provides default operations for read/update/delete against a model instance.
|
||||||
"""
|
"""
|
||||||
_suffix = 'Instance'
|
_suffix = 'Instance'
|
||||||
|
|
||||||
|
|
||||||
class ListModelView(ListModelMixin, ModelView):
|
class ListModelView(ListModelMixin, ModelView):
|
||||||
"""
|
"""
|
||||||
A view which provides default operations for list, against a model in the database.
|
A view which provides default operations for list, against a model in the database.
|
||||||
"""
|
"""
|
||||||
_suffix = 'List'
|
_suffix = 'List'
|
||||||
|
|
||||||
|
|
||||||
class ListOrCreateModelView(ListModelMixin, CreateModelMixin, ModelView):
|
class ListOrCreateModelView(ListModelMixin, CreateModelMixin, ModelView):
|
||||||
"""
|
"""
|
||||||
A view which provides default operations for list and create, against a model in the database.
|
A view which provides default operations for list and create, against a model in the database.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user