Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
01d6a089
Commit
01d6a089
authored
Sep 07, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bits of cleanup
parent
c648f278
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
9 deletions
+27
-9
djangorestframework/generics.py
+3
-2
djangorestframework/mixins.py
+11
-0
djangorestframework/settings.py
+7
-5
djangorestframework/urlpatterns.py
+6
-2
No files found.
djangorestframework/generics.py
View file @
01d6a089
...
...
@@ -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 ###
...
...
djangorestframework/mixins.py
View file @
01d6a089
"""
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
=
{
...
...
djangorestframework/settings.py
View file @
01d6a089
...
...
@@ -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
():
...
...
djangorestframework/urlpatterns.py
View file @
01d6a089
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment