本文整理汇总了Python中rest_framework.utils.formatting.markup_description函数的典型用法代码示例。如果您正苦于以下问题:Python markup_description函数的具体用法?Python markup_description怎么用?Python markup_description使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了markup_description函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_view_doc
def get_view_doc(view, html=True):
"""
Build view documentation. Return in html format.
If you want in markdown format, use html=False
"""
try:
description = view.__doc__ or ''
description = formatting.dedent(smart_text(description))
# include filters in description
filter_fields = get_filter_fields(view)
if filter_fields:
filter_doc = ['\n\n\n## Filters', '']
for f in filter_fields:
filter_doc.append('- `%s`' % f)
description += '\n'.join(filter_doc)
# replace {api_url} by current base url
api_url = "/api"
description = description.replace('{api_url}', api_url)
if html:
description = formatting.markup_description(description)
return description
except:
import traceback
traceback.print_exc()
raise
示例2: get_view_description
def get_view_description(view_cls, html=False):
"""
Given a view class, return a textual description to represent the view.
This name is used in the browsable API, and in OPTIONS responses.
This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
"""
description = view_cls.__doc__ or ''
description = formatting.dedent(smart_text(description))
if hasattr(getattr(view_cls, 'serializer_class', 'None'), 'Meta'):
doc_url = get_doc_url(
'api',
'{0}s'.format(
view_cls.serializer_class.Meta.model.__name__.lower()
)
)
else:
doc_url = get_doc_url('api')
if html:
return (
formatting.markup_description(description) +
mark_safe(DOC_TEXT.format(doc_url))
)
return description
示例3: get_view_description
def get_view_description(self, html=False):
description = self.__doc__ or """
Returns a nested list of objects that would be also be deleted when
this object is deleted.
"""
description = formatting.dedent(description)
if html:
return formatting.markup_description(description)
return description
示例4: get_view_description
def get_view_description(view_cls, html=False):
"""
Given a view class, return a textual description to represent the view.
This name is used in the browsable API, and in OPTIONS responses.
This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
"""
description = view_cls.__doc__ or ''
description = formatting.dedent(smart_text(description))
if html:
return formatting.markup_description(description)
return description
示例5: format_docstring
def format_docstring(self, view, method, docstring):
macros = settings.BROWSABLE_DOCUMENT_MACROS
if view:
macros['FILTERS'] = get_filters(view)
if '%(SERIALIZER)s' in docstring:
macros['SERIALIZER'] = get_serializer(view, include_read_only=True)
if '%(WRITABLE_SERIALIZER)s' in docstring:
macros['WRITABLE_SERIALIZER'] = get_serializer(view, include_read_only=False)
string = formatting.dedent(docstring)
formatted = string % macros
formatted = self.substitute_urls(view, method, formatted)
string = smart_text(formatted)
return formatting.markup_description(string)
示例6: get_view_description
def get_view_description(cls, html=False):
description = ''
if getattr(cls, 'get_description', None):
cache_key = cls.__name__
cached_description = cache.get(cache_key)
if not cached_description:
description = cls.get_description()
description = formatting.dedent(smart_text(description))
# Cache for 1 hour (if we update description, it will take 1 hour to show)
cache.set(cache_key, description, 60*60)
else:
description = cached_description
if html:
return formatting.markup_description(description)
return description
示例7: get_view_description
def get_view_description(view_cls, html=False):
from django_markwhat.templatetags.markup import restructuredtext
description = view_cls.__doc__ or ''
description = formatting.dedent(smart_text(description))
if html:
rst_doc = getattr(view_cls, 'rst_doc', None)
if rst_doc:
if isinstance(rst_doc, str):
path = os.path.dirname(sys.modules[view_cls.__module__].__file__)
path = os.path.join(path, rst_doc)
with open(path) as rst:
return restructuredtext(rst.read())
return restructuredtext(description)
return formatting.markup_description(description)
return description
示例8: get_view_description
def get_view_description(view, html=False):
"""
Given a view class, return a textual description to represent the view.
This name is used in the browsable API, and in OPTIONS responses.
This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
"""
# Description may be set by some Views, such as a ViewSet.
description = getattr(view, 'description', None)
if description is None:
description = view.__class__.__doc__ or ''
description = formatting.dedent(smart_text(description))
if html:
return formatting.markup_description(description)
return description
示例9: format_docstring
def format_docstring(self, view, method, docstring):
macros = settings.BROWSABLE_DOCUMENT_MACROS
if view:
macros['FILTERS'] = get_filters(view)
if 'list' == method:
ordering_field = get_ordering_field(view, method)
if ordering_field:
ordering_string = ORDERING_STRING + " %s ." % ordering_field
macros['FILTERS'] += ordering_string
if '%(SERIALIZER)s' in docstring:
macros['SERIALIZER'] = get_serializer(view, include_read_only=True)
if '%(WRITABLE_SERIALIZER)s' in docstring:
macros['WRITABLE_SERIALIZER'] = get_serializer(view, include_read_only=False)
if hasattr(view, 'docstring_macros'):
macros.update(view.docstring_macros)
string = formatting.dedent(docstring)
formatted = string % macros
formatted = self.substitute_urls(view, method, formatted)
string = smart_text(formatted)
return formatting.markup_description(string)
示例10: markdown
def markdown(value):
return markup_description(value)
示例11: get_view_description
def get_view_description(cls, html=False):
description = cls.__doc__ or ''
description = formatting.dedent(smart_text(description))
if html:
return formatting.markup_description(description)
return description
示例12: format_docstring
def format_docstring(self, docstring):
formatted = docstring % settings.BROWSABLE_DOCUMENT_MACROS
string = formatting.dedent(smart_text(formatted))
return formatting.markup_description(string)