Views

class rstview.views.RSTFileView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

Parse and render a reStructuredText file from given path.

Example

from django.conf.urls import url

from rstview.views import RSTFileView

urlpatterns = [
    url(r'^basic/$', RSTFileView.as_view(
        doc_path="/home/foo/basic/input.rst",
        doc_title="Basic sample"
    ), name='sample-view-basic'),
]
template_name

string – Template file to render. Default to rstview/fileview.html.

doc_title

string – Optionnal document title. Default to None.

doc_path

string – Path to a reStructuredText file, it is recommended you use an absolute path.

This is the only required argument you must allways define.

Default to None.

doc_parser_class

object – A parser class from rstview.parser. Default is rstview.parser.RstExtendedRenderer.

doc_parser_silent

bool – Enable to override default silent mode behavior. Default value is the same as settings.RSTVIEW_PARSER_SILENT.

doc_parser_bodyonly

bool – If True, parser will only return the rendered content, this is the default behavior. Default is False.

doc_parser_configuration

string – A registered configuration name. Default to default.

doc_parser_class

alias of RstExtendedRenderer

get_context_data(**kwargs)[source]

Expand template context with some document related variables:

doc_title
The given document title.
doc_source
Source from given filepath.
doc_html
Rendered source from parser.
doc_parser_configuration
Used configuration name.
Returns:Context variables expanded with variables.
Return type:dict
get_document_title()[source]

Get document title from RSTFileView.doc_title

Returns:Document title.
Return type:string
get_parser_opts()[source]

Return parser options.

Returns:Options to give to parser.SourceParser:
  • setting_key: from class attribute RSTFileView.doc_parser_configuration;
  • silent: from class attribute RSTFileView.doc_parser_silent;
  • body_only: from class attribute RSTFileView.doc_parser_bodyonly;
Return type:dict
get_source()[source]

Return file source from given path in RSTFileView.doc_path.

Raises:rstview.views.RstViewInvalidException – If RSTFileView.doc_path is not defined.
Returns:File content.
Return type:string
render_source(source)[source]

Parse given source and return result as safe for django template.

Use RSTFileView.get_parser_opts() to get and give options to parser.

Parameters:source (string) – reStructuredText markup to parse.
Returns:Rendered source from parser.
Return type:string
template_name = 'rstview/fileview.html'

Default template

exception rstview.views.RstViewInvalidException[source]

Bases: exceptions.Exception

Exception to be raised when RSTFileView usage is incorrect.