mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 11:04:02 +03:00
Login/Logout and FlyWheel API link in HTML emitter - Add templates, quote next value, only use login/logout if settings.LOGIN_URL and settings.LOGOUT_URL are in urlconf
This commit is contained in:
parent
216baa551f
commit
e9168b508b
7
examples/templates/base.html
Normal file
7
examples/templates/base.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
26
examples/templates/registration/login.html
Normal file
26
examples/templates/registration/login.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if form.errors %}
|
||||
<p>Your username and password didn't match. Please try again.</p>
|
||||
{% endif %}
|
||||
|
||||
<form method="post" action="{% url django.contrib.auth.views.login %}">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
<tr>
|
||||
<td>{{ form.username.label_tag }}</td>
|
||||
<td>{{ form.username }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ form.password.label_tag }}</td>
|
||||
<td>{{ form.password }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<input type="submit" value="login" />
|
||||
<input type="hidden" name="next" value="{{ next }}" />
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
|
@ -3,8 +3,9 @@ from django.template import RequestContext, loader
|
|||
from django import forms
|
||||
|
||||
from flywheel.response import NoContent
|
||||
from flywheel.utils import dict2xml, url_resolves
|
||||
|
||||
from utils import dict2xml, url_resolves
|
||||
from urllib import quote_plus
|
||||
import string
|
||||
try:
|
||||
import json
|
||||
|
@ -121,8 +122,8 @@ class DocumentingTemplateEmitter(BaseEmitter):
|
|||
form_instance = self._get_form_instance(self.resource)
|
||||
|
||||
if url_resolves(settings.LOGIN_URL) and url_resolves(settings.LOGOUT_URL):
|
||||
login_url = "%s?next=%s" % (settings.LOGIN_URL, self.resource.request.path)
|
||||
logout_url = "%s?next=%s" % (settings.LOGOUT_URL, self.resource.request.path)
|
||||
login_url = "%s?next=%s" % (settings.LOGIN_URL, quote_plus(self.resource.request.path))
|
||||
logout_url = "%s?next=%s" % (settings.LOGOUT_URL, quote_plus(self.resource.request.path))
|
||||
else:
|
||||
login_url = None
|
||||
logout_url = None
|
||||
|
|
|
@ -36,11 +36,11 @@
|
|||
|
||||
{% if 'GET' in resource.allowed_methods %}
|
||||
<div class='action'>
|
||||
<a href='{{ request.path }}'>GET</a>
|
||||
<a href='{{ request.path }}' rel="nofollow">GET</a>
|
||||
<ul class="accepttypes">
|
||||
{% for media_type in resource.emitted_media_types %}
|
||||
{% with resource.ACCEPT_QUERY_PARAM|add:"="|add:media_type as param %}
|
||||
<li>[<a href='{{ request.path|add_query_param:param }}'>{{ media_type }}</a>]</li>
|
||||
<li>[<a href='{{ request.path|add_query_param:param }} rel="nofollow"'>{{ media_type }}</a>]</li>
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -33,7 +33,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)
|
||||
trailing_empty_content_re = re.compile(r'(?:<p>(?: |\s|<br \/>)*?</p>\s*)+\Z')
|
||||
|
||||
def urlize_quoted_links(text, trim_url_limit=None, nofollow=False, autoescape=True):
|
||||
def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=True):
|
||||
"""
|
||||
Converts any URLs in text into clickable links.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user