mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-16 07:02:10 +03:00
Merge 0ebbfbff45
into f74185b6dd
This commit is contained in:
commit
2195c9fb4d
|
@ -263,64 +263,9 @@ def data(value):
|
|||
|
||||
|
||||
@register.filter
|
||||
def schema_links(section, sec_key=None):
|
||||
"""
|
||||
Recursively find every link in a schema, even nested.
|
||||
"""
|
||||
NESTED_FORMAT = '%s > %s' # this format is used in docs/js/api.js:normalizeKeys
|
||||
links = section.links
|
||||
if section.data:
|
||||
data = section.data.items()
|
||||
for sub_section_key, sub_section in data:
|
||||
new_links = schema_links(sub_section, sec_key=sub_section_key)
|
||||
links.update(new_links)
|
||||
|
||||
if sec_key is not None:
|
||||
new_links = {}
|
||||
for link_key, link in links.items():
|
||||
new_key = NESTED_FORMAT % (sec_key, link_key)
|
||||
new_links.update({new_key: link})
|
||||
return new_links
|
||||
|
||||
return links
|
||||
|
||||
|
||||
@register.filter
|
||||
def add_nested_class(value):
|
||||
if isinstance(value, dict):
|
||||
return 'class=nested'
|
||||
if isinstance(value, list) and any(isinstance(item, (list, dict)) for item in value):
|
||||
return 'class=nested'
|
||||
return ''
|
||||
|
||||
|
||||
# Bunch of stuff cloned from urlize
|
||||
TRAILING_PUNCTUATION = ['.', ',', ':', ';', '.)', '"', "']", "'}", "'"]
|
||||
WRAPPING_PUNCTUATION = [('(', ')'), ('<', '>'), ('[', ']'), ('<', '>'),
|
||||
('"', '"'), ("'", "'")]
|
||||
word_split_re = re.compile(r'(\s+)')
|
||||
simple_url_re = re.compile(r'^https?://\[?\w', re.IGNORECASE)
|
||||
simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net|org)$', re.IGNORECASE)
|
||||
simple_email_re = re.compile(r'^\S+@\S+\.\S+$')
|
||||
|
||||
|
||||
def smart_urlquote_wrapper(matched_url):
|
||||
"""
|
||||
Simple wrapper for smart_urlquote. ValueError("Invalid IPv6 URL") can
|
||||
be raised here, see issue #1386
|
||||
"""
|
||||
try:
|
||||
return smart_urlquote(matched_url)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
@register.filter
|
||||
def break_long_headers(header):
|
||||
"""
|
||||
Breaks headers longer than 160 characters (~page length)
|
||||
when possible (are comma separated)
|
||||
"""
|
||||
if len(header) > 160 and ',' in header:
|
||||
header = mark_safe('<br> ' + ', <br>'.join(escape(header).split(',')))
|
||||
return header
|
||||
def schema_links(section, sec_type):
|
||||
return [
|
||||
(key, link)
|
||||
for key, link in section.data.items()
|
||||
if link.action == sec_type
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue
Block a user