shuup.admin.dashboard package

Submodules

shuup.admin.dashboard.blocks module

class shuup.admin.dashboard.blocks.DashboardBlock(id, size=None, color=None, sort_order=0)[source]

Bases: object

type: str | None = None
SIZES = ('small', 'normal', 'medium', 'large', 'full')
default_size = 'normal'
__init__(id, size=None, color=None, sort_order=0)[source]
sort_order = 0
class shuup.admin.dashboard.blocks.DashboardContentBlock(id, content, size='normal')[source]

Bases: DashboardBlock

type: str | None = 'normal'
__init__(id, content, size='normal')[source]
classmethod by_rendering_template(id, request, template_name, context)[source]
class shuup.admin.dashboard.blocks.DashboardValueBlock(id, value, title, **kwargs)[source]

Bases: DashboardBlock

type: str | None = 'value'
default_size = 'small'
__init__(id, value, title, **kwargs)[source]
class shuup.admin.dashboard.blocks.DashboardNumberBlock(id, value, title, **kwargs)[source]

Bases: DashboardValueBlock

__init__(id, value, title, **kwargs)[source]
class shuup.admin.dashboard.blocks.DashboardMoneyBlock(id, value, title, currency, **kwargs)[source]

Bases: DashboardValueBlock

__init__(id, value, title, currency, **kwargs)[source]
class shuup.admin.dashboard.blocks.DashboardChartBlock(id, size='normal')[source]

Bases: DashboardBlock

type: str | None = 'chart'
default_size = 'medium'
BLOCK_TEMPLATE = '\n    <div class="color-block block-purple">\n        <h2 class="block-title">%(title)s</h2>\n        <div class="block-content">\n            <canvas id="chart-%(id)s" height="250"></canvas>\n        </div>\n    </div>\n    <script>\n    window.CHART_CONFIGS = window.CHART_CONFIGS || {};\n    window.CHART_CONFIGS["%(id)s"] = %(config)s;\n    </script>\n    '
get_chart()[source]

Get the actual chart instance for this block.

Returns:

The chart (or None, if it can’t be rendered)

Return type:

shuup.admin.dashboard.charts.Chart|None

__init__(id, size='normal')[source]

shuup.admin.dashboard.charts module

class shuup.admin.dashboard.charts.ChartType[source]

Bases: object

Type of a chart

BAR = 'bar'
LINE = 'line'
class shuup.admin.dashboard.charts.ChartDataType[source]

Bases: object

Data type of datasets

NUMBER = 'number'
CURRENCY = 'currency'
PERCENT = 'percent'
class shuup.admin.dashboard.charts.Chart(title, data_type='number', locale=None, currency=None, options=None)[source]

Bases: object

Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

supported_chart_types: List[str] = []
__init__(title, data_type='number', locale=None, currency=None, options=None)[source]
Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

abstractmethod get_config()[source]

Get a JSONable dictionary of configuration data for this chart. This is passed on as CHART_CONFIGS in the JS environment and eventually processed by dashboard-charts.js.

Returns:

Dict of configuration

Return type:

dict

get_config_json()[source]
add_data(name, data, chart_type)[source]

Add data to this chart.

Parameters:
  • name (str) – the name of the dataset

  • data (list[int|float|Decimal]) – the list of data

  • chart_type (ChartType) – the chart type - tells how data should be rendered. This data type must be available in the supported_chart_type attribute of this instance

class shuup.admin.dashboard.charts.BarChart(title, labels, data_type='number', **kwargs)[source]

Bases: Chart

Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

supported_chart_types: List[str] = ['bar']
__init__(title, labels, data_type='number', **kwargs)[source]
Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

get_config()[source]

Get a JSONable dictionary of configuration data for this chart. This is passed on as CHART_CONFIGS in the JS environment and eventually processed by dashboard-charts.js.

Returns:

Dict of configuration

Return type:

dict

class shuup.admin.dashboard.charts.MixedChart(title, labels, data_type='number', **kwargs)[source]

Bases: Chart

This chart supports both Bars and Lines.

Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

supported_chart_types: List[str] = ['bar', 'line']
__init__(title, labels, data_type='number', **kwargs)[source]
Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

get_config()[source]

Get a JSONable dictionary of configuration data for this chart. This is passed on as CHART_CONFIGS in the JS environment and eventually processed by dashboard-charts.js.

Returns:

Dict of configuration

Return type:

dict

shuup.admin.dashboard.utils module

shuup.admin.dashboard.utils.get_activity(request, n_entries=30, cutoff_hours=10)[source]

Get Activity objects from all modules as a list in latest-first order.

Parameters:
  • request (django.http.request.HttpRequest) – Request context

  • n_entries (int) – Number of entries to return in total.

  • cutoff_hours (float) – Calculate cutoff datetime so the oldest entry should be at most this old

Returns:

List of Activity objects

Return type:

list[Activity]

Module contents

class shuup.admin.dashboard.BarChart(title, labels, data_type='number', **kwargs)[source]

Bases: Chart

Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

__init__(title, labels, data_type='number', **kwargs)[source]
Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

get_config()[source]

Get a JSONable dictionary of configuration data for this chart. This is passed on as CHART_CONFIGS in the JS environment and eventually processed by dashboard-charts.js.

Returns:

Dict of configuration

Return type:

dict

supported_chart_types: List[str] = ['bar']
class shuup.admin.dashboard.MixedChart(title, labels, data_type='number', **kwargs)[source]

Bases: Chart

This chart supports both Bars and Lines.

Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

__init__(title, labels, data_type='number', **kwargs)[source]
Parameters:
  • title (str) – the title of the chart

  • data_type (ChartDataType) – the data type of values The chart will format the output labels according to this parameter

  • locale (str) – the locale to render values If not set, the locale will be fetched from Babel

  • currency (str) – the ISO-4217 code for the currency This is necessary when the data_type is CURRENCY

  • options (dict) – a dicionaty with options for Chartjs

get_config()[source]

Get a JSONable dictionary of configuration data for this chart. This is passed on as CHART_CONFIGS in the JS environment and eventually processed by dashboard-charts.js.

Returns:

Dict of configuration

Return type:

dict

supported_chart_types: List[str] = ['bar', 'line']
class shuup.admin.dashboard.ChartType[source]

Bases: object

Type of a chart

BAR = 'bar'
LINE = 'line'
class shuup.admin.dashboard.ChartDataType[source]

Bases: object

Data type of datasets

CURRENCY = 'currency'
NUMBER = 'number'
PERCENT = 'percent'
class shuup.admin.dashboard.DashboardBlock(id, size=None, color=None, sort_order=0)[source]

Bases: object

SIZES = ('small', 'normal', 'medium', 'large', 'full')
__init__(id, size=None, color=None, sort_order=0)[source]
default_size = 'normal'
sort_order = 0
type: str | None = None
class shuup.admin.dashboard.DashboardChartBlock(id, size='normal')[source]

Bases: DashboardBlock

BLOCK_TEMPLATE = '\n    <div class="color-block block-purple">\n        <h2 class="block-title">%(title)s</h2>\n        <div class="block-content">\n            <canvas id="chart-%(id)s" height="250"></canvas>\n        </div>\n    </div>\n    <script>\n    window.CHART_CONFIGS = window.CHART_CONFIGS || {};\n    window.CHART_CONFIGS["%(id)s"] = %(config)s;\n    </script>\n    '
__init__(id, size='normal')[source]
default_size = 'medium'
get_chart()[source]

Get the actual chart instance for this block.

Returns:

The chart (or None, if it can’t be rendered)

Return type:

shuup.admin.dashboard.charts.Chart|None

type: str | None = 'chart'
class shuup.admin.dashboard.DashboardContentBlock(id, content, size='normal')[source]

Bases: DashboardBlock

__init__(id, content, size='normal')[source]
classmethod by_rendering_template(id, request, template_name, context)[source]
type: str | None = 'normal'
class shuup.admin.dashboard.DashboardMoneyBlock(id, value, title, currency, **kwargs)[source]

Bases: DashboardValueBlock

__init__(id, value, title, currency, **kwargs)[source]
class shuup.admin.dashboard.DashboardNumberBlock(id, value, title, **kwargs)[source]

Bases: DashboardValueBlock

__init__(id, value, title, **kwargs)[source]
class shuup.admin.dashboard.DashboardValueBlock(id, value, title, **kwargs)[source]

Bases: DashboardBlock

__init__(id, value, title, **kwargs)[source]
default_size = 'small'
type: str | None = 'value'
shuup.admin.dashboard.get_activity(request, n_entries=30, cutoff_hours=10)[source]

Get Activity objects from all modules as a list in latest-first order.

Parameters:
  • request (django.http.request.HttpRequest) – Request context

  • n_entries (int) – Number of entries to return in total.

  • cutoff_hours (float) – Calculate cutoff datetime so the oldest entry should be at most this old

Returns:

List of Activity objects

Return type:

list[Activity]