timApp.plugin package
Contents
timApp.plugin package#
Subpackages#
Submodules#
timApp.plugin.containerLink module#
- class timApp.plugin.containerLink.PluginReg(name: str, domain: str, port: int = 5000, path: str = '/', automd: bool | None = None, regexattrs: list[str] | None = None, skip_reqs: bool = False, lazy: bool = True, can_give_task: bool = False, instance: Optional[Any] = None)[source]#
Bases:
object
- automd: bool | None = None#
- can_give_task: bool = False#
- domain: str#
- property host: str#
- instance: Optional[Any] = None#
- lazy: bool = True#
- name: str#
- path: str = '/'#
- port: int = 5000#
- regexattrs: list[str] | None = None#
- skip_reqs: bool = False#
- timApp.plugin.containerLink.call_plugin_generic(plugin: str, method: str, route: str, data: Optional[Any] = None, headers: Optional[Any] = None, params: Optional[Any] = None, read_timeout: int = 30) requests.models.Response [source]#
- timApp.plugin.containerLink.call_plugin_resource(plugin: str, filename: str, args: Optional[Any] = None) requests.models.Response [source]#
- timApp.plugin.containerLink.convert_md(plugin_data: list[dict], options: timApp.markdown.dumboclient.DumboOptions, outtype: str = 'md', plugin_opts: Optional[list[timApp.markdown.dumboclient.DumboOptions]] = None) None [source]#
- timApp.plugin.containerLink.do_request(method: str, url: str, data: Any, params: Any, headers: Any, read_timeout: int) requests.models.Response [source]#
- timApp.plugin.containerLink.get_plugin(plugin: str) timApp.plugin.containerLink.PluginReg [source]#
- timApp.plugin.containerLink.get_plugins() dict[str, timApp.plugin.containerLink.PluginReg] [source]#
- timApp.plugin.containerLink.plugin_request_fn(method: str, url: str, data: Any, params: Any, headers: Any, read_timeout: int) requests.models.Response #
- timApp.plugin.containerLink.prepare_for_dumbo_attr_list_list_recursive(regex_obj: re.Pattern, data: list) None [source]#
- timApp.plugin.containerLink.prepare_for_dumbo_attr_list_recursive(regex_obj: re.Pattern, plugin_data: dict) None [source]#
- timApp.plugin.containerLink.render_plugin(docsettings: timApp.document.docsettings.DocSettings, plugin: timApp.plugin.plugin.Plugin, output_format: timApp.plugin.pluginOutputFormat.PluginOutputFormat) str [source]#
- timApp.plugin.containerLink.render_plugin_multi(docsettings: timApp.document.docsettings.DocSettings, plugin: str, plugin_data: list[timApp.plugin.plugin.Plugin], plugin_output_format: timApp.plugin.pluginOutputFormat.PluginOutputFormat = PluginOutputFormat.HTML, default_auto_md: bool = False) str [source]#
timApp.plugin.exportdata module#
- class timApp.plugin.exportdata.ExportData(plugin: str, data: Any, save: bool)[source]#
Bases:
object
- data: Any#
- plugin: str#
- save: bool#
- class timApp.plugin.exportdata.WithExportData(exportdata: list[timApp.plugin.exportdata.ExportData])[source]#
Bases:
object
- exportdata: list[timApp.plugin.exportdata.ExportData]#
- class timApp.plugin.exportdata.WithOutData(outdata: timApp.plugin.exportdata.WithExportData)[source]#
Bases:
object
timApp.plugin.jsrunner module#
- class timApp.plugin.jsrunner.JsRunnerParams(code: str, data: Any, error_text: str = '', caller: str = '')[source]#
Bases:
object
- caller: str = ''#
- code: str#
- data: Any#
- error_text: str = ''#
- timApp.plugin.jsrunner.jsrunner_run(params: timApp.plugin.jsrunner.JsRunnerParams) tuple[Any, str] [source]#
Run JavaScript code in jsrunner.
timApp.plugin.plugin module#
- class timApp.plugin.plugin.CachedPluginFinder(doc_map: dict[int, timApp.document.docinfo.DocInfo], curr_user: timApp.document.usercontext.UserContext, view_ctx: timApp.document.viewcontext.ViewContext, cache: dict[str, timApp.plugin.plugin.Plugin | None] = <factory>)[source]#
Bases:
object
- cache: dict[str, timApp.plugin.plugin.Plugin | None]#
- curr_user: timApp.document.usercontext.UserContext#
- doc_map: dict[int, timApp.document.docinfo.DocInfo]#
- find(task_id: timApp.plugin.taskid.TaskId) timApp.plugin.plugin.Plugin | None [source]#
- view_ctx: timApp.document.viewcontext.ViewContext#
- class timApp.plugin.plugin.InlinePlugin(task_id: timApp.plugin.taskid.TaskId | None, values: dict, plugin_type: str, p_range: tuple[int, int], par: Optional[timApp.document.docparagraph.DocParagraph] = None)[source]#
Bases:
timApp.plugin.plugin.Plugin
- class timApp.plugin.plugin.Plugin(task_id: timApp.plugin.taskid.TaskId | None, values: dict, plugin_type: str, par: timApp.document.docparagraph.DocParagraph)[source]#
Bases:
object
- answer_limit_key = 'answerLimit'#
- deadline_key = 'deadline'#
- property fake_task_id#
- static from_global_par(global_par_id: timApp.document.editing.globalparid.GlobalParId, user_ctx: timApp.document.usercontext.UserContext, view_ctx: timApp.document.viewcontext.ViewContext) tuple['Plugin', timApp.document.docinfo.DocInfo] [source]#
- static from_paragraph(par: timApp.document.docparagraph.DocParagraph, view_ctx: timApp.document.viewcontext.ViewContext, user: Optional[timApp.document.usercontext.UserContext] = None)[source]#
- static from_task_id(task_id: str, user_ctx: timApp.document.usercontext.UserContext, view_ctx: timApp.document.viewcontext.ViewContext, cached_doc: Optional[timApp.document.docinfo.DocInfo] = None) tuple['Plugin', timApp.document.docinfo.DocInfo] [source]#
- get_info(users: Iterable[timApp.user.user.User], old_answers: int, look_answer: bool = False, valid: bool = True)[source]#
- is_answer_valid(old_answers: int, tim_info: dict) tuple[bool, str] [source]#
Determines whether the currently posted answer should be considered valid.
- Parameters
old_answers – The number of old answers for this task for the current user.
tim_info – The tim_info structure returned by the plugin or empty object.
- Returns
True if the answer should be considered valid, False otherwise.
- limit_defaults = {'mcq': 1, 'mcq2': 1, 'mmcq': 1, 'mmcq2': 1}#
- points_rule_key = 'pointsRule'#
- set_access_end_for_user(user: Optional[timApp.user.user.User] = None)[source]#
Changes access_end_for_user to match the end of user’s plugin access
- set_render_options(answer: tuple[timApp.answer.answer.Answer, int] | None, options: timApp.plugin.plugin.PluginRenderOptions)[source]#
- starttime_key = 'starttime'#
- to_paragraph(max_attr_width: Optional[float] = None) timApp.document.docparagraph.DocParagraph [source]#
- class timApp.plugin.plugin.PluginRenderOptions(user_ctx: timApp.document.usercontext.UserContext, do_lazy: bool, user_print: bool, preview: bool, target_format: timApp.printing.printsettings.PrintFormat, output_format: timApp.plugin.pluginOutputFormat.PluginOutputFormat, review: bool, wraptype: timApp.plugin.plugin.PluginWrap, viewmode: bool)[source]#
Bases:
object
- do_lazy: bool#
- property is_html#
- output_format: timApp.plugin.pluginOutputFormat.PluginOutputFormat#
- preview: bool#
- review: bool#
- target_format: timApp.printing.printsettings.PrintFormat#
- user_ctx: timApp.document.usercontext.UserContext#
- user_print: bool#
- viewmode: bool#
- wraptype: timApp.plugin.plugin.PluginWrap#
- class timApp.plugin.plugin.PluginWrap(value)[source]#
Bases:
enum.Enum
An enumeration.
- Full = 3#
- NoLoader = 2#
- Nothing = 1#
- exception timApp.plugin.plugin.TaskNotFoundException[source]#
Bases:
timApp.plugin.pluginexception.PluginException
The exception that is thrown when a task cannot be found.
- timApp.plugin.plugin.expand_macros_for_plugin(par: timApp.document.docparagraph.DocParagraph, macros, env: timApp.markdown.autocounters.TimSandboxedEnvironment)[source]#
- timApp.plugin.plugin.find_inline_plugins(block: timApp.document.docparagraph.DocParagraph, macroinfo: timApp.document.macroinfo.MacroInfo) Generator[tuple[timApp.plugin.taskid.UnvalidatedTaskId, str | None, tuple[int, int], str], None, None] [source]#
- timApp.plugin.plugin.find_inline_plugins_from_str(md) Generator[tuple[timApp.plugin.taskid.UnvalidatedTaskId, str | None, tuple[int, int], str], None, None] [source]#
- timApp.plugin.plugin.find_plugin_from_document(d: timApp.document.document.Document, task_id: timApp.plugin.taskid.TaskId, u: timApp.document.usercontext.UserContext, view_ctx: timApp.document.viewcontext.ViewContext) timApp.plugin.plugin.Plugin [source]#
- timApp.plugin.plugin.find_task_ids(blocks: list[timApp.document.docparagraph.DocParagraph], view_ctx: timApp.document.viewcontext.ViewContext, user_ctx: timApp.document.usercontext.UserContext, check_access=True) tuple[list[timApp.plugin.taskid.TaskId], int, list[timApp.plugin.taskid.TaskId]] [source]#
Finds all task plugins from the given list of paragraphs and returns their ids. :param user_ctx:
- timApp.plugin.plugin.get_num_value(values, key, default=None)[source]#
Gets the value either from key or -key :param values: dict where to find :param key: key to use :param default: value returned if key not found from either of key or -key :return: value for key, -key or default
- timApp.plugin.plugin.get_simple_hash_from_par_and_user(block: timApp.document.docparagraph.DocParagraph, uc: timApp.document.usercontext.UserContext | None) int [source]#
Get simple int hash from TIM’s document block and user.
- Parameters
block – TIM’s document block
uc – The user context.
- Returns
simple hash that can be used for example as a seed for random number generator
- timApp.plugin.plugin.get_value(values, key, default=None)[source]#
Gets the value either from key or -key :param values: dict where to find :param key: key to use :param default: value returned if key not found from either of key or -key :return: value for key, -key or default
- timApp.plugin.plugin.load_markup_from_yaml(yaml_str: str, global_attrs: dict[str, str], plugin_type: str)[source]#
- timApp.plugin.plugin.maybe_get_plugin_from_par(p: timApp.document.docparagraph.DocParagraph, task_id: timApp.plugin.taskid.TaskId, u: timApp.document.usercontext.UserContext, view_ctx: timApp.document.viewcontext.ViewContext, match_exact_document: bool = False) timApp.plugin.plugin.Plugin | None [source]#
- timApp.plugin.plugin.parse_plugin_values(par: timApp.document.docparagraph.DocParagraph, global_attrs: dict[str, str], macroinfo: timApp.document.macroinfo.MacroInfo) dict [source]#
- timApp.plugin.plugin.parse_plugin_values_macros(par: timApp.document.docparagraph.DocParagraph, global_attrs: dict[str, str], macros: dict[str, object], env: timApp.markdown.autocounters.TimSandboxedEnvironment) dict [source]#
Parses the markup values for a plugin paragraph, taking document attributes and macros into account.
- Parameters
par – The plugin paragraph.
global_attrs – Global (Document) attributes.
macros – Dict of macros
env – macro environment
- Returns
The parsed markup values.
- timApp.plugin.plugin.render_template_string2(source, **context)[source]#
Renders a template from the given template source string with the given context. Template variables will be autoescaped.
- Parameters
source – the source code of the template to be rendered
context – the variables that should be available in the context of the template.
- timApp.plugin.plugin.render_template_string3(rtemplate, **context)[source]#
Renders a template from the given template source string with the given context. Template variables will be autoescaped.
- Parameters
rtemplate – ready made render template
context – the variables that should be available in the context of the template.
timApp.plugin.pluginControl module#
Functions for dealing with plugin paragraphs.
- class timApp.plugin.pluginControl.PluginPlacement(*, plugins: dict[tuple[int, int], timApp.plugin.plugin.Plugin], errors: dict[tuple[int, int], tuple[str, str]], block: timApp.document.docparagraph.DocParagraph, expanded_md: str, is_block_plugin: bool, output_format: timApp.plugin.pluginOutputFormat.PluginOutputFormat)[source]#
Bases:
object
Represents the position(s) of plugin(s) in a block.
- Can be either:
a block-level (traditional) plugin, or
one or more inlineplugins.
In case of a block-level plugin, the range spans the entire block’s expanded markdown.
- block: timApp.document.docparagraph.DocParagraph#
The block where the plugins are.
- errors: dict[tuple[int, int], tuple[str, str]]#
- expanded_md: str#
Expanded markdown of the containing block.
- static from_par(block: timApp.document.docparagraph.DocParagraph, load_states: bool, macroinfo: timApp.document.macroinfo.MacroInfo, plugin_opts: timApp.plugin.plugin.PluginRenderOptions, user_ctx: timApp.document.usercontext.UserContext, view_ctx: timApp.document.viewcontext.ViewContext, settings: timApp.document.docsettings.DocSettings, answer_map: dict[str, tuple[timApp.answer.answer.Answer, int]], custom_answer: timApp.answer.answer.Answer | None, output_format: timApp.plugin.pluginOutputFormat.PluginOutputFormat) Optional[timApp.plugin.pluginControl.PluginPlacement] [source]#
- get_block_output(extract_plugins: bool = False) tuple[str, dict[str, str]] [source]#
TODO: this did not help very much if self.is_block_plugin:
idx = next(iter(self.plugins)) p = self.plugins[idx] return p.get_final_output().strip()
- is_block_plugin: bool#
Whether this is a block-level plugin.
- output_format: timApp.plugin.pluginOutputFormat.PluginOutputFormat#
- plugins: dict[tuple[int, int], timApp.plugin.plugin.Plugin]#
- class timApp.plugin.pluginControl.PluginifyResult(pars: list[timApp.document.docparagraph.DocParagraph], js_paths: list[str], css_paths: list[str], custom_answer_plugin: timApp.plugin.plugin.Plugin | None, all_plugins: list[timApp.plugin.plugin.Plugin], has_errors: bool)[source]#
Bases:
object
- all_plugins: list[timApp.plugin.plugin.Plugin]#
- css_paths: list[str]#
- custom_answer_plugin: timApp.plugin.plugin.Plugin | None#
- has_errors: bool#
- js_paths: list[str]#
- pars: list[timApp.document.docparagraph.DocParagraph]#
- timApp.plugin.pluginControl.check_task_access(errs: dict[tuple[int, int], tuple[str, str]], p_range: tuple[int, int], plugin_name: str, tid: timApp.plugin.taskid.TaskId)[source]#
- timApp.plugin.pluginControl.get_error_plugin(plugin_name, message, response=None, plugin_output_format: timApp.plugin.pluginOutputFormat.PluginOutputFormat = PluginOutputFormat.HTML, inline=False)[source]#
- Parameters
response –
- timApp.plugin.pluginControl.plugin_deps(p: dict) tuple[list[str], list[str]] [source]#
- Parameters
p – is json of plugin requirements of the form: {“js”: [“js.js”], “css”:[“css.css”]}
- timApp.plugin.pluginControl.pluginify(doc: timApp.document.document.Document, pars: list[timApp.document.docparagraph.DocParagraph], user_ctx: timApp.document.usercontext.UserContext, view_ctx: timApp.document.viewcontext.ViewContext, custom_answer: Optional[timApp.answer.answer.Answer] = None, task_id: Optional[timApp.plugin.taskid.TaskId] = None, sanitize=True, do_lazy=False, load_states=True, review=False, pluginwrap=PluginWrap.Full, output_format: timApp.plugin.pluginOutputFormat.PluginOutputFormat = PluginOutputFormat.HTML, user_print: bool = False, target_format: timApp.printing.printsettings.PrintFormat = PrintFormat.LATEX) timApp.plugin.pluginControl.PluginifyResult [source]#
“Pluginifies” the specified DocParagraphs by calling the corresponding plugin route for each plugin paragraph.
- Parameters
view_ctx – The view context.
doc – Document / DocumentVersion object.
pars – A list of DocParagraphs to be processed.
user_ctx – The user context.
custom_answer – Optional answer that will used as the state for the plugin instead of answer database.
task_id – Optional taskId for plugin which will load it’s current state (returned as custom_answer_plugin) If custom_answer or task_id is specified, the expression len(blocks) MUST be 1.
sanitize – Whether the blocks should be sanitized before processing.
do_lazy – Whether to use lazy versions of the plugins.
output_format – Desired output format (html/md) for plugins
user_print – Whether the plugins should output the original values or user’s input (when exporting markdown).
target_format – for MD-print what exact format to use
- Returns
Processed HTML blocks along with JavaScript and CSS stylesheet dependencies.
timApp.plugin.pluginOutputFormat module#
timApp.plugin.pluginexception module#
timApp.plugin.plugintype module#
- class timApp.plugin.plugintype.PluginType(**kwargs)[source]#
Bases:
sqlalchemy.ext.declarative.api.Model
,timApp.plugin.plugintype.PluginTypeBase
- id#
- static resolve(p_type: str) timApp.plugin.plugintype.PluginType [source]#
- type#
- class timApp.plugin.plugintype.PluginTypeLazy(type: str)[source]#
Bases:
timApp.plugin.plugintype.PluginTypeBase
- resolve() timApp.plugin.plugintype.PluginType [source]#
- type: str#
timApp.plugin.routes module#
timApp.plugin.save_plugin module#
- timApp.plugin.save_plugin.save_plugin(p: timApp.plugin.plugin.Plugin, max_attr_width: Optional[float] = None) None [source]#
timApp.plugin.taskid module#
- class timApp.plugin.taskid.TaskId(doc_id: int | None, task_name: str, block_id_hint: str | None = None, field: str | None = None, plugin_type: str | None = None, access_specifier: timApp.plugin.taskid.TaskIdAccess | None = None)[source]#
Bases:
object
- access_specifier: timApp.plugin.taskid.TaskIdAccess | None = None#
- block_id_hint: str | None = None#
- doc_id: int | None#
- property doc_task#
- property doc_task_with_field#
- property extended#
- property extended_or_doc_task#
- field: str | None = None#
- property is_global#
- property is_points_ref#
- static parse(s: str, *, require_doc_id=True, allow_block_hint=True, allow_custom_field=False, allow_type=True) timApp.plugin.taskid.TaskId [source]#
- plugin_type: str | None = None#
- task_name: str#
- update_doc_id_from_block(par: timApp.document.docparagraph.DocParagraph)[source]#