shoop.xtheme package¶
Subpackages¶
Submodules¶
shoop.xtheme.editing module¶
-
shoop.xtheme.editing.
could_edit
(request)[source]¶ Return true if the context of the given request would allow Xtheme editing.
Parameters: request (django.http.HttpRequest) – HTTP request Returns: Would allow editing? Return type: bool
-
shoop.xtheme.editing.
is_edit_mode
(request)[source]¶ Return true if the given request has xtheme editing enabled.
Parameters: request (django.http.HttpRequest) – HTTP request Returns: In edit mode? Return type: bool
-
shoop.xtheme.editing.
set_edit_mode
(request, flag)[source]¶ Enable or disable edit mode for the request.
Parameters: - request (django.http.HttpRequest) – HTTP request
- flag (bool) – Enable flag
-
shoop.xtheme.editing.
may_inject
(context)[source]¶ Figure out if we may inject Xtheme editing into this view.
The requirements are that there is a CBV
view
object in the context, and thatview
object does not explicitly opt-out of editing withxtheme_injection = False
Parameters: context (jinja2.runtime.Context) – Jinja rendering context Returns: Permission bool Return type: bool
shoop.xtheme.engine module¶
-
class
shoop.xtheme.engine.
XthemeTemplate
[source]¶ Bases:
jinja2.environment.Template
A subclass of Jinja templates with additional post-processing magic.
-
class
shoop.xtheme.engine.
XthemeEnvironment
(block_start_string='{%', block_end_string='%}', variable_start_string='{{', variable_end_string='}}', comment_start_string='{#', comment_end_string='#}', line_statement_prefix=None, line_comment_prefix=None, trim_blocks=False, lstrip_blocks=False, newline_sequence='n', keep_trailing_newline=False, extensions=(), optimized=True, undefined=<class 'jinja2.runtime.Undefined'>, finalize=None, autoescape=False, loader=None, cache_size=400, auto_reload=True, bytecode_cache=None)[source]¶ Bases:
jinja2.environment.Environment
Overrides the usual template class and allows dynamic switching of Xthemes.
Enable by adding
"environment": "shoop.xtheme.engine.XthemeEnvironment"
in yourTEMPLATES
settings.-
template_class
¶ alias of
XthemeTemplate
-
get_template
(name, parent=None, globals=None)[source]¶ Load a template from the loader. If a loader is configured this method asks the loader for the template and returns a
Template
.Parameters: - name (str) – Template name.
- parent (str|None) – If the
parent
parameter is notNone
,join_path
is called to get the real template name before loading. - globals (dict|None) – The
globals
parameter can be used to provide template wide globals. These variables are available in the context at render time.
Returns: Template object
Return type:
-
get_or_select_template
(template_name_or_list, parent=None, globals=None)[source]¶ Does a typecheck and dispatches to
select_template
orget_template
.Parameters: - template_name_or_list (str|Iterable[str]) – Template name or list
- parent (str|None) – If the
parent
parameter is notNone
,join_path
is called to get the real template name before loading. - globals – The
globals
parameter can be used to provide template wide globals. These variables are available in the context at render time.
Returns: Template object
Return type:
-
-
shoop.xtheme.engine.
concat
()¶ S.join(iterable) -> str
Return a string which is the concatenation of the strings in the iterable. The separator between elements is S.
shoop.xtheme.forms module¶
-
class
shoop.xtheme.forms.
GenericThemeForm
(**kwargs)[source]¶ Bases:
django.forms.models.ModelForm
A generic form for Xthemes; populates itself based on
fields
in the theme class.-
GenericThemeForm.
base_fields
= OrderedDict()¶
-
GenericThemeForm.
declared_fields
= OrderedDict()¶
-
GenericThemeForm.
media
¶
-
GenericThemeForm.
save
(commit=True)[source]¶ Save theme settings into the ThemeSettings instance
Parameters: commit (bool) – Commit flag. Ignored, but there for compatibility with the superclass. Returns: The now saved ThemeSettings
instanceReturn type: shoop.xtheme.models.ThemeSettings
-
shoop.xtheme.layout module¶
-
class
shoop.xtheme.layout.
LayoutCell
(plugin_identifier, config=None, sizes=None)[source]¶ Bases:
object
A single cell in a layout. Maps to Bootstrap’s
col-XX-XX
classes.Initialize a layout cell with a given plugin, config and sizing configuration.
Parameters: - plugin_identifier (str) – Plugin identifier string
- config (dict|None) – Config dict
- sizes (dict|None) – Size dict
-
plugin_class
¶ Get the actual plugin class for this cell, or None if the plugin class isn’t available.
Returns: Plugin or None. Return type: Plugin|None
-
plugin_name
¶ Get the name of the plugin in this cell for display purposes.
Returns: Plugin name string Return type: str
-
instantiate_plugin
()[source]¶ Instantiate the plugin with the current config.
Returns: Instantiated plugin (if a class is available) Return type: Plugin|None
-
render
(context)[source]¶ Return the plugin’s rendered contents.
Parameters: context (jinja2.runtime.Context) – Jinja2 rendering context. Returns: string of content Return type: str
-
classmethod
unserialize
(data)[source]¶ Unserialize a dict of layout cell data into a new cell.
Parameters: data (dict) – Layout cell data dict Returns: New cell Return type: LayoutCell
-
class
shoop.xtheme.layout.
LayoutRow
(cells=None)[source]¶ Bases:
object
A single row in a layout. Maps to Bootstrap’s
row
class.Parameters: cells – Optional iterable of LayoutCells to populate this LayoutRow with. -
classmethod
unserialize
(data)[source]¶ Unserialize a dict of layout row data into a new row, along with all cell children.
Parameters: data (dict) – Layout row data dict Returns: New row Return type: LayoutRow
-
add_cell
(sizes=None)[source]¶ Add an empty cell to this row. Used by the editor API.
Parameters: sizes (dict|None) – An optional size dict, see LayoutCell
Returns: The new layout cell Return type: LayoutCell
-
classmethod
-
class
shoop.xtheme.layout.
Layout
(placeholder_name, rows=None)[source]¶ Bases:
object
The layout (row, cell and plugin configuration) for a single placeholder.
Parameters: - placeholder_name (str|None) – The name of the placeholder. Could be None.
- rows (Iterable[LayoutRow]|None) – Optional iterable of LayoutRows to populate this Layout with.
-
row_class
= 'row'¶
-
cell_class_template
= 'col-%(breakpoint)s-%(width)s'¶
-
hide_cell_class_template
= 'hidden-%(breakpoint)s'¶
-
classmethod
unserialize
(data, placeholder_name=None)[source]¶ Unserialize a dict of layout data into a new layout, with all rows and cells.
Parameters: Returns: New layout
Return type:
-
begin_row
()[source]¶ Begin a new row in the layout.
This is internally used by
LayoutPartExtension
, but could just as well be used to programmatically create layouts for whichever purpose.Returns: The newly created row Return type: LayoutRow
-
begin_column
(sizes=None)[source]¶ Begin a new column (cell) in the layout, in the last row.
If no rows exist, one is implicitly created, for your convenience. The newly created cell has no plugin or configuration.
This is internally used by
LayoutPartExtension
, but could just as well be used to programmatically create layouts for whichever purpose.Parameters: sizes – The size dictionary to pass to LayoutCell
.Returns: The newly created cell Return type: LayoutCell
-
add_plugin
(plugin_identifier, config)[source]¶ Configure a plugin in the last row and cell of the layout.
If no rows or cells exist, one row and one cell is implicitly created.
This is internally used by
LayoutPartExtension
, but could just as well be used to programmatically create layouts for whichever purpose.Parameters: Returns: The configured cell
Return type:
-
get_cell
(x, y)[source]¶ Get a layout cell indicated by the given (zero-based) coordinates.
If the coordinates are out of range, returns None.
Parameters: Returns: Layout cell
Return type: LayoutCell|None
-
insert_row
(y=None)[source]¶ Insert a new row at the given zero-based row and return it.
If
y
is None, the row in inserted at the end.Parameters: y (int) – Y coordinate Returns: The new layout row Return type: LayoutRow
shoop.xtheme.models module¶
-
class
shoop.xtheme.models.
SavedViewConfigQuerySet
(model=None, query=None, using=None, hints=None)[source]¶ Bases:
django.db.models.query.QuerySet
-
appropriate
(theme, view_name, draft)[source]¶ Get an “appropriate”
SavedViewConfig
for the parameters given.When draft mode is off:
- A PUBLIC SavedViewConfig is returned, or a new one in CURRENT_DRAFT status.
When draft mode is on:
- A CURRENT_DRAFT SavedViewConfig is returned, if one exists.
- If a PUBLIC SavedViewConfig exists, its data is copied into a new, unsaved CURRENT_DRAFT SavedViewConfig.
Parameters: - theme (shoop.xtheme.Theme) – Theme instance
- view_name (str) – View name string
- draft (bool) – Draft mode flag
Returns: SavedViewConfig (possibly not saved)
Return type:
-
-
class
shoop.xtheme.models.
SavedViewConfigStatus
[source]¶ Bases:
enumfields.enums.Enum
Stati for SavedViewConfigs.
The lifecycle for SavedViewConfigs (SVCs) for a given (theme, view) pair is as follows:
- Initially, there’s zero SVCs.
- When a placeholder layout is saved in edit mode, an SVC in the CURRENT_DRAFT status is saved.
- When an SVC in CURRENT_DRAFT status is published, all other SVCs for the theme/view pair are “demoted” to being OLD_VERSIONs and the CURRENT_DRAFT SVC is promoted to being the PUBLIC one (and there should always be zero or one PUBLIC SavedViewConfigs per (theme, view) pair).
- When an SVC in CURRENT_DRAFT status is reverted, it is simply deleted.
- When an SVC has been published and edit mode is entered again, the current PUBLIC SVC is copied into a new CURRENT_DRAFT version.
-
class
shoop.xtheme.models.
SavedViewConfig
(id, theme_identifier, view_name, created_on, status, _data)[source]¶ Bases:
django.db.models.base.Model
-
status
¶ A placeholder class that provides a way to set the attribute on the model.
-
objects
= <django.db.models.manager.ManagerFromSavedViewConfigQuerySet object>¶
-
draft
¶
-
exception
DoesNotExist
¶
-
exception
SavedViewConfig.
MultipleObjectsReturned
¶
-
SavedViewConfig.
get_next_by_created_on
(*moreargs, **morekwargs)¶
-
SavedViewConfig.
get_previous_by_created_on
(*moreargs, **morekwargs)¶
-
SavedViewConfig.
get_status_display
(*moreargs, **morekwargs)¶
-
-
class
shoop.xtheme.models.
ThemeSettings
(id, theme_identifier, active, data)[source]¶ Bases:
django.db.models.base.Model
-
data
¶ A placeholder class that provides a way to set the attribute on the model.
-
exception
DoesNotExist
¶
-
exception
ThemeSettings.
MultipleObjectsReturned
¶
-
ThemeSettings.
objects
= <django.db.models.manager.Manager object>¶
-
shoop.xtheme.parsing module¶
-
exception
shoop.xtheme.parsing.
Unflattenable
[source]¶ Bases:
Exception
Exception raised when a node list can’t be flattened into a constant.
-
exception
shoop.xtheme.parsing.
NonConstant
[source]¶ Bases:
ValueError
Exception raised when something expected to be constant... is not.
-
exception
shoop.xtheme.parsing.
NestingError
[source]¶ Bases:
ValueError
Exception raised when a template’s placeholder/column/row/plugin hierarchy is out of whack.
-
shoop.xtheme.parsing.
flatten_const_node_list
(environment, node_list)[source]¶ Try to flatten the given node list into a single string.
Parameters: - environment (jinja2.environment.Environment) – Jinja2 environment
- node_list (list[jinja2.nodes.Node]) – List of nodes
Returns: String of content
Return type: Raises Unflattenable: Raised when the node list can’t be flattened into a constant
-
shoop.xtheme.parsing.
parse_constantlike
(environment, parser)[source]¶ Parse the next expression as a “constantlike” expression.
Expression trees that fold into constants are constantlike, as are bare variable names.
Parameters: - environment (jinja2.environment.Environment) – Jinja2 environment
- parser (jinja2.parser.Parser) – Template parser
Returns: constant value of any type
Return type:
-
shoop.xtheme.parsing.
noop_node
(lineno)[source]¶ Return a no-op node (compiled into a single
0
).Parameters: lineno (int) – Line number for the node Returns: Node Return type: jinja2.nodes.ExprStmt
-
class
shoop.xtheme.parsing.
PlaceholderExtension
(environment)[source]¶ Bases:
shoop.xtheme.parsing._PlaceholderManagingExtension
PlaceholderExtension
manages{% placeholder <NAME> %}
...{% endplaceholder %}
.- The
name
can be any Jinja2 expression that can be folded into a constant, with the addition of bare variable names such asname
meaning the same as"name"
. This makes it slightly easier to write templates. - The body of this block is actually discarded; only the inner
column
,row
andplugin
directives have any meaning. (A parser-timeLayout
object is created and populated during parsing of this block.)
-
parse
(parser)[source]¶ Parse a placeholder!
Parameters: parser (jinja2.parser.Parser) – Template parser Returns: Output node for rendering a placeholder. Return type: jinja2.nodes.Output
-
identifier
= 'shoop.xtheme.parsing.PlaceholderExtension'¶
- The
-
class
shoop.xtheme.parsing.
LayoutPartExtension
(environment)[source]¶ Bases:
shoop.xtheme.parsing._PlaceholderManagingExtension
Parser for row and column tags.
Syntax for the row and column tags is:
{% row %} {% column [SIZES] %}...{% endcolumn %} {% endrow %}
- Rows map to
LayoutRow
objects and columns map toLayoutCell
. - For a single-cell layout, these are not necessary.
{% plugin %}
invocations without preceding{% row %}
/{% column %}
directives imply a single row and a single column.
-
parse
(parser)[source]¶ Parse a column or row.
Parameters: parser (jinja2.parser.Parser) – Template parser Returns: A null output node. Return type: jinja2.nodes.Node
-
identifier
= 'shoop.xtheme.parsing.LayoutPartExtension'¶
- Rows map to
-
class
shoop.xtheme.parsing.
PluginExtension
(environment)[source]¶ Bases:
shoop.xtheme.parsing._PlaceholderManagingExtension
Parser for plugin tags.
Syntax for plugin tag is:
{% plugin <NAME> %}...{% endplugin %}
- The (optional) body of the plugin block is expected to be a Jinja2
AST that can be folded into a constant. Generally this means a
single block of text (
{% raw }
/{% endraw %}
is okay!). - The contents of the body, if set, must be valid TOML markup. The TOML is parsed during Jinja2 parse time into a dict, which in turn is folded into the layout description object. This means only the initial parsing of the template incurs whatever performance hit there is in parsing TOML; the Jinja2 bccache should take care of the rest.
-
parse
(parser)[source]¶ Parse a column or row.
Parameters: parser (jinja2.parser.Parser) – Template parser Returns: A null output node. Return type: jinja2.nodes.Node
-
identifier
= 'shoop.xtheme.parsing.PluginExtension'¶
- The (optional) body of the plugin block is expected to be a Jinja2
AST that can be folded into a constant. Generally this means a
single block of text (
shoop.xtheme.rendering module¶
-
shoop.xtheme.rendering.
get_view_config
(context)[source]¶ Get a view configuration object for a Jinja2 rendering context.
Parameters: context (jinja2.runtime.Context) – Rendering context Returns: View config Return type: shoop.xtheme.view_config.ViewConfig
-
shoop.xtheme.rendering.
render_placeholder
(context, placeholder_name, default_layout=None, template_name=None)[source]¶ Render a placeholder in a given context.
See
PlaceholderRenderer
for argument docs.Returns: Markup Return type: Markup
-
class
shoop.xtheme.rendering.
PlaceholderRenderer
(context, placeholder_name, default_layout=None, template_name=None)[source]¶ Bases:
object
Main class for materializing a placeholder’s contents during template render time.
Parameters: - context (jinja2.runtime.Context) – Rendering context
- placeholder_name (str) – Placeholder name
- default_layout (Layout|dict|None) – Layout or serialized layout (from template configuration)
- template_name (str|None) – The actual template this node was in. Used to figure out whether the placeholder
lives in an
extends
parent, or in a child.
shoop.xtheme.resources module¶
-
class
shoop.xtheme.resources.
InlineScriptResource
[source]¶ Bases:
str
An inline script resource (a subclass of string).
The contents are rendered inside a
<script>
tag.-
classmethod
from_vars
(var_name, *args, **kwargs)[source]¶ Create an InlineScriptResource assigning an object of variables into a name in the
window
scope.Aside from
var_name
the signature of this function is similar to that ofdict
. Useful for configuration options, etc.Parameters: var_name (str) – The variable to add into global scope Returns: An InlineScriptResource
objectReturn type: InlineScriptResource
-
classmethod
-
class
shoop.xtheme.resources.
InlineMarkupResource
[source]¶ Bases:
str
An inline markup resource (a subclass of string).
The contents are rendered as-is.
-
class
shoop.xtheme.resources.
ResourceContainer
[source]¶ Bases:
object
ResourceContainers deal with storing and rendering injected resources.
A ResourceContainer is injected into rendering contexts by
XthemeTemplate
(akin to howdjango-jinja
‘s Template injectsrequest
andcsrf_token
).-
add_resource
(location, resource)[source]¶ Add a resource into the given location.
Duplicate resources are ignored (and false is returned). Resource injection order is retained.
Parameters: - location (str) – The name of the location. See KNOWN_LOCATIONS.
- resource (str|InlineMarkupResource|InlineScriptResource) – The actual resource. Either an URL string or one of the inline resource classes.
Returns: Success flag.
Return type:
-
-
shoop.xtheme.resources.
inject_resources
(context, content, clean=True)[source]¶ Inject all the resources in the context’s ResourceContainer into appropriate places in the content given.
Parameters: Returns: Possibly modified HTML content
Return type:
-
shoop.xtheme.resources.
get_resource_container
(context)[source]¶ Get a
ResourceContainer
from a rendering context.Parameters: context (jinja2.runtime.Context) – Context Returns: Resource Container Return type: shoop.xtheme.resources.ResourceContainer|None
-
shoop.xtheme.resources.
add_resource
(context, location, resource)[source]¶ Add an Xtheme resource into the given context.
Parameters: - context (jinja2.runtime.Context) – Context
- location (str) – Location string (see KNOWN_LOCATIONS)
- resource (str|InlineMarkupResource|InlineScriptResource) – Resource descriptor (URL or inline markup object)
Returns: Success flag
Return type:
shoop.xtheme.template_ns module¶
-
class
shoop.xtheme.template_ns.
XthemeNamespace
[source]¶ Bases:
object
A template helper namespace for Xtheme-related functionality.
-
get_view_name
(context)[source]¶ Get the current view’s view name (used for identifying view configurations).
Parameters: context (jinja2.runtime.Context) – Implicit Jinja2 context Returns: View name string Return type: str
-
shoop.xtheme.testing module¶
-
shoop.xtheme.testing.
override_current_theme_class
(theme_class=<object object>)¶ Context manager for overriding the currently active theme class for testing.
An instance of this class is then returned by
get_current_theme
.A falsy value means
None
is returned fromget_current_theme
, which is also useful for testing.Parameters: theme_class (class[Theme]) – A theme class object
shoop.xtheme.urls module¶
shoop.xtheme.utils module¶
-
shoop.xtheme.utils.
join_css_classes
(class_list)[source]¶ Join an iterable of truthy values by spaces, effectively creating a list of CSS classes.
The retval is sorted for cleanliness.
Parameters: class_list (Iterable[str]) – Iterable of classes Returns: String Return type: str
-
shoop.xtheme.utils.
get_html_attrs
(attrs)[source]¶ Flatten a dict into HTML attributes (it’s
django.forms.utils.flatatt
on steroids!).Only truthy keys and values are taken into account; list-like values are flattened with
join_css_classes
Parameters: attrs (dict[str, object]) – Attribute dict Returns: string ready to paste after a HTML tag open. <foo%s>
!Return type: str
shoop.xtheme.view_config module¶
-
class
shoop.xtheme.view_config.
ViewConfig
(theme, view_name, draft)[source]¶ Bases:
object
A view configuration.
Contains layout and plugin configuration for all placeholders in a given view.
This class does not directly correspond to a database model; it may act as a container for
SavedViewConfig
objects, and wraps theSavedViewConfig
API.Initialize a view configuration.
Parameters: -
saved_view_config
¶ Get a saved view config model depending on the current parameters.
Returns: A SavedViewConfig object for the current theme/view/draft mode, or None Return type: shoop.xtheme.models.SavedViewConfig|None
-
get_placeholder_layout
(placeholder_name, default_layout=None)[source]¶ Get a Layout object for the given placeholder.
Parameters: - placeholder_name (str) – The name of the placeholder to load.
- default_layout (dict|Layout) – Default layout configuration (either a dict or an actual Layout)
Returns: Layout
Return type:
-
save_default_placeholder_layout
(placeholder_name, layout)[source]¶ Save a default placeholder layout (only if no data for the PH already exists).
Parameters: - placeholder_name (str) – Placeholder name
- layout (Layout|dict) – Layout or layout data
Returns: True if saved
Return type:
-
publish
()[source]¶ Publish this revision of the view configuration as the currently public one.
Returns: Success flag Return type: bool
-
Module contents¶
-
class
shoop.xtheme.
Plugin
(config)¶ Bases:
object
A plugin that can be instantiated within a
shoop.xtheme.layout.LayoutCell
.Other plugins should inherit from this class and register themselves in the
xtheme_plugin
provide category.Instantiate a Plugin with the given
config
dictionary.Parameters: config (dict) – Dictionary of freeform configuration data -
editor_form_class
¶ alias of
GenericPluginForm
-
fields
= []¶
-
get_editor_form_class
()[source]¶ Return the form class for editing this plugin.
The form class should either derive from PluginForm, or at least have a
get_config()
method.Form classes without
fields
are treated the same way as if you’d returnNone
, i.e. no configuration form is presented to the user.Returns: Editor form class Return type: class[forms.Form]|None
-
classmethod
get_plugin_choices
(empty_label=None)[source]¶ Get a sorted list of 2-tuples (identifier and name) of available Xtheme plugins.
Handy for
<select>
boxen.Parameters: empty_label (str|None) – Label for the “empty” choice. If falsy, no empty choice is prepended Returns: List of 2-tuples Return type: Iterable[tuple[str, str]]
-
get_translated_value
(key, default=None, language=None)[source]¶ Get a translated value from the plugin’s configuration.
It’s assumed that translated values are stored in a
{language: data, ...}
dictionary in the plugin configuration blob. This is the protocol thatshoop.xtheme.plugins.forms.TranslatableField
uses.If the configuration blob contains such a dictionary, but it does not contain a translated value in the requested language does not exist, the fallback value, if any, within that dictionary is tried next. Failing that, the
default
value is returned.Parameters: - key (str) – Configuration key
- default – Default value to return when all else fails.
- language (str|None) – Requested language. Defaults to the active language.
Returns: A translated value.
-
identifier
= None¶
-
is_context_valid
(context)[source]¶ Check that the given rendering context is valid for rendering this plugin.
By default, just checks
required_context_variables
.Parameters: context (jinja2.runtime.Context) – Rendering context Returns: True if we should bother trying to render this Return type: bool
-
classmethod
load
(identifier)[source]¶ Get a plugin class based on the identifier from the
xtheme_plugin
provides registry.Parameters: identifier (str) – Plugin class identifier Returns: A plugin class, or None Return type: class[Plugin]|None
-
name
= <django.utils.functional.lazy.<locals>.__proxy__ object>¶
-
render
(context)[source]¶ Return the HTML for a plugin in a given rendering context.
Parameters: context (jinja2.runtime.Context) – Rendering context Returns: String of rendered content. Return type: str
-
required_context_variables
= set()¶
-
-
class
shoop.xtheme.
TemplatedPlugin
(config)¶ Bases:
shoop.xtheme.Plugin
Convenience base class for plugins that just render a “sub-template” with a given context.
Instantiate a Plugin with the given
config
dictionary.Parameters: config (dict) – Dictionary of freeform configuration data -
config_copied_variables
= set()¶
-
engine
= None¶
-
get_context_data
(context)[source]¶ Get a context dictionary from a Jinja2 context.
Parameters: context (jinja2.runtime.Context) – Jinja2 rendering context Returns: Dict of vars Return type: dict[str, object]
-
inherited_variables
= set()¶
-
template_name
= ''¶
-
-
class
shoop.xtheme.
Theme
(settings_obj=None)¶ Bases:
object
Base class for all Xtheme themes.
This class does not directly correspond to a database object; it’s used in the rendering, etc. process.
It does, however, act as a container for a
ThemeSettings
object that contains the actual persisted settings etc.Initialize this theme, with an optional
ThemeSettings
objectParameters: settings_obj (ThemeSettings|None) – A theme settings object for this theme, if one exists. Passing this in will avoid extraneous database queries. -
fields
= []¶
-
get_configuration_form
(form_kwargs)[source]¶ Return a ModelForm instance (model=ThemeSettings) for configuring this theme.
By default, returns a GenericThemeForm (a ModelForm populated from
theme.fields
).Parameters: form_kwargs (dict) – The keyword arguments that should be used for initializing the form Return type: django.forms.ModelForm
-
get_setting
(key, default=None)[source]¶ Get a setting value for this theme.
Parameters: Returns: Setting value
Return type:
-
get_settings
()[source]¶ Get all the currently set settings for the theme as a dict.
Returns: Dict of settings Return type: dict
-
get_view
(view_name)[source]¶ Get an extra view for this theme.
Views may be either normal Django functions or CBVs (or anything that has
as_view()
really). Falsy values are considered “not found”.Parameters: view_name (str) – View name Returns: The extra view, if one exists for the given name. Return type: dict[str, View|callable]|None
-
global_placeholders
= []¶
-
identifier
= None¶
-
name
= ''¶
-
set_settings
(*args, **kwargs)[source]¶ Set a number of settings for this theme.
The arguments are exactly the same as those to
dict
.Note
It’s better to call this once than
set_setting
several times.
-
settings_obj
¶ Get a saved settings model for this theme. If one does not yet exist, an unsaved one is returned.
If one was passed in the ctor, naturally that one is returned.
Return type: shoop.xtheme.models.ThemeSettings
-
template_dir
= None¶
-
-
shoop.xtheme.
get_current_theme
(request=None)¶ Get the currently active theme object.
Parameters: request (HttpRequest|None) – Request, if available Returns: Theme object or None Return type: Theme
-
shoop.xtheme.
get_theme_by_identifier
(identifier, settings_obj=None)¶ Get an instantiated theme by identifier.
Parameters: - identifier (str) – Theme identifier
- settings_obj (shoop.xtheme.models.ThemeSettings) – Optional ThemeSettings object for the theme constructor
Returns: Theme object or None
Return type:
-
shoop.xtheme.
set_current_theme
(identifier)¶ Activate a theme based on identifier.
Parameters: identifier (str) – Theme identifier
-
shoop.xtheme.
templated_plugin_factory
(identifier, template_name, **kwargs)¶ A factory (akin to
modelform_factory
) to quickly create simple plugins.Parameters: - identifier (str) – The unique identifier for the new plugin.
- template_name (str) – The template file path this plugin should render
- kwargs (dict) – Other arguments for the
TemplatedPlugin
/Plugin
classes.
Returns: New
TemplatedPlugin
subclassReturn type: class[TemplatedPlugin]