shuup.xtheme package

Submodules

shuup.xtheme.editing module

shuup.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
shuup.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
shuup.xtheme.editing.set_edit_mode(request, flag)[source]

Enable or disable edit mode for the request.

Parameters:
shuup.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 that view object does not explicitly opt-out of editing with xtheme_injection = False

Parameters:context (jinja2.runtime.Context) – Jinja rendering context
Returns:Permission bool
Return type:bool
shuup.xtheme.editing.add_edit_resources(context)[source]

Possibly inject Xtheme editor injection resources into the given context’s resources.

Parameters:context (jinja2.runtime.Context) – Jinja rendering context

shuup.xtheme.engine module

class shuup.xtheme.engine.XthemeTemplate[source]

Bases: jinja2.environment.Template

A subclass of Jinja templates with additional post-processing magic.

render(*args, **kwargs)[source]

Render the template and postprocess it.

Returns:Rendered markup
Return type:str
class shuup.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": "shuup.xtheme.engine.XthemeEnvironment" in your TEMPLATES 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 not None, 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:

shuup.xtheme.engine.XthemeTemplate

get_or_select_template(template_name_or_list, parent=None, globals=None)[source]

Does a typecheck and dispatches to select_template or get_template.

Parameters:
  • template_name_or_list (str|Iterable[str]) – Template name or list
  • parent (str|None) – If the parent parameter is not None, 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:

shuup.xtheme.engine.XthemeTemplate

shuup.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.

shuup.xtheme.extenders module

class shuup.xtheme.extenders.MenuExtenderLocation[source]

Bases: enumfields.enums.Enum

An enumeration.

MAIN_MENU = <MenuExtenderLocation.MAIN_MENU: 1>
ADMIN_MENU = <MenuExtenderLocation.ADMIN_MENU: 2>
LEFT_MENU = <MenuExtenderLocation.LEFT_MENU: 3>
FOOTER = <MenuExtenderLocation.FOOTER: 4>
class shuup.xtheme.extenders.FrontMenuExtender[source]

Bases: object

location = <MenuExtenderLocation.MAIN_MENU: 1>
items = []
menu_item_template = 'menu_extension.jinja'
get_rendered_menu_items(request, theme)[source]

shuup.xtheme.forms module

class shuup.xtheme.forms.GenericThemeForm(**kwargs)[source]

Bases: django.forms.models.ModelForm

A generic form for Xthemes; populates itself based on fields in the theme class.

class Meta[source]

Bases: object

model

alias of ThemeSettings

fields = ()
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 instance
Return type:shuup.xtheme.models.ThemeSettings

shuup.xtheme.layout module

class shuup.xtheme.layout.LayoutCell(theme, plugin_identifier, config=None, sizes=None, align='')[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
  • align (str) – Align string
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(theme, 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
serialize()[source]

Serialize this cell into a dict.

Returns:Layout cell data dict
Return type:dict
class shuup.xtheme.layout.LayoutRow(theme, 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(theme, 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
serialize()[source]

Serialize this row into a dict.

Returns:Layout row data dict
Return type:dict
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
class shuup.xtheme.layout.Layout(theme, 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(theme, data, placeholder_name=None)[source]

Unserialize a dict of layout data into a new layout, with all rows and cells.

Parameters:
  • data (dict) – Layout data dict
  • placeholder_name (str) – Placeholder name if none is specified in the data
Returns:

New layout

Return type:

Layout

serialize()[source]

Serialize this layout into a dict.

Returns:Layout data dict
Return type:dict
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:
  • plugin_identifier (str) – Plugin identifier string
  • config (dict) – Configuration dict
Returns:

The configured cell

Return type:

LayoutCell

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:
  • x (int) – X (horizontal) coordinate
  • y (int) – Y (vertical) coordinate
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
delete_row(y)[source]

Delete the y’th (zero-based) row.

If y is out of bounds, nothing is done.

Parameters:y (int) – Y coordinate
Returns:Was something done?
Return type:bool
move_row_to_index(from_y, to_y)[source]

Move the y’th row to the specified zero-based index.

If y or index is out of bounds, nothing is done.

Parameters:
  • from_y (int) – current Y coordinate
  • to_y (int) – new Y coordinate
Returns:

Was something done?

Return type:

bool

move_cell_to_position(from_x, from_y, to_x, to_y)[source]

Move the layout cell to the specified zero-based coordinates.

If the coordinates are out of range, nothing is done.

Parameters:
  • from_x (int) – X (horizontal) coordinate of the cell to move
  • from_y (int) – Y (vertical) coordinate of the cell to move
  • to_x (int) – X (horizontal) coordinate of the cell after moving
  • to_y (int) – Y (vertical) coordinate of the cell after moving
Returns:

Was something done?

Return type:

bool

delete_cell(x, y)[source]

Delete a layout cell indicated by the given (zero-based) coordinates.

If the coordinates are out of range, nothing is done.

Parameters:
  • x (int) – X (horizontal) coordinate
  • y (int) – Y (vertical) coordinate
Returns:

Was something done?

Return type:

bool

shuup.xtheme.models module

class shuup.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:
Returns:

SavedViewConfig (possibly not saved)

Return type:

SavedViewConfig

class shuup.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.
CURRENT_DRAFT = <SavedViewConfigStatus.CURRENT_DRAFT: 1>
OLD_VERSION = <SavedViewConfigStatus.OLD_VERSION: 2>
PUBLIC = <SavedViewConfigStatus.PUBLIC: 3>
class shuup.xtheme.models.SavedViewConfig(id, theme_identifier, view_name, created_on, status, _data)[source]

Bases: django.db.models.base.Model

Parameters:
  • id (AutoField) – Id
  • theme_identifier (CharField) – Theme identifier
  • view_name (CharField) – View name
  • created_on (DateTimeField) – Created on
  • status (EnumIntegerField) – Status
  • _data (TaggedJSONField) – Internal data
status

A placeholder class that provides a way to set the attribute on the model.

objects = <django.db.models.manager.ManagerFromSavedViewConfigQuerySet object>
draft
publish()[source]
revert()[source]
set_layout_data(placeholder_name, layout)[source]
get_layout_data(placeholder_name)[source]
clear_layout_data(placeholder_name)[source]
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception SavedViewConfig.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

SavedViewConfig.get_next_by_created_on(*moreargs, **morekwargs)
SavedViewConfig.get_previous_by_created_on(*moreargs, **morekwargs)
SavedViewConfig.get_status_display(*moreargs, **morekwargs)
class shuup.xtheme.models.ThemeSettings(id, theme_identifier, active, data)[source]

Bases: django.db.models.base.Model

Parameters:
  • id (AutoField) – Id
  • theme_identifier (CharField) – Theme identifier
  • active (BooleanField) – Active
  • data (TaggedJSONField) – Data
data

A placeholder class that provides a way to set the attribute on the model.

activate()[source]
get_setting(key, default=None)[source]
get_settings()[source]
update_settings(update_values)[source]
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception ThemeSettings.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

ThemeSettings.objects = <django.db.models.manager.Manager object>

shuup.xtheme.parsing module

exception shuup.xtheme.parsing.Unflattenable[source]

Bases: Exception

Exception raised when a node list can’t be flattened into a constant.

exception shuup.xtheme.parsing.NonConstant[source]

Bases: ValueError

Exception raised when something expected to be constant... is not.

exception shuup.xtheme.parsing.NestingError[source]

Bases: ValueError

Exception raised when a template’s placeholder/column/row/plugin hierarchy is out of whack.

shuup.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:

str

Raises:

Unflattenable – Raised when the node list can’t be flattened into a constant

shuup.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:

object

shuup.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 shuup.xtheme.parsing.PlaceholderExtension(environment)[source]

Bases: shuup.xtheme.parsing._PlaceholderManagingExtension

PlaceholderExtension manages {% placeholder <NAME> [global] %} ...
{% endplaceholder %}.
  • The name can be any Jinja2 expression that can be folded into a constant, with the addition of bare variable names such as name 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 and plugin directives have any meaning. (A parser-time Layout object is created and populated during parsing of this block.)
  • An optional global parameter can be used to specify that the configuration for this placeholder should be “global” across different views (although currently that only applies to placeholders within the same template, i.e, if you defined the same global placeholder in different templates they will not share configuration, but an included or base template that is rendered by different views will).
tags = {'placeholder'}
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 = 'shuup.xtheme.parsing.PlaceholderExtension'
class shuup.xtheme.parsing.LayoutPartExtension(environment)[source]

Bases: shuup.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 to LayoutCell.
  • For a single-cell layout, these are not necessary. {% plugin %} invocations without preceding {% row %}/{% column %} directives imply a single row and a single column.
tags = {'row', '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 = 'shuup.xtheme.parsing.LayoutPartExtension'
class shuup.xtheme.parsing.PluginExtension(environment)[source]

Bases: shuup.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.
tags = {'plugin'}
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 = 'shuup.xtheme.parsing.PluginExtension'

shuup.xtheme.rendering module

shuup.xtheme.rendering.get_view_config(context, global_type=False)[source]

Get a view configuration object for a Jinja2 rendering context.

Parameters:
  • context (jinja2.runtime.Context) – Rendering context
  • global_type (bool|False) – Boolean indicating whether this is a global type
Returns:

View config

Return type:

shuup.xtheme.view_config.ViewConfig

shuup.xtheme.rendering.render_placeholder(context, placeholder_name, default_layout=None, template_name=None, global_type=False)[source]

Render a placeholder in a given context.

See PlaceholderRenderer for argument docs.

Returns:Markup
Return type:Markup
class shuup.xtheme.rendering.PlaceholderRenderer(context, placeholder_name, default_layout=None, template_name=None, global_type=False)[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.
  • global_type (bool|False) – Boolean indicating whether this is a global placeholder
render()[source]

Get this placeholder’s rendered contents.

Returns:Rendered markup.
Return type:markupsafe.Markup

shuup.xtheme.resources module

class shuup.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 of dict. Useful for configuration options, etc.

Parameters:var_name (str) – The variable to add into global scope
Returns:An InlineScriptResource object
Return type:InlineScriptResource
class shuup.xtheme.resources.InlineMarkupResource[source]

Bases: str

An inline markup resource (a subclass of string).

The contents are rendered as-is.

class shuup.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 how django-jinja‘s Template injects request and csrf_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:

bool

render_resources(location, clean=True)[source]

Render the resources for the given location, then (by default) clean that list of resources.

Parameters:
  • location (str) – The name of the location. See KNOWN_LOCATIONS.
  • clean (bool) – Whether or not to clean up the list of resources.
Returns:

String of HTML

shuup.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:
  • context (jinja2.runtime.Context) – Rendering context
  • content (str) – HTML content
  • clean (bool) – Clean the resource container as we go?
Returns:

Possibly modified HTML content

Return type:

str

shuup.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:shuup.xtheme.resources.ResourceContainer|None
shuup.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:

bool

shuup.xtheme.template_ns module

class shuup.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
is_edit_mode(context)[source]

Get the current edit mode status.

Parameters:context (jinja2.runtime.Context) – Implicit Jinja2 context
Returns:Edit mode enable flag
Return type:bool
get(context, name, default=None)[source]

Get a theme setting value.

Parameters:
  • context (jinja2.runtime.Context) – Implicit Jinja2 context
  • name (str) – Setting name
  • default (object) – Default value if setting is not found
Returns:

Value

Return type:

object

shuup.xtheme.testing module

shuup.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 from get_current_theme, which is also useful for testing.

Parameters:theme_class (class[Theme]) – A theme class object

shuup.xtheme.urls module

shuup.xtheme.utils module

shuup.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
shuup.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

shuup.xtheme.view_config module

class shuup.xtheme.view_config.ViewConfig(theme, view_name, draft, global_type=False)[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 the SavedViewConfig API.

Initialize a view configuration.

Parameters:
  • theme (shuup.xtheme.Theme|None) – Theme object (could be None to not touch the database)
  • view_name (str) – View name (the class name of the view)
  • draft (bool) – Load in draft mode?
  • global_type (bool|False) – Boolean indicating whether this is a global config
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:shuup.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:

Layout

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:

bool

publish()[source]

Publish this revision of the view configuration as the currently public one.

Returns:Success flag
Return type:bool
revert()[source]

Revert this revision of the view configuration, if it’s a draft.

Returns:Success flag
Return type:bool
save_placeholder_layout(placeholder_name, layout)[source]

Save the given layout as the layout for the given placeholder.

Parameters:
  • placeholder_name (str) – The placeholder name.
  • layout (Layout|dict) – Layout object (or dict)

Module contents

class shuup.xtheme.Plugin(config)

Bases: object

A plugin that can be instantiated within a shuup.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_defaults()[source]

Return the default values of this plugins configuration.

Default values will be set to the plugin’s configuration and applied to the form fields’ initial values

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 return None, 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> boxes.

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 that shuup.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, theme=None)[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()
set_defaults()[source]

Apply the default configuration to the current configuration.

class shuup.xtheme.TemplatedPlugin(config)

Bases: shuup.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()
render(context)[source]
template_name = ''
class shuup.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 object

Parameters:settings_obj (ThemeSettings|None) – A theme settings object for this theme, if one exists. Passing this in will avoid extraneous database queries.
author = ''
default_style_identifier = None
default_template_dir = None
fields = []
get_all_plugin_choices(empty_label=None)[source]

Get grouped list of 2-tuples (identifier and name) of all available Xtheme plugins.

Super handy for <select> boxes.

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_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_default_style()[source]
get_global_plugin_choices(empty_label=None)[source]

Get a sorted list of 2-tuples (identifier and name) of available global Xtheme plugins.

Handy for <select> boxes.

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_setting(key, default=None)[source]

Get a setting value for this theme.

Parameters:
  • key (str) – Setting name
  • default (object) – Default value, if the setting is not set
Returns:

Setting value

Return type:

object

get_settings()[source]

Get all the currently set settings for the theme as a dict.

Returns:Dict of settings
Return type:dict
get_theme_plugin_choices(empty_label=None)[source]

Get a sorted list of 2-tuples (identifier and name) of available theme specific Xtheme plugins.

Handy for <select> boxes.

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_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 = []
guide_template = None
has_images()[source]

Check if theme has images available

Returns:True or False
Return type:bool
has_stylesheets()[source]
identifier = None
name = ''
plugins = []
render_menu_extensions(request, location=<MenuExtenderLocation.MAIN_MENU: 1>)[source]

Render menu extensions

Some addons want to provide items to main menu. :param request: :return safe HTML string:

set_current()[source]

Set this theme as the active theme.

set_setting(key, value)[source]

Set a theme setting key to the value value.

Parameters:
  • key (str) – Setting name
  • value (object) – Setting value
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:shuup.xtheme.models.ThemeSettings
stylesheets = []
template_dir = None
shuup.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
shuup.xtheme.get_theme_by_identifier(identifier, settings_obj=None)

Get an instantiated theme by identifier.

Parameters:
Returns:

Theme object or None

Return type:

Theme

shuup.xtheme.set_current_theme(identifier)

Activate a theme based on identifier.

Parameters:identifier (str) – Theme identifier
Returns:Activated theme
Return type:Theme
shuup.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 subclass

Return type:

class[TemplatedPlugin]