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
f1dc9be5
Commit
f1dc9be5
authored
Sep 07, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optional login/logout tags so browseable API will work without requiring auth views
parent
215de9af
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
8 deletions
+42
-8
djangorestframework/templates/djangorestframework/base.html
+3
-3
djangorestframework/templatetags/optional_login.py
+32
-0
djangorestframework/templatetags/urlize_quoted_links.py
+7
-5
No files found.
djangorestframework/templates/djangorestframework/base.html
View file @
f1dc9be5
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
{% load urlize_quoted_links %}
{% load urlize_quoted_links %}
{% load add_query_param %}
{% load add_query_param %}
{% load optional_login %}
{% load static %}
{% load static %}
<html
xmlns=
"http://www.w3.org/1999/xhtml"
>
<html
xmlns=
"http://www.w3.org/1999/xhtml"
>
<head>
<head>
...
@@ -24,10 +25,9 @@
...
@@ -24,10 +25,9 @@
{% block userlinks %}
{% block userlinks %}
{% if user.is_active %}
{% if user.is_active %}
Welcome, {{ user }}.
Welcome, {{ user }}.
<a
href=
'{% url '
djangorestframework:logout
'
%}?
next=
{{
request
.
path
}}'
>
Log out
</a>
{% optional_login %}
{% else %}
{% else %}
Anonymous
{% optional_logout %}
<a
href=
'{% url '
djangorestframework:login
'
%}?
next=
{{
request
.
path
}}'
>
Log in
</a>
{% endif %}
{% endif %}
{% endblock %}
{% endblock %}
</div>
</div>
...
...
djangorestframework/templatetags/optional_login.py
0 → 100644
View file @
f1dc9be5
"""
Tags to optionally include the login and logout links, depending on if the
login and logout views are in the urlconf.
"""
from
django
import
template
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
register
=
template
.
Library
()
@register.simple_tag
(
takes_context
=
True
)
def
optional_login
(
context
):
try
:
login_url
=
reverse
(
'djangorestframework:login'
)
except
NoReverseMatch
:
return
''
request
=
context
[
'request'
]
snippet
=
"<a href='
%
s?next=
%
s'>Log in</a>"
%
(
login_url
,
request
.
path
)
return
snippet
@register.simple_tag
(
takes_context
=
True
)
def
optional_logout
(
context
):
try
:
logout_url
=
reverse
(
'djangorestframework:logout'
)
except
NoReverseMatch
:
return
''
request
=
context
[
'request'
]
snippet
=
"<a href='
%
s?next=
%
s'>Log out</a>"
%
(
logout_url
,
request
.
path
)
return
snippet
djangorestframework/templatetags/urlize_quoted_links.py
View file @
f1dc9be5
"""Adds the custom filter 'urlize_quoted_links'
"""
Adds the custom filter 'urlize_quoted_links'
This is identical to the built-in filter 'urlize' with the exception that
This is identical to the built-in filter 'urlize' with the exception that
single and double quotes are permitted as leading or trailing punctuation.
single and double quotes are permitted as leading or trailing punctuation.
Almost all of this code is copied verbatim from django.utils.html
LEADING_PUNCTUATION and TRAILING_PUNCTUATION have been modified
"""
"""
# Almost all of this code is copied verbatim from django.utils.html
# LEADING_PUNCTUATION and TRAILING_PUNCTUATION have been modified
import
re
import
re
import
string
import
string
from
django.utils.safestring
import
SafeData
,
mark_safe
from
django.utils.safestring
import
SafeData
,
mark_safe
from
django.utils.encoding
import
force_unicode
from
django.utils.encoding
import
force_unicode
from
django.utils.http
import
urlquote
from
django.utils.html
import
escape
from
django.utils.html
import
escape
from
django
import
template
from
django
import
template
# Configuration for urlize() function.
# Configuration for urlize() function.
LEADING_PUNCTUATION
=
[
'('
,
'<'
,
'<'
,
'"'
,
"'"
]
LEADING_PUNCTUATION
=
[
'('
,
'<'
,
'<'
,
'"'
,
"'"
]
TRAILING_PUNCTUATION
=
[
'.'
,
','
,
')'
,
'>'
,
'
\n
'
,
'>'
,
'"'
,
"'"
]
TRAILING_PUNCTUATION
=
[
'.'
,
','
,
')'
,
'>'
,
'
\n
'
,
'>'
,
'"'
,
"'"
]
# List of possible strings used for bullets in bulleted lists.
# List of possible strings used for bullets in bulleted lists.
...
@@ -33,6 +34,7 @@ html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<st
...
@@ -33,6 +34,7 @@ html_gunk_re = re.compile(r'(?:<br clear="all">|<i><\/i>|<b><\/b>|<em><\/em>|<st
hard_coded_bullets_re
=
re
.
compile
(
r'((?:<p>(?:
%
s).*?[a-zA-Z].*?</p>\s*)+)'
%
'|'
.
join
([
re
.
escape
(
x
)
for
x
in
DOTS
]),
re
.
DOTALL
)
hard_coded_bullets_re
=
re
.
compile
(
r'((?:<p>(?:
%
s).*?[a-zA-Z].*?</p>\s*)+)'
%
'|'
.
join
([
re
.
escape
(
x
)
for
x
in
DOTS
]),
re
.
DOTALL
)
trailing_empty_content_re
=
re
.
compile
(
r'(?:<p>(?: |\s|<br \/>)*?</p>\s*)+\Z'
)
trailing_empty_content_re
=
re
.
compile
(
r'(?:<p>(?: |\s|<br \/>)*?</p>\s*)+\Z'
)
def
urlize_quoted_links
(
text
,
trim_url_limit
=
None
,
nofollow
=
True
,
autoescape
=
True
):
def
urlize_quoted_links
(
text
,
trim_url_limit
=
None
,
nofollow
=
True
,
autoescape
=
True
):
"""
"""
Converts any URLs in text into clickable links.
Converts any URLs in text into clickable links.
...
...
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