mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 10:03:57 +03:00
Bits of cleanup
This commit is contained in:
parent
c648f2786f
commit
01d6a0899e
|
@ -41,8 +41,9 @@ class SingleObjectBaseView(SingleObjectMixin, BaseView):
|
|||
"""
|
||||
Override default to add support for object-level permissions.
|
||||
"""
|
||||
super(self, SingleObjectBaseView).get_object()
|
||||
self.check_permissions(self.request, self.object)
|
||||
obj = super(SingleObjectBaseView, self).get_object()
|
||||
self.check_permissions(self.request, obj)
|
||||
return obj
|
||||
|
||||
|
||||
### Concrete view classes that provide method handlers ###
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
"""
|
||||
Basic building blocks for generic class based views.
|
||||
|
||||
We don't bind behaviour to http method handlers yet,
|
||||
which allows mixin classes to be composed in interesting ways.
|
||||
|
||||
Eg. Use mixins to build a Resource class, and have a Router class
|
||||
perform the binding of http methods to actions for us.
|
||||
"""
|
||||
from djangorestframework import status
|
||||
from djangorestframework.response import Response
|
||||
|
||||
|
@ -68,6 +77,8 @@ class MetadataMixin(object):
|
|||
"""
|
||||
Return a dicitonary of view metadata.
|
||||
Should be mixed in with any `BaseView`.
|
||||
|
||||
This mixin is typically used for the HTTP 'OPTIONS' method.
|
||||
"""
|
||||
def metadata(self, request, *args, **kwargs):
|
||||
content = {
|
||||
|
|
|
@ -13,10 +13,12 @@ API_SETTINGS = {
|
|||
)
|
||||
}
|
||||
|
||||
This module provides the `api_setting` object, that is used to access
|
||||
REST framework settings, checking for user settings first, then falling
|
||||
back to the defaults.
|
||||
"""
|
||||
from django.conf import settings
|
||||
from django.utils import importlib
|
||||
from djangorestframework.compat import yaml
|
||||
|
||||
|
||||
DEFAULTS = {
|
||||
|
@ -35,17 +37,16 @@ DEFAULTS = {
|
|||
),
|
||||
'DEFAULT_PERMISSIONS': (),
|
||||
'DEFAULT_THROTTLES': (),
|
||||
|
||||
'UNAUTHENTICATED_USER': 'django.contrib.auth.models.AnonymousUser',
|
||||
'UNAUTHENTICATED_TOKEN': None,
|
||||
|
||||
'FORM_METHOD_OVERRIDE': '_method',
|
||||
'FORM_CONTENT_OVERRIDE': '_content',
|
||||
'FORM_CONTENTTYPE_OVERRIDE': '_content_type',
|
||||
'URL_ACCEPT_OVERRIDE': '_accept'
|
||||
}
|
||||
|
||||
if yaml:
|
||||
DEFAULTS['DEFAULT_RENDERERS'] += ('djangorestframework.renderers.YAMLRenderer', )
|
||||
|
||||
|
||||
# List of settings that may be in string import notation.
|
||||
IMPORT_STRINGS = (
|
||||
|
@ -97,7 +98,8 @@ class APISettings(object):
|
|||
from djangorestframework.settings import api_settings
|
||||
print api_settings.DEFAULT_RENDERERS
|
||||
|
||||
Any setting with string import paths will be resolved.
|
||||
Any setting with string import paths will be automatically resolved
|
||||
and return the class, rather than the string literal.
|
||||
"""
|
||||
def __getattr__(self, attr):
|
||||
if attr not in DEFAULTS.keys():
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
from django.conf.urls.defaults import url
|
||||
from djangorestframework.settings import api_settings
|
||||
|
||||
|
||||
def format_suffix_patterns(urlpatterns, suffix_required=False):
|
||||
def format_suffix_patterns(urlpatterns, suffix_required=False, suffix_kwarg=None):
|
||||
"""
|
||||
Supplement existing urlpatterns with corrosponding patterns that also
|
||||
include a '.format' suffix. Retains urlpattern ordering.
|
||||
"""
|
||||
suffix_kwarg = suffix_kwarg or api_settings.FORMAT_SUFFIX_KWARG
|
||||
suffix_pattern = '.(?P<%s>[a-z]+)$' % suffix_kwarg
|
||||
|
||||
ret = []
|
||||
for urlpattern in urlpatterns:
|
||||
# Form our complementing '.format' urlpattern
|
||||
regex = urlpattern.regex.pattern.rstrip('$') + '.(?P<format>[a-z]+)$'
|
||||
regex = urlpattern.regex.pattern.rstrip('$') + suffix_pattern
|
||||
view = urlpattern._callback or urlpattern._callback_str
|
||||
kwargs = urlpattern.default_args
|
||||
name = urlpattern.name
|
||||
|
|
Loading…
Reference in New Issue
Block a user