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
66eabe8b
Commit
66eabe8b
authored
Feb 21, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove staticviews. Use standard login/logout
parent
b074754b
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
57 additions
and
31 deletions
+57
-31
djangorestframework/renderers.py
+1
-3
djangorestframework/templates/djangorestframework/base.html
+9
-2
djangorestframework/templates/djangorestframework/login.html
+1
-1
djangorestframework/tests/accept.py
+13
-2
djangorestframework/tests/oauthentication.py
+1
-1
djangorestframework/tests/renderers.py
+2
-1
djangorestframework/tests/views.py
+6
-6
djangorestframework/urls.py
+7
-4
docs/howto/setup.rst
+9
-8
docs/index.rst
+6
-0
examples/urls.py
+2
-3
No files found.
djangorestframework/renderers.py
View file @
66eabe8b
...
@@ -335,7 +335,7 @@ class DocumentingTemplateRenderer(BaseRenderer):
...
@@ -335,7 +335,7 @@ class DocumentingTemplateRenderer(BaseRenderer):
context
=
RequestContext
(
self
.
view
.
request
,
{
context
=
RequestContext
(
self
.
view
.
request
,
{
'content'
:
content
,
'content'
:
content
,
'view'
:
self
.
view
,
'view'
:
self
.
view
,
'request'
:
self
.
view
.
request
,
# TODO: remove
'request'
:
self
.
view
.
request
,
'response'
:
self
.
view
.
response
,
'response'
:
self
.
view
.
response
,
'description'
:
description
,
'description'
:
description
,
'name'
:
name
,
'name'
:
name
,
...
@@ -344,8 +344,6 @@ class DocumentingTemplateRenderer(BaseRenderer):
...
@@ -344,8 +344,6 @@ class DocumentingTemplateRenderer(BaseRenderer):
'available_formats'
:
self
.
view
.
_rendered_formats
,
'available_formats'
:
self
.
view
.
_rendered_formats
,
'put_form'
:
put_form_instance
,
'put_form'
:
put_form_instance
,
'post_form'
:
post_form_instance
,
'post_form'
:
post_form_instance
,
'login_url'
:
login_url
,
'logout_url'
:
logout_url
,
'FORMAT_PARAM'
:
self
.
_FORMAT_QUERY_PARAM
,
'FORMAT_PARAM'
:
self
.
_FORMAT_QUERY_PARAM
,
'METHOD_PARAM'
:
getattr
(
self
.
view
,
'_METHOD_PARAM'
,
None
),
'METHOD_PARAM'
:
getattr
(
self
.
view
,
'_METHOD_PARAM'
,
None
),
})
})
...
...
djangorestframework/templates/djangorestframework/base.html
View file @
66eabe8b
...
@@ -20,8 +20,15 @@
...
@@ -20,8 +20,15 @@
<h1
id=
"site-name"
>
{% block branding %}
<a
href=
'http://django-rest-framework.org'
>
Django REST framework
</a>
<span
class=
"version"
>
v {{ version }}
</span>
{% endblock %}
</h1>
<h1
id=
"site-name"
>
{% block branding %}
<a
href=
'http://django-rest-framework.org'
>
Django REST framework
</a>
<span
class=
"version"
>
v {{ version }}
</span>
{% endblock %}
</h1>
</div>
</div>
<div
id=
"user-tools"
>
<div
id=
"user-tools"
>
{% if user.is_active %}Welcome, {{ user }}.{% if logout_url %}
<a
href=
'{{ logout_url }}'
>
Log out
</a>
{% endif %}{% else %}Anonymous {% if login_url %}
<a
href=
'{{ login_url }}'
>
Log in
</a>
{% endif %}{% endif %}
{% block userlinks %}
{% block userlinks %}{% endblock %}
{% if user.is_active %}
Welcome, {{ user }}.
<a
href=
'{% url djangorestframework:logout %}?next={{ request.path }}'
>
Log out
</a>
{% else %}
Anonymous
<a
href=
'{% url djangorestframework:login %}?next={{ request.path }}'
>
Log in
</a>
{% endif %}
{% endblock %}
</div>
</div>
{% block nav-global %}{% endblock %}
{% block nav-global %}{% endblock %}
</div>
</div>
...
...
djangorestframework/templates/djangorestframework/login.html
View file @
66eabe8b
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
<div
id=
"content"
class=
"colM"
>
<div
id=
"content"
class=
"colM"
>
<div
id=
"content-main"
>
<div
id=
"content-main"
>
<form
method=
"post"
action=
"{% url djangorestframework
.utils.staticviews.api_
login %}"
id=
"login-form"
>
<form
method=
"post"
action=
"{% url djangorestframework
:
login %}"
id=
"login-form"
>
{% csrf_token %}
{% csrf_token %}
<div
class=
"form-row"
>
<div
class=
"form-row"
>
<label
for=
"id_username"
>
Username:
</label>
{{ form.username }}
<label
for=
"id_username"
>
Username:
</label>
{{ form.username }}
...
...
djangorestframework/tests/accept.py
View file @
66eabe8b
from
django.conf.urls.defaults
import
patterns
,
url
,
include
from
django.test
import
TestCase
from
django.test
import
TestCase
from
djangorestframework.compat
import
RequestFactory
from
djangorestframework.compat
import
RequestFactory
from
djangorestframework.views
import
View
from
djangorestframework.views
import
View
...
@@ -13,9 +14,19 @@ SAFARI_5_0_USER_AGENT = 'Mozilla/5.0 (X11; U; Linux x86_64; en-ca) AppleWebKit/5
...
@@ -13,9 +14,19 @@ SAFARI_5_0_USER_AGENT = 'Mozilla/5.0 (X11; U; Linux x86_64; en-ca) AppleWebKit/5
OPERA_11_0_MSIE_USER_AGENT
=
'Mozilla/4.0 (compatible; MSIE 8.0; X11; Linux x86_64; pl) Opera 11.00'
OPERA_11_0_MSIE_USER_AGENT
=
'Mozilla/4.0 (compatible; MSIE 8.0; X11; Linux x86_64; pl) Opera 11.00'
OPERA_11_0_OPERA_USER_AGENT
=
'Opera/9.80 (X11; Linux x86_64; U; pl) Presto/2.7.62 Version/11.00'
OPERA_11_0_OPERA_USER_AGENT
=
'Opera/9.80 (X11; Linux x86_64; U; pl) Presto/2.7.62 Version/11.00'
urlpatterns
=
patterns
(
''
,
url
(
r'^api'
,
include
(
'djangorestframework.urls'
,
namespace
=
'djangorestframework'
))
)
class
UserAgentMungingTest
(
TestCase
):
class
UserAgentMungingTest
(
TestCase
):
"""We need to fake up the accept headers when we deal with MSIE. Blergh.
"""
http://www.gethifi.com/blog/browser-rest-http-accept-headers"""
We need to fake up the accept headers when we deal with MSIE. Blergh.
http://www.gethifi.com/blog/browser-rest-http-accept-headers
"""
urls
=
'djangorestframework.tests.accept'
def
setUp
(
self
):
def
setUp
(
self
):
...
...
djangorestframework/tests/oauthentication.py
View file @
66eabe8b
...
@@ -27,7 +27,7 @@ else:
...
@@ -27,7 +27,7 @@ else:
urlpatterns
=
patterns
(
''
,
urlpatterns
=
patterns
(
''
,
url
(
r'^$'
,
oauth_required
(
ClientView
.
as_view
())),
url
(
r'^$'
,
oauth_required
(
ClientView
.
as_view
())),
url
(
r'^oauth/'
,
include
(
'oauth_provider.urls'
)),
url
(
r'^oauth/'
,
include
(
'oauth_provider.urls'
)),
url
(
r'^
accounts/login/$'
,
'djangorestframework.utils.staticviews.api_login'
),
url
(
r'^
restframework/'
,
include
(
'djangorestframework.urls'
,
namespace
=
'djangorestframework'
)
),
)
)
...
...
djangorestframework/tests/renderers.py
View file @
66eabe8b
import
re
import
re
from
django.conf.urls.defaults
import
patterns
,
url
from
django.conf.urls.defaults
import
patterns
,
url
,
include
from
django.test
import
TestCase
from
django.test
import
TestCase
from
djangorestframework
import
status
from
djangorestframework
import
status
...
@@ -73,6 +73,7 @@ urlpatterns = patterns('',
...
@@ -73,6 +73,7 @@ urlpatterns = patterns('',
url
(
r'^jsonp/nojsonrenderer$'
,
MockGETView
.
as_view
(
renderers
=
[
JSONPRenderer
])),
url
(
r'^jsonp/nojsonrenderer$'
,
MockGETView
.
as_view
(
renderers
=
[
JSONPRenderer
])),
url
(
r'^html$'
,
HTMLView
.
as_view
()),
url
(
r'^html$'
,
HTMLView
.
as_view
()),
url
(
r'^html1$'
,
HTMLView1
.
as_view
()),
url
(
r'^html1$'
,
HTMLView1
.
as_view
()),
url
(
r'^api'
,
include
(
'djangorestframework.urls'
,
namespace
=
'djangorestframework'
))
)
)
...
...
djangorestframework/tests/views.py
View file @
66eabe8b
from
django.conf.urls.defaults
import
patterns
,
url
from
django.core.urlresolvers
import
reverse
from
django.conf.urls.defaults
import
patterns
,
url
,
include
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test
import
Client
from
django.test
import
Client
...
@@ -45,14 +46,13 @@ class MockResource(ModelResource):
...
@@ -45,14 +46,13 @@ class MockResource(ModelResource):
model
=
MockResourceModel
model
=
MockResourceModel
fields
=
(
'foo'
,
'bar'
,
'baz'
)
fields
=
(
'foo'
,
'bar'
,
'baz'
)
urlpatterns
=
patterns
(
'djangorestframework.utils.staticviews'
,
urlpatterns
=
patterns
(
''
,
url
(
r'^accounts/login$'
,
'api_login'
),
url
(
r'^accounts/logout$'
,
'api_logout'
),
url
(
r'^mock/$'
,
MockView
.
as_view
()),
url
(
r'^mock/$'
,
MockView
.
as_view
()),
url
(
r'^mock/final/$'
,
MockViewFinal
.
as_view
()),
url
(
r'^mock/final/$'
,
MockViewFinal
.
as_view
()),
url
(
r'^resourcemock/$'
,
ResourceMockView
.
as_view
()),
url
(
r'^resourcemock/$'
,
ResourceMockView
.
as_view
()),
url
(
r'^model/$'
,
ListOrCreateModelView
.
as_view
(
resource
=
MockResource
)),
url
(
r'^model/$'
,
ListOrCreateModelView
.
as_view
(
resource
=
MockResource
)),
url
(
r'^model/(?P<pk>[^/]+)/$'
,
InstanceModelView
.
as_view
(
resource
=
MockResource
)),
url
(
r'^model/(?P<pk>[^/]+)/$'
,
InstanceModelView
.
as_view
(
resource
=
MockResource
)),
url
(
r'^restframework/'
,
include
(
'djangorestframework.urls'
,
namespace
=
'djangorestframework'
)),
)
)
class
BaseViewTests
(
TestCase
):
class
BaseViewTests
(
TestCase
):
...
@@ -123,13 +123,13 @@ class ExtraViewsTests(TestCase):
...
@@ -123,13 +123,13 @@ class ExtraViewsTests(TestCase):
def
test_login_view
(
self
):
def
test_login_view
(
self
):
"""Ensure the login view exists"""
"""Ensure the login view exists"""
response
=
self
.
client
.
get
(
'/accounts/login'
)
response
=
self
.
client
.
get
(
reverse
(
'djangorestframework:login'
)
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
[
'Content-Type'
]
.
split
(
';'
)[
0
],
'text/html'
)
self
.
assertEqual
(
response
[
'Content-Type'
]
.
split
(
';'
)[
0
],
'text/html'
)
def
test_logout_view
(
self
):
def
test_logout_view
(
self
):
"""Ensure the logout view exists"""
"""Ensure the logout view exists"""
response
=
self
.
client
.
get
(
'/accounts/logout'
)
response
=
self
.
client
.
get
(
reverse
(
'djangorestframework:logout'
)
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
[
'Content-Type'
]
.
split
(
';'
)[
0
],
'text/html'
)
self
.
assertEqual
(
response
[
'Content-Type'
]
.
split
(
';'
)[
0
],
'text/html'
)
...
...
djangorestframework/urls.py
View file @
66eabe8b
from
django.conf.urls.defaults
import
patterns
from
django.conf.urls.defaults
import
patterns
,
url
urlpatterns
=
patterns
(
'djangorestframework.utils.staticviews'
,
(
r'^accounts/login/$'
,
'api_login'
),
template_name
=
{
'template_name'
:
'djangorestframework/login.html'
}
(
r'^accounts/logout/$'
,
'api_logout'
),
urlpatterns
=
patterns
(
'django.contrib.auth.views'
,
url
(
r'^login/$'
,
'login'
,
template_name
,
name
=
'login'
),
url
(
r'^logout/$'
,
'logout'
,
template_name
,
name
=
'logout'
),
)
)
docs/howto/setup.rst
View file @
66eabe8b
...
@@ -53,16 +53,17 @@ YAML support is optional, and requires `PyYAML`_.
...
@@ -53,16 +53,17 @@ YAML support is optional, and requires `PyYAML`_.
Login / Logout
Login / Logout
--------------
--------------
Django REST framework includes login and logout views that are
useful
if
Django REST framework includes login and logout views that are
needed
if
you're using the self-documenting API
::
you're using the self-documenting API
.
from django.conf.urls.defaults import patterns
Make sure you include the following in your `urlconf`::
urlpatterns = patterns('djangorestframework.views',
from django.conf.urls.defaults import patterns, url
# Add your resources here
(r'^accounts/login/$', 'api_login'),
urlpatterns = patterns('',
(r'^accounts/logout/$', 'api_logout'),
...
)
url(r'^restframework', include('djangorestframework.urls', namespace='djangorestframework'))
)
.. _django.contrib.staticfiles: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/
.. _django.contrib.staticfiles: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/
.. _django-staticfiles: http://pypi.python.org/pypi/django-staticfiles/
.. _django-staticfiles: http://pypi.python.org/pypi/django-staticfiles/
...
...
docs/index.rst
View file @
66eabe8b
...
@@ -64,6 +64,12 @@ To add Django REST framework to a Django project:
...
@@ -64,6 +64,12 @@ To add Django REST framework to a Django project:
* Ensure that the ``djangorestframework`` directory is on your ``PYTHONPATH``.
* Ensure that the ``djangorestframework`` directory is on your ``PYTHONPATH``.
* Add ``djangorestframework`` to your ``INSTALLED_APPS``.
* Add ``djangorestframework`` to your ``INSTALLED_APPS``.
* Add the following to your URLconf. (To include the REST framework Login/Logout views.)::
urlpatterns = patterns('',
...
url(r'
^
restframework
', include('
djangorestframework
.
urls
', namespace='
djangorestframework
'))
)
For more information on settings take a look at the :ref:`setup` section.
For more information on settings take a look at the :ref:`setup` section.
...
...
examples/urls.py
View file @
66eabe8b
from
django.conf.urls.defaults
import
patterns
,
include
from
django.conf.urls.defaults
import
patterns
,
include
,
url
from
sandbox.views
import
Sandbox
from
sandbox.views
import
Sandbox
try
:
try
:
from
django.contrib.staticfiles.urls
import
staticfiles_urlpatterns
from
django.contrib.staticfiles.urls
import
staticfiles_urlpatterns
...
@@ -15,8 +15,7 @@ urlpatterns = patterns('',
...
@@ -15,8 +15,7 @@ urlpatterns = patterns('',
(
r'^pygments/'
,
include
(
'pygments_api.urls'
)),
(
r'^pygments/'
,
include
(
'pygments_api.urls'
)),
(
r'^blog-post/'
,
include
(
'blogpost.urls'
)),
(
r'^blog-post/'
,
include
(
'blogpost.urls'
)),
(
r'^permissions-example/'
,
include
(
'permissionsexample.urls'
)),
(
r'^permissions-example/'
,
include
(
'permissionsexample.urls'
)),
url
(
r'^restframework/'
,
include
(
'djangorestframework.urls'
,
namespace
=
'djangorestframework'
)),
(
r'^'
,
include
(
'djangorestframework.urls'
)),
)
)
urlpatterns
+=
staticfiles_urlpatterns
()
urlpatterns
+=
staticfiles_urlpatterns
()
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