shuup.notify package

Subpackages

Submodules

shuup.notify.base module

class shuup.notify.base.BaseMetaclass(name, bases, namespace)[source]

Bases: type

class shuup.notify.base.Variable(name, type=<class 'shuup.notify.typology.Type'>, required=True, help_text='', attributes=())[source]

Bases: object

Parameters:
  • name (str) – A human readable name for the variable.

  • type (shuup.notify.typology.Type) – The datatype of the variable.

  • required (bool) – Whether the variable is required or not.

  • help_text (str) – A free-form plaintext help text for the variable.

  • attributes (Sequence[tuple[str, str]]) – A sequence of (label, accessor) pairs that will be shown under the variable as guides of attributes that can be accessed from it. If one would pass [_("ID", "id")] to this when the name param is “Order” if would get rendered as Order ID: {{ order.id }} in the script editor.

__init__(name, type=<class 'shuup.notify.typology.Type'>, required=True, help_text='', attributes=())[source]
Parameters:
  • name (str) – A human readable name for the variable.

  • type (shuup.notify.typology.Type) – The datatype of the variable.

  • required (bool) – Whether the variable is required or not.

  • help_text (str) – A free-form plaintext help text for the variable.

  • attributes (Sequence[tuple[str, str]]) – A sequence of (label, accessor) pairs that will be shown under the variable as guides of attributes that can be accessed from it. If one would pass [_("ID", "id")] to this when the name param is “Order” if would get rendered as Order ID: {{ order.id }} in the script editor.

get_matching_types(variable_dict)[source]
class shuup.notify.base.Binding(name, type=<class 'shuup.notify.typology.Type'>, required=False, help_text='', constant_use=ConstantUse.VARIABLE_ONLY, default=None)[source]

Bases: Variable

Parameters:
  • name (str) – A human readable name for the variable.

  • type (shuup.notify.typology.Type) – The datatype of the variable.

  • required (bool) – Whether the variable is required or not.

  • help_text (str) – A free-form plaintext help text for the variable.

  • attributes (Sequence[tuple[str, str]]) – A sequence of (label, accessor) pairs that will be shown under the variable as guides of attributes that can be accessed from it. If one would pass [_("ID", "id")] to this when the name param is “Order” if would get rendered as Order ID: {{ order.id }} in the script editor.

__init__(name, type=<class 'shuup.notify.typology.Type'>, required=False, help_text='', constant_use=ConstantUse.VARIABLE_ONLY, default=None)[source]
Parameters:
  • name (str) – A human readable name for the variable.

  • type (shuup.notify.typology.Type) – The datatype of the variable.

  • required (bool) – Whether the variable is required or not.

  • help_text (str) – A free-form plaintext help text for the variable.

  • attributes (Sequence[tuple[str, str]]) – A sequence of (label, accessor) pairs that will be shown under the variable as guides of attributes that can be accessed from it. If one would pass [_("ID", "id")] to this when the name param is “Order” if would get rendered as Order ID: {{ order.id }} in the script editor.

property accepts_any_type
property allow_constant
property allow_variable
get_value(context, bind_data)[source]
class shuup.notify.base.TemplatedBinding(*args, **kwargs)[source]

Bases: Binding

Parameters:
  • name (str) – A human readable name for the variable.

  • type (shuup.notify.typology.Type) – The datatype of the variable.

  • required (bool) – Whether the variable is required or not.

  • help_text (str) – A free-form plaintext help text for the variable.

  • attributes (Sequence[tuple[str, str]]) – A sequence of (label, accessor) pairs that will be shown under the variable as guides of attributes that can be accessed from it. If one would pass [_("ID", "id")] to this when the name param is “Order” if would get rendered as Order ID: {{ order.id }} in the script editor.

__init__(*args, **kwargs)[source]
Parameters:
  • name (str) – A human readable name for the variable.

  • type (shuup.notify.typology.Type) – The datatype of the variable.

  • required (bool) – Whether the variable is required or not.

  • help_text (str) – A free-form plaintext help text for the variable.

  • attributes (Sequence[tuple[str, str]]) – A sequence of (label, accessor) pairs that will be shown under the variable as guides of attributes that can be accessed from it. If one would pass [_("ID", "id")] to this when the name param is “Order” if would get rendered as Order ID: {{ order.id }} in the script editor.

get_value(context, bind_data)[source]
class shuup.notify.base.Base[source]

Bases: object

identifier = None
name = None
description = None
variables = {}
bindings = {}
provide_category = None
classmethod class_for_identifier(identifier)[source]
class shuup.notify.base.Event(**variable_values)[source]

Bases: Base

provide_category = 'notify_event'
identifier = None
log_target_variable = None

The name of the variable to be used as the log target for this event.

The target variable must have an add_log_entry method.

__init__(**variable_values)[source]
property log_target
load_variables(variable_values)[source]
run(shop)[source]
bindings = {}
variables = {}
class shuup.notify.base.ScriptItem(data, validate=True)[source]

Bases: Base

provide_category = None
__init__(data, validate=True)[source]
verify_bindings()[source]
get_value(context, binding_name)[source]

Get the actual value of a binding from the given script context.

Parameters:
Returns:

The variable value

get_values(context)[source]

Get all binding values in a dict.

Parameters:

context (shuup.notify.script.Context) – Script Context

Returns:

Dict of binding name -> value

Return type:

dict[name, value]

classmethod unserialize(data, validate=True)[source]
serialize()[source]
classmethod get_ui_info_map()[source]
bindings = {}
identifier = 'script_item'
name = 'Script Item'
variables = {}
class shuup.notify.base.Condition(data, validate=True)[source]

Bases: ScriptItem

provide_category = 'notify_condition'
abstractmethod test(context)[source]
bindings = {}
identifier = 'condition'
name = 'Condition'
variables = {}
class shuup.notify.base.Action(data, validate=True)[source]

Bases: ScriptItem

provide_category = 'notify_action'
template_use = 0
template_fields = {}
abstractmethod execute(context)[source]
Parameters:

context (shuup.notify.script.Context) – Script Context

get_template(context)[source]

Get this action’s template instance, bound in the context.

Return type:

shuup.notify.template.Template

get_template_values(context, language_preferences=())[source]

Render this Action’s template with data from the given context.

Parameters:
  • context (shuup.notify.script.Context) – Script Context

  • language_preferences (list[str]) – Language preference list. The first language in the template to have values for all fields will be used. Has no effect for UNILINGUAL template_use.

Returns:

Dict of field name -> rendered template text.

Return type:

dict[str, str]|None

bindings = {}
identifier = 'action'
name = 'Action'
variables = {}
class shuup.notify.base.ScriptTemplate(script_instance=None)[source]

Bases: object

Represents a script template to use in provides.

Subclass this, implement the methods and add a reference to the class in the notify_script_template provide category.

When form_class is set, a form will be presented to the user and validated, so you can extract more information to build the Script.

Variables:
  • identifier (str) – unique identifier for this ScriptTemplate with a max of 64 characters.

  • event (shuup.notify.Event) – event class which will be used to trigger the notification.

  • name (str) – name of the ScriptTemplate.

  • description (str) – description of the ScriptTemplate presented to the user.

  • help_text (str) – text to help users understand how this script will work.

  • form_class (django.forms.Form|None) – form class if your ScriptTemplate needs extra configuration.

  • initial (dict) – initial data to use in forms.

  • template_name (str) – template to use to render the form, if needed.

  • extra_js_template_name (str) – template with extra JavaScript code to use when rendering the form, if needed.

:ivar django.http.request.HttpRequest : http request.

Parameters:

script_instance (shuup.notify.models.script.Script|None) – script instance to change or None

identifier = ''
event = None
name = ''
description = ''
help_text = ''
form_class = None
initial = {}
template_name = ''
extra_js_template_name = ''
__init__(script_instance=None)[source]
Parameters:

script_instance (shuup.notify.models.script.Script|None) – script instance to change or None

abstractmethod create_script(shop, form=None)[source]

Create and returns the Script.

If form_class is set, the will be validated and you can use it to do extra configuration on the Script.

Returns:

the created script

Return type:

shuup.notify.models.script.Script

abstractmethod can_edit_script()[source]

Check whether the bound script_instance attribute can be edited by this TemplateScript.

This means if you can still understand the current script state and structure and parse it, so you can edit the script through the form_class.

This is a necessary check since the user can change the script through the Editor and those changes can disfigure the expected script structure.

Return type:

bool

Returns:

whether the bound script_instance can be edited by this script template

abstractmethod update_script(form)[source]

Updates the current bound script_instance with the validated form data.

This method is invoked when editing a Script created through this ScriptTemplate.

Note that only script templates which provides a form will have this method invoked.

Returns:

the updated script

Return type:

shuup.notify.models.script.Script

get_initial()[source]

Returns the initial data to use for configuration form.

Note: You must also check for the bound script_instance attribute. One can edit the Script created by the template editor through the form this instance provides. This way, when a script instance is bound, you must return the the representantion of the Script as the initial form data.

Returns:

initial data to to use in configuration form

Return type:

dict

get_form_class()[source]

Returns the configuration form class.

get_form(**kwargs)[source]

Returns an instance of the configuration form to be used.

get_form_kwargs(**kwargs)[source]

Returns the keyword arguments for instantiating the configuration form.

get_context_data()[source]

Returns extra data when rendering the form.

shuup.notify.enums module

class shuup.notify.enums.TemplateUse(value)[source]

Bases: Enum

NONE = 0
UNILINGUAL = 1
MULTILINGUAL = 2
class shuup.notify.enums.ConstantUse(value)[source]

Bases: Enum

VARIABLE_ONLY = 1
CONSTANT_ONLY = 2
VARIABLE_OR_CONSTANT = 3
class shuup.notify.enums.StepNext(value)[source]

Bases: Enum

CONTINUE = 'continue'
STOP = 'stop'
class shuup.notify.enums.StepConditionOperator(value)[source]

Bases: Enum

ALL = 'all'
ANY = 'any'
NONE = 'none'
class shuup.notify.enums.RecipientType(value)[source]

Bases: Enum

ADMINS = 1
SPECIFIC_USER = 2
class shuup.notify.enums.Priority(value)[source]

Bases: Enum

LOW = 1
NORMAL = 2
HIGH = 3
CRITICAL = 4

shuup.notify.notify_events module

class shuup.notify.notify_events.PasswordReset(**variable_values)[source]

Bases: Event

identifier = 'shuup_notify_password_reset'
name = 'Password Reset'
description = 'This event is triggered when password reset is requested.'
bindings = {}
variables = {'customer_email': <shuup.notify.base.Variable object>, 'recovery_url': <shuup.notify.base.Variable object>, 'site_name': <shuup.notify.base.Variable object>, 'token': <shuup.notify.base.Variable object>, 'uid': <shuup.notify.base.Variable object>, 'user_to_recover': <shuup.notify.base.Variable object>}

shuup.notify.runner module

shuup.notify.runner.run_event(event, shop)[source]

Run the event. :param shuup.notify.Event event: the event. :param shuup.Shop shop: the shop to run the event.

shuup.notify.script module

shuup.notify.script.none(conditions)[source]
class shuup.notify.script.Step(conditions=(), actions=(), next=StepNext.CONTINUE, cond_op=StepConditionOperator.ALL, enabled=True)[source]

Bases: object

__init__(conditions=(), actions=(), next=StepNext.CONTINUE, cond_op=StepConditionOperator.ALL, enabled=True)[source]
execute(context)[source]
serialize()[source]
classmethod unserialize(step_data)[source]
property enabled
class shuup.notify.script.Context(variables=None, shop=None, event_identifier=None)[source]

Bases: object

__init__(variables=None, shop=None, event_identifier=None)[source]
classmethod from_variables(shop=None, event_identifier=None, **variables)[source]

Create Context from variables.

Parameters:

event_identifier – identifier for shuup.notify event type

Return type:

shuup.notify.script.Context

classmethod from_event(event, shop=None)[source]

Create Context from event.

Return type:

shuup.notify.script.Context

get(name, default=None)[source]
set(name, value)[source]
get_variables()[source]
log(level, msg, *args, **kwargs)[source]

Log a message with the context’s logger (not the log target). This may be an useful debugging tool.

The parameters are the same as for logging.Logger.log().

add_log_entry_on_log_target(message, identifier, **kwargs)[source]

Add a log entry on the context’s log target.

The kwargs are passed to the target’s add_log_entry method.

If no log target exists or if it has no add_log_entry method, this method does nothing.

Parameters:
  • message (str) – The message text.

  • identifier (str) – The message identifier. Unlike with add_log_entry, this is required.

  • kwargs (dict) – Other kwargs to pass to add_log_entry

property log_entry_queryset

shuup.notify.script_templates module

shuup.notify.settings module

shuup.notify.settings.SHUUP_NOTIFY_SCRIPT_RUNNER = 'shuup.notify.runner.run_event'

The method used to run scripts.

shuup.notify.settings.SHUUP_NOTIFY_TEMPLATE_ENVIRONMENT_PROVIDER = 'shuup.notify.template.get_sandboxed_template_environment'

The method used to return the render environment for templates.

shuup.notify.signal_handlers module

shuup.notify.signal_handlers.on_user_requested_reset_password(sender, shop, user, reset_domain_url, reset_url_name, **kwargs)[source]

shuup.notify.signals module

shuup.notify.tasks module

shuup.notify.tasks.send_user_reset_password_email(user_id: int, shop_id: int, reset_domain_url: str, reset_url_name: str)[source]

shuup.notify.template module

exception shuup.notify.template.NoLanguageMatches[source]

Bases: Exception

shuup.notify.template.get_sandboxed_template_environment(context, **kwargs)[source]

Returns a Jinja2 enviroment for rendering templates in notifications

Parameters:
Returns:

The environment used to render.

Return type:

jinja2.environment.Environment

shuup.notify.template.render_in_context(context, template_text, html_intent=False)[source]

Render the given Jinja2 template text in the script context.

Parameters:
  • context (shuup.notify.script.Context) – Script context.

  • template_text (str) – Jinja2 template text.

  • html_intent (bool) – Is the template text intended for HTML output? This currently turns on autoescaping.

Returns:

Rendered template text.

Return type:

str

Raises:

Whatever Jinja2 might happen to raise.

class shuup.notify.template.Template(context, data)[source]

Bases: object

Parameters:
__init__(context, data)[source]
Parameters:
has_language(language, fields)[source]
render(language, fields)[source]

Render this template in the given language, returning the given fields.

Parameters:
  • language (str) – Language code (ISO 639-1 or ISO 639-2).

  • fields (list[str]) – Desired fields to render.

Returns:

Dict of field -> rendered content.

Return type:

dict[str, str]

render_first_match(language_preferences, fields)[source]

shuup.notify.typology module

class shuup.notify.typology.MultiEmailField(*, required=True, widget=None, label=None, initial=None, help_text='', error_messages=None, show_hidden_initial=False, validators=(), localize=False, disabled=False, label_suffix=None)[source]

Bases: Field

From https://docs.djangoproject.com/en/1.11/ref/forms/validation/#form-field-default-cleaning

validate(value)[source]

Check if value consists only of valid emails.

class shuup.notify.typology.Type[source]

Bases: object

name = None
identifier = None
get_field(**kwargs)[source]

Get a Django form field for this type.

The kwargs are passed directly to the field constructor.

Parameters:

kwargs (dict) – Kwargs for field constructor.

Returns:

Form field.

Return type:

django.forms.Field

unserialize(value)[source]
validate(value)[source]
is_coercible_from(other_type)[source]
class shuup.notify.typology.Boolean[source]

Bases: Type

name = 'Boolean'
identifier = 'boolean'
get_field(**kwargs)[source]

Get a Django form field for this type.

The kwargs are passed directly to the field constructor.

Parameters:

kwargs (dict) – Kwargs for field constructor.

Returns:

Form field.

Return type:

django.forms.Field

class shuup.notify.typology.Integer[source]

Bases: _Number

name = 'Integer Number'
identifier = 'integer'
get_field(**kwargs)[source]

Get a Django form field for this type.

The kwargs are passed directly to the field constructor.

Parameters:

kwargs (dict) – Kwargs for field constructor.

Returns:

Form field.

Return type:

django.forms.Field

class shuup.notify.typology.Decimal[source]

Bases: _Number

name = 'Decimal Number'
identifier = 'decimal'
get_field(**kwargs)[source]

Get a Django form field for this type.

The kwargs are passed directly to the field constructor.

Parameters:

kwargs (dict) – Kwargs for field constructor.

Returns:

Form field.

Return type:

django.forms.Field

class shuup.notify.typology.Text[source]

Bases: _String

name = 'Text'
identifier = 'text'
is_coercible_from(other_type)[source]
class shuup.notify.typology.Language[source]

Bases: _String

name = 'Language'
identifier = 'language'
class shuup.notify.typology.Email[source]

Bases: _String

name = 'Email Address'
identifier = 'email'
get_field(**kwargs)[source]

Get a Django form field for this type.

The kwargs are passed directly to the field constructor.

Parameters:

kwargs (dict) – Kwargs for field constructor.

Returns:

Form field.

Return type:

django.forms.Field

class shuup.notify.typology.URL[source]

Bases: _String

name = 'URL Address'
identifier = 'url'
get_field(**kwargs)[source]

Get a Django form field for this type.

The kwargs are passed directly to the field constructor.

Parameters:

kwargs (dict) – Kwargs for field constructor.

Returns:

Form field.

Return type:

django.forms.Field

class shuup.notify.typology.Phone[source]

Bases: _String

name = 'Phone Number'
identifier = 'phone'
class shuup.notify.typology.Model(model_label)[source]

Bases: Type

Parameters:

model_label (str) – Model label in Django app.Model format (e.g. shuup.Order).

identifier = 'model'
property name
__init__(model_label)[source]
Parameters:

model_label (str) – Model label in Django app.Model format (e.g. shuup.Order).

model_label = None
unserialize(value)[source]
is_coercible_from(other_type)[source]
get_model()[source]
Return type:

django.db.models.Model

get_field(**kwargs)[source]

Get a Django form field for this type.

The kwargs are passed directly to the field constructor.

Parameters:

kwargs (dict) – Kwargs for field constructor.

Returns:

Form field.

Return type:

django.forms.Field

class shuup.notify.typology.Enum(enum_class)[source]

Bases: Type

identifier = 'enum'
property name
__init__(enum_class)[source]
enum_class = None
unserialize(value)[source]
get_field(**kwargs)[source]

Get a Django form field for this type.

The kwargs are passed directly to the field constructor.

Parameters:

kwargs (dict) – Kwargs for field constructor.

Returns:

Form field.

Return type:

django.forms.Field

Module contents

class shuup.notify.ShuupNotifyAppConfig(*args, **kwargs)[source]

Bases: AppConfig

name = 'shuup.notify'
verbose_name = 'Shuup Notification Framework'
label = 'shuup_notify'
default_auto_field = 'django.db.models.BigAutoField'
provides = {'admin_module': ['shuup.notify.admin_module:NotifyAdminModule', 'shuup.notify.admin_module:EmailTemplateAdminModule'], 'notify_action': ['shuup.notify.actions:SetDebugFlag', 'shuup.notify.actions:AddOrderLogEntry', 'shuup.notify.actions:SendEmail', 'shuup.notify.actions:AddNotification'], 'notify_condition': ['shuup.notify.conditions:LanguageEqual', 'shuup.notify.conditions:BooleanEqual', 'shuup.notify.conditions:IntegerEqual', 'shuup.notify.conditions:TextEqual', 'shuup.notify.conditions:Empty', 'shuup.notify.conditions:NonEmpty'], 'notify_event': ['shuup.notify.notify_events:PasswordReset'], 'notify_script_template': ['shuup.notify.script_templates:PasswordResetTemplate']}

See /provides for details about the provides variable.

ready()[source]

Override this method in subclasses to run code when Django starts.