mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-15 19:45:46 +00:00
fix docstrings 8
This commit is contained in:
@ -1,5 +1,4 @@
|
|||||||
"""
|
"""The Part module is responsible for Part management.
|
||||||
The Part module is responsible for Part management.
|
|
||||||
|
|
||||||
It includes models for:
|
It includes models for:
|
||||||
|
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
"""This module provides template tags for extra functionality, over and above the built-in Django tags."""
|
||||||
|
|
||||||
"""
|
|
||||||
This module provides template tags for extra functionality,
|
|
||||||
over and above the built-in Django tags.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -33,26 +28,22 @@ logger = logging.getLogger('inventree')
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def define(value, *args, **kwargs):
|
def define(value, *args, **kwargs):
|
||||||
"""
|
"""Shortcut function to overcome the shortcomings of the django templating language
|
||||||
Shortcut function to overcome the shortcomings of the django templating language
|
|
||||||
|
|
||||||
Use as follows: {% define "hello_world" as hello %}
|
Use as follows: {% define "hello_world" as hello %}
|
||||||
|
|
||||||
Ref: https://stackoverflow.com/questions/1070398/how-to-set-a-value-of-a-variable-inside-a-template-code
|
Ref: https://stackoverflow.com/questions/1070398/how-to-set-a-value-of-a-variable-inside-a-template-code
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def render_date(context, date_object):
|
def render_date(context, date_object):
|
||||||
"""
|
"""Renders a date according to the preference of the provided user
|
||||||
Renders a date according to the preference of the provided user
|
|
||||||
|
|
||||||
Note that the user preference is stored using the formatting adopted by moment.js,
|
Note that the user preference is stored using the formatting adopted by moment.js,
|
||||||
which differs from the python formatting!
|
which differs from the python formatting!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if date_object is None:
|
if date_object is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -105,27 +96,25 @@ def render_date(context, date_object):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def decimal(x, *args, **kwargs):
|
def decimal(x, *args, **kwargs):
|
||||||
""" Simplified rendering of a decimal number """
|
"""Simplified rendering of a decimal number"""
|
||||||
|
|
||||||
return InvenTree.helpers.decimal2string(x)
|
return InvenTree.helpers.decimal2string(x)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def str2bool(x, *args, **kwargs):
|
def str2bool(x, *args, **kwargs):
|
||||||
""" Convert a string to a boolean value """
|
"""Convert a string to a boolean value"""
|
||||||
|
|
||||||
return InvenTree.helpers.str2bool(x)
|
return InvenTree.helpers.str2bool(x)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inrange(n, *args, **kwargs):
|
def inrange(n, *args, **kwargs):
|
||||||
""" Return range(n) for iterating through a numeric quantity """
|
"""Return range(n) for iterating through a numeric quantity"""
|
||||||
return range(n)
|
return range(n)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def multiply(x, y, *args, **kwargs):
|
def multiply(x, y, *args, **kwargs):
|
||||||
""" Multiply two numbers together """
|
"""Multiply two numbers together"""
|
||||||
return InvenTree.helpers.decimal2string(x * y)
|
return InvenTree.helpers.decimal2string(x * y)
|
||||||
|
|
||||||
|
|
||||||
@ -137,27 +126,25 @@ def add(x, y, *args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def to_list(*args):
|
def to_list(*args):
|
||||||
""" Return the input arguments as list """
|
"""Return the input arguments as list"""
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def part_allocation_count(build, part, *args, **kwargs):
|
def part_allocation_count(build, part, *args, **kwargs):
|
||||||
""" Return the total number of <part> allocated to <build> """
|
"""Return the total number of <part> allocated to <build>"""
|
||||||
|
|
||||||
return InvenTree.helpers.decimal2string(build.getAllocatedQuantity(part))
|
return InvenTree.helpers.decimal2string(build.getAllocatedQuantity(part))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_in_debug_mode(*args, **kwargs):
|
def inventree_in_debug_mode(*args, **kwargs):
|
||||||
""" Return True if the server is running in DEBUG mode """
|
"""Return True if the server is running in DEBUG mode"""
|
||||||
|
|
||||||
return djangosettings.DEBUG
|
return djangosettings.DEBUG
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_show_about(user, *args, **kwargs):
|
def inventree_show_about(user, *args, **kwargs):
|
||||||
""" Return True if the about modal should be shown """
|
"""Return True if the about modal should be shown"""
|
||||||
if InvenTreeSetting.get_setting('INVENTREE_RESTRICT_ABOUT') and not user.is_superuser:
|
if InvenTreeSetting.get_setting('INVENTREE_RESTRICT_ABOUT') and not user.is_superuser:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@ -165,22 +152,19 @@ def inventree_show_about(user, *args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_docker_mode(*args, **kwargs):
|
def inventree_docker_mode(*args, **kwargs):
|
||||||
""" Return True if the server is running as a Docker image """
|
"""Return True if the server is running as a Docker image"""
|
||||||
|
|
||||||
return djangosettings.DOCKER
|
return djangosettings.DOCKER
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def plugins_enabled(*args, **kwargs):
|
def plugins_enabled(*args, **kwargs):
|
||||||
""" Return True if plugins are enabled for the server instance """
|
"""Return True if plugins are enabled for the server instance"""
|
||||||
|
|
||||||
return djangosettings.PLUGINS_ENABLED
|
return djangosettings.PLUGINS_ENABLED
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_db_engine(*args, **kwargs):
|
def inventree_db_engine(*args, **kwargs):
|
||||||
""" Return the InvenTree database backend e.g. 'postgresql' """
|
"""Return the InvenTree database backend e.g. 'postgresql'"""
|
||||||
|
|
||||||
db = djangosettings.DATABASES['default']
|
db = djangosettings.DATABASES['default']
|
||||||
|
|
||||||
engine = db.get('ENGINE', _('Unknown database'))
|
engine = db.get('ENGINE', _('Unknown database'))
|
||||||
@ -192,33 +176,31 @@ def inventree_db_engine(*args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_instance_name(*args, **kwargs):
|
def inventree_instance_name(*args, **kwargs):
|
||||||
""" Return the InstanceName associated with the current database """
|
"""Return the InstanceName associated with the current database"""
|
||||||
return version.inventreeInstanceName()
|
return version.inventreeInstanceName()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_title(*args, **kwargs):
|
def inventree_title(*args, **kwargs):
|
||||||
""" Return the title for the current instance - respecting the settings """
|
"""Return the title for the current instance - respecting the settings"""
|
||||||
return version.inventreeInstanceTitle()
|
return version.inventreeInstanceTitle()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_base_url(*args, **kwargs):
|
def inventree_base_url(*args, **kwargs):
|
||||||
""" Return the INVENTREE_BASE_URL setting """
|
"""Return the INVENTREE_BASE_URL setting"""
|
||||||
return InvenTreeSetting.get_setting('INVENTREE_BASE_URL')
|
return InvenTreeSetting.get_setting('INVENTREE_BASE_URL')
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def python_version(*args, **kwargs):
|
def python_version(*args, **kwargs):
|
||||||
"""
|
"""Return the current python version"""
|
||||||
Return the current python version
|
|
||||||
"""
|
|
||||||
return sys.version.split(' ')[0]
|
return sys.version.split(' ')[0]
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_version(shortstring=False, *args, **kwargs):
|
def inventree_version(shortstring=False, *args, **kwargs):
|
||||||
""" Return InvenTree version string """
|
"""Return InvenTree version string"""
|
||||||
if shortstring:
|
if shortstring:
|
||||||
return _("{title} v{version}".format(
|
return _("{title} v{version}".format(
|
||||||
title=version.inventreeInstanceTitle(),
|
title=version.inventreeInstanceTitle(),
|
||||||
@ -244,38 +226,37 @@ def inventree_docs_version(*args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_api_version(*args, **kwargs):
|
def inventree_api_version(*args, **kwargs):
|
||||||
""" Return InvenTree API version """
|
"""Return InvenTree API version"""
|
||||||
return version.inventreeApiVersion()
|
return version.inventreeApiVersion()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def django_version(*args, **kwargs):
|
def django_version(*args, **kwargs):
|
||||||
""" Return Django version string """
|
"""Return Django version string"""
|
||||||
return version.inventreeDjangoVersion()
|
return version.inventreeDjangoVersion()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_commit_hash(*args, **kwargs):
|
def inventree_commit_hash(*args, **kwargs):
|
||||||
""" Return InvenTree git commit hash string """
|
"""Return InvenTree git commit hash string"""
|
||||||
return version.inventreeCommitHash()
|
return version.inventreeCommitHash()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_commit_date(*args, **kwargs):
|
def inventree_commit_date(*args, **kwargs):
|
||||||
""" Return InvenTree git commit date string """
|
"""Return InvenTree git commit date string"""
|
||||||
return version.inventreeCommitDate()
|
return version.inventreeCommitDate()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_github_url(*args, **kwargs):
|
def inventree_github_url(*args, **kwargs):
|
||||||
""" Return URL for InvenTree github site """
|
"""Return URL for InvenTree github site"""
|
||||||
return "https://github.com/InvenTree/InvenTree/"
|
return "https://github.com/InvenTree/InvenTree/"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_docs_url(*args, **kwargs):
|
def inventree_docs_url(*args, **kwargs):
|
||||||
""" Return URL for InvenTree documenation site """
|
"""Return URL for InvenTree documenation site"""
|
||||||
|
|
||||||
tag = version.inventreeDocsVersion()
|
tag = version.inventreeDocsVersion()
|
||||||
|
|
||||||
return f"https://inventree.readthedocs.io/en/{tag}"
|
return f"https://inventree.readthedocs.io/en/{tag}"
|
||||||
@ -283,24 +264,22 @@ def inventree_docs_url(*args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_credits_url(*args, **kwargs):
|
def inventree_credits_url(*args, **kwargs):
|
||||||
""" Return URL for InvenTree credits site """
|
"""Return URL for InvenTree credits site"""
|
||||||
return "https://inventree.readthedocs.io/en/latest/credits/"
|
return "https://inventree.readthedocs.io/en/latest/credits/"
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def default_currency(*args, **kwargs):
|
def default_currency(*args, **kwargs):
|
||||||
""" Returns the default currency code """
|
"""Returns the default currency code"""
|
||||||
return currency_code_default()
|
return currency_code_default()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def setting_object(key, *args, **kwargs):
|
def setting_object(key, *args, **kwargs):
|
||||||
"""
|
"""Return a setting object speciifed by the given key
|
||||||
Return a setting object speciifed by the given key
|
|
||||||
(Or return None if the setting does not exist)
|
(Or return None if the setting does not exist)
|
||||||
if a user-setting was requested return that
|
if a user-setting was requested return that
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if 'plugin' in kwargs:
|
if 'plugin' in kwargs:
|
||||||
# Note, 'plugin' is an instance of an InvenTreePlugin class
|
# Note, 'plugin' is an instance of an InvenTreePlugin class
|
||||||
|
|
||||||
@ -319,10 +298,7 @@ def setting_object(key, *args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def settings_value(key, *args, **kwargs):
|
def settings_value(key, *args, **kwargs):
|
||||||
"""
|
"""Return a settings value specified by the given key"""
|
||||||
Return a settings value specified by the given key
|
|
||||||
"""
|
|
||||||
|
|
||||||
if 'user' in kwargs:
|
if 'user' in kwargs:
|
||||||
if not kwargs['user'] or (kwargs['user'] and kwargs['user'].is_authenticated is False):
|
if not kwargs['user'] or (kwargs['user'] and kwargs['user'].is_authenticated is False):
|
||||||
return InvenTreeUserSetting.get_setting(key)
|
return InvenTreeUserSetting.get_setting(key)
|
||||||
@ -333,37 +309,25 @@ def settings_value(key, *args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def user_settings(user, *args, **kwargs):
|
def user_settings(user, *args, **kwargs):
|
||||||
"""
|
"""Return all USER settings as a key:value dict"""
|
||||||
Return all USER settings as a key:value dict
|
|
||||||
"""
|
|
||||||
|
|
||||||
return InvenTreeUserSetting.allValues(user=user)
|
return InvenTreeUserSetting.allValues(user=user)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def global_settings(*args, **kwargs):
|
def global_settings(*args, **kwargs):
|
||||||
"""
|
"""Return all GLOBAL InvenTree settings as a key:value dict"""
|
||||||
Return all GLOBAL InvenTree settings as a key:value dict
|
|
||||||
"""
|
|
||||||
|
|
||||||
return InvenTreeSetting.allValues()
|
return InvenTreeSetting.allValues()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def visible_global_settings(*args, **kwargs):
|
def visible_global_settings(*args, **kwargs):
|
||||||
"""
|
"""Return any global settings which are not marked as 'hidden'"""
|
||||||
Return any global settings which are not marked as 'hidden'
|
|
||||||
"""
|
|
||||||
|
|
||||||
return InvenTreeSetting.allValues(exclude_hidden=True)
|
return InvenTreeSetting.allValues(exclude_hidden=True)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def progress_bar(val, max_val, *args, **kwargs):
|
def progress_bar(val, max_val, *args, **kwargs):
|
||||||
"""
|
"""Render a progress bar element"""
|
||||||
Render a progress bar element
|
|
||||||
"""
|
|
||||||
|
|
||||||
item_id = kwargs.get('id', 'progress-bar')
|
item_id = kwargs.get('id', 'progress-bar')
|
||||||
|
|
||||||
val = InvenTree.helpers.normalize(val)
|
val = InvenTree.helpers.normalize(val)
|
||||||
@ -414,7 +378,7 @@ def get_color_theme_css(username):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def get_user_color_theme(username):
|
def get_user_color_theme(username):
|
||||||
""" Get current user color theme """
|
"""Get current user color theme"""
|
||||||
try:
|
try:
|
||||||
user_theme = ColorTheme.objects.filter(user=username).get()
|
user_theme = ColorTheme.objects.filter(user=username).get()
|
||||||
user_theme_name = user_theme.name
|
user_theme_name = user_theme.name
|
||||||
@ -428,10 +392,7 @@ def get_user_color_theme(username):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def get_available_themes(*args, **kwargs):
|
def get_available_themes(*args, **kwargs):
|
||||||
"""
|
"""Return the available theme choices"""
|
||||||
Return the available theme choices
|
|
||||||
"""
|
|
||||||
|
|
||||||
themes = []
|
themes = []
|
||||||
|
|
||||||
for key, name in ColorTheme.get_color_themes_choices():
|
for key, name in ColorTheme.get_color_themes_choices():
|
||||||
@ -445,13 +406,11 @@ def get_available_themes(*args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def primitive_to_javascript(primitive):
|
def primitive_to_javascript(primitive):
|
||||||
"""
|
"""Convert a python primitive to a javascript primitive.
|
||||||
Convert a python primitive to a javascript primitive.
|
|
||||||
|
|
||||||
e.g. True -> true
|
e.g. True -> true
|
||||||
'hello' -> '"hello"'
|
'hello' -> '"hello"'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if type(primitive) is bool:
|
if type(primitive) is bool:
|
||||||
return str(primitive).lower()
|
return str(primitive).lower()
|
||||||
|
|
||||||
@ -465,10 +424,9 @@ def primitive_to_javascript(primitive):
|
|||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def keyvalue(dict, key):
|
def keyvalue(dict, key):
|
||||||
"""
|
"""Access to key of supplied dict
|
||||||
access to key of supplied dict
|
|
||||||
|
|
||||||
usage:
|
Usage:
|
||||||
{% mydict|keyvalue:mykey %}
|
{% mydict|keyvalue:mykey %}
|
||||||
"""
|
"""
|
||||||
return dict.get(key)
|
return dict.get(key)
|
||||||
@ -476,10 +434,9 @@ def keyvalue(dict, key):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def call_method(obj, method_name, *args):
|
def call_method(obj, method_name, *args):
|
||||||
"""
|
"""Enables calling model methods / functions from templates with arguments
|
||||||
enables calling model methods / functions from templates with arguments
|
|
||||||
|
|
||||||
usage:
|
Usage:
|
||||||
{% call_method model_object 'fnc_name' argument1 %}
|
{% call_method model_object 'fnc_name' argument1 %}
|
||||||
"""
|
"""
|
||||||
method = getattr(obj, method_name)
|
method = getattr(obj, method_name)
|
||||||
@ -488,8 +445,7 @@ def call_method(obj, method_name, *args):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def authorized_owners(group):
|
def authorized_owners(group):
|
||||||
""" Return authorized owners """
|
"""Return authorized owners"""
|
||||||
|
|
||||||
owners = []
|
owners = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -507,39 +463,37 @@ def authorized_owners(group):
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def object_link(url_name, pk, ref):
|
def object_link(url_name, pk, ref):
|
||||||
""" Return highlighted link to object """
|
"""Return highlighted link to object"""
|
||||||
|
|
||||||
ref_url = reverse(url_name, kwargs={'pk': pk})
|
ref_url = reverse(url_name, kwargs={'pk': pk})
|
||||||
return mark_safe('<b><a href="{}">{}</a></b>'.format(ref_url, ref))
|
return mark_safe('<b><a href="{}">{}</a></b>'.format(ref_url, ref))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def mail_configured():
|
def mail_configured():
|
||||||
""" Return if mail is configured """
|
"""Return if mail is configured"""
|
||||||
return bool(settings.EMAIL_HOST)
|
return bool(settings.EMAIL_HOST)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_customize(reference, *args, **kwargs):
|
def inventree_customize(reference, *args, **kwargs):
|
||||||
""" Return customization values for the user interface """
|
"""Return customization values for the user interface"""
|
||||||
|
|
||||||
return djangosettings.CUSTOMIZE.get(reference, '')
|
return djangosettings.CUSTOMIZE.get(reference, '')
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def inventree_logo(*args, **kwargs):
|
def inventree_logo(*args, **kwargs):
|
||||||
""" Return the path to the logo-file """
|
"""Return the path to the logo-file"""
|
||||||
|
|
||||||
if settings.CUSTOM_LOGO:
|
if settings.CUSTOM_LOGO:
|
||||||
return default_storage.url(settings.CUSTOM_LOGO)
|
return default_storage.url(settings.CUSTOM_LOGO)
|
||||||
return static('img/inventree.png')
|
return static('img/inventree.png')
|
||||||
|
|
||||||
|
|
||||||
class I18nStaticNode(StaticNode):
|
class I18nStaticNode(StaticNode):
|
||||||
|
"""Custom StaticNode
|
||||||
|
|
||||||
|
Replaces a variable named *lng* in the path with the current language
|
||||||
"""
|
"""
|
||||||
custom StaticNode
|
|
||||||
replaces a variable named *lng* in the path with the current language
|
|
||||||
"""
|
|
||||||
def render(self, context): # pragma: no cover
|
def render(self, context): # pragma: no cover
|
||||||
|
|
||||||
self.original = getattr(self, 'original', None)
|
self.original = getattr(self, 'original', None)
|
||||||
@ -561,17 +515,16 @@ if settings.DEBUG:
|
|||||||
|
|
||||||
@register.simple_tag()
|
@register.simple_tag()
|
||||||
def i18n_static(url_name):
|
def i18n_static(url_name):
|
||||||
""" simple tag to enable {% url %} functionality instead of {% static %} """
|
"""Simple tag to enable {% url %} functionality instead of {% static %}"""
|
||||||
return reverse(url_name)
|
return reverse(url_name)
|
||||||
|
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
|
|
||||||
@register.tag('i18n_static')
|
@register.tag('i18n_static')
|
||||||
def do_i18n_static(parser, token):
|
def do_i18n_static(parser, token):
|
||||||
"""
|
"""Overrides normal static, adds language - lookup for prerenderd files #1485
|
||||||
Overrides normal static, adds language - lookup for prerenderd files #1485
|
|
||||||
|
|
||||||
usage (like static):
|
Usage (like static):
|
||||||
{% i18n_static path [as varname] %}
|
{% i18n_static path [as varname] %}
|
||||||
"""
|
"""
|
||||||
bits = token.split_contents()
|
bits = token.split_contents()
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""
|
"""Provide templates for the various model status codes."""
|
||||||
Provide templates for the various model status codes.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
@ -13,19 +11,19 @@ register = template.Library()
|
|||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def purchase_order_status_label(key, *args, **kwargs):
|
def purchase_order_status_label(key, *args, **kwargs):
|
||||||
""" Render a PurchaseOrder status label """
|
"""Render a PurchaseOrder status label"""
|
||||||
return mark_safe(PurchaseOrderStatus.render(key, large=kwargs.get('large', False)))
|
return mark_safe(PurchaseOrderStatus.render(key, large=kwargs.get('large', False)))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def sales_order_status_label(key, *args, **kwargs):
|
def sales_order_status_label(key, *args, **kwargs):
|
||||||
""" Render a SalesOrder status label """
|
"""Render a SalesOrder status label"""
|
||||||
return mark_safe(SalesOrderStatus.render(key, large=kwargs.get('large', False)))
|
return mark_safe(SalesOrderStatus.render(key, large=kwargs.get('large', False)))
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def stock_status_label(key, *args, **kwargs):
|
def stock_status_label(key, *args, **kwargs):
|
||||||
""" Render a StockItem status label """
|
"""Render a StockItem status label"""
|
||||||
return mark_safe(StockStatus.render(key, large=kwargs.get('large', False)))
|
return mark_safe(StockStatus.render(key, large=kwargs.get('large', False)))
|
||||||
|
|
||||||
|
|
||||||
@ -36,5 +34,5 @@ def stock_status_text(key, *args, **kwargs):
|
|||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def build_status_label(key, *args, **kwargs):
|
def build_status_label(key, *args, **kwargs):
|
||||||
""" Render a Build status label """
|
"""Render a Build status label"""
|
||||||
return mark_safe(BuildStatus.render(key, large=kwargs.get('large', False)))
|
return mark_safe(BuildStatus.render(key, large=kwargs.get('large', False)))
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
"""
|
"""URL lookup for Part app. Provides URL endpoints for:
|
||||||
URL lookup for Part app. Provides URL endpoints for:
|
|
||||||
|
|
||||||
- Display / Create / Edit / Delete PartCategory
|
- Display / Create / Edit / Delete PartCategory
|
||||||
- Display / Create / Edit / Delete Part
|
- Display / Create / Edit / Delete Part
|
||||||
- Create / Edit / Delete PartAttachment
|
- Create / Edit / Delete PartAttachment
|
||||||
- Display / Create / Edit / Delete SupplierPart
|
- Display / Create / Edit / Delete SupplierPart
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.urls import include, re_path
|
from django.urls import include, re_path
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""
|
"""Django views for interacting with Part app"""
|
||||||
Django views for interacting with Part app
|
|
||||||
"""
|
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
@ -43,8 +41,7 @@ from .models import (Part, PartCategory, PartCategoryParameterTemplate,
|
|||||||
|
|
||||||
|
|
||||||
class PartIndex(InvenTreeRoleMixin, ListView):
|
class PartIndex(InvenTreeRoleMixin, ListView):
|
||||||
""" View for displaying list of Part objects
|
"""View for displaying list of Part objects"""
|
||||||
"""
|
|
||||||
|
|
||||||
model = Part
|
model = Part
|
||||||
template_name = 'part/category.html'
|
template_name = 'part/category.html'
|
||||||
@ -68,7 +65,7 @@ class PartIndex(InvenTreeRoleMixin, ListView):
|
|||||||
|
|
||||||
|
|
||||||
class PartSetCategory(AjaxUpdateView):
|
class PartSetCategory(AjaxUpdateView):
|
||||||
""" View for settings the part category for multiple parts at once """
|
"""View for settings the part category for multiple parts at once"""
|
||||||
|
|
||||||
ajax_template_name = 'part/set_category.html'
|
ajax_template_name = 'part/set_category.html'
|
||||||
ajax_form_title = _('Set Part Category')
|
ajax_form_title = _('Set Part Category')
|
||||||
@ -80,7 +77,7 @@ class PartSetCategory(AjaxUpdateView):
|
|||||||
parts = []
|
parts = []
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
""" Respond to a GET request to this view """
|
"""Respond to a GET request to this view"""
|
||||||
|
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
@ -92,7 +89,7 @@ class PartSetCategory(AjaxUpdateView):
|
|||||||
return self.renderJsonResponse(request, form=self.get_form(), context=self.get_context_data())
|
return self.renderJsonResponse(request, form=self.get_form(), context=self.get_context_data())
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
""" Respond to a POST request to this view """
|
"""Respond to a POST request to this view"""
|
||||||
|
|
||||||
self.parts = []
|
self.parts = []
|
||||||
|
|
||||||
@ -135,7 +132,7 @@ class PartSetCategory(AjaxUpdateView):
|
|||||||
part.set_category(self.category)
|
part.set_category(self.category)
|
||||||
|
|
||||||
def get_context_data(self):
|
def get_context_data(self):
|
||||||
""" Return context data for rendering in the form """
|
"""Return context data for rendering in the form"""
|
||||||
ctx = {}
|
ctx = {}
|
||||||
|
|
||||||
ctx['parts'] = self.parts
|
ctx['parts'] = self.parts
|
||||||
@ -146,7 +143,7 @@ class PartSetCategory(AjaxUpdateView):
|
|||||||
|
|
||||||
|
|
||||||
class PartImport(FileManagementFormView):
|
class PartImport(FileManagementFormView):
|
||||||
''' Part: Upload file, match to fields and import parts(using multi-Step form) '''
|
"""Part: Upload file, match to fields and import parts(using multi-Step form)"""
|
||||||
permission_required = 'part.add'
|
permission_required = 'part.add'
|
||||||
|
|
||||||
class PartFileManager(FileManager):
|
class PartFileManager(FileManager):
|
||||||
@ -226,7 +223,7 @@ class PartImport(FileManagementFormView):
|
|||||||
file_manager_class = PartFileManager
|
file_manager_class = PartFileManager
|
||||||
|
|
||||||
def get_field_selection(self):
|
def get_field_selection(self):
|
||||||
""" Fill the form fields for step 3 """
|
"""Fill the form fields for step 3"""
|
||||||
# fetch available elements
|
# fetch available elements
|
||||||
self.allowed_items = {}
|
self.allowed_items = {}
|
||||||
self.matches = {}
|
self.matches = {}
|
||||||
@ -269,7 +266,7 @@ class PartImport(FileManagementFormView):
|
|||||||
row[idx.lower()] = data
|
row[idx.lower()] = data
|
||||||
|
|
||||||
def done(self, form_list, **kwargs):
|
def done(self, form_list, **kwargs):
|
||||||
""" Create items """
|
"""Create items"""
|
||||||
items = self.get_clean_items()
|
items = self.get_clean_items()
|
||||||
|
|
||||||
import_done = 0
|
import_done = 0
|
||||||
@ -354,8 +351,7 @@ class PartImportAjax(FileManagementAjaxView, PartImport):
|
|||||||
|
|
||||||
|
|
||||||
class PartDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
class PartDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||||
""" Detail view for Part object
|
"""Detail view for Part object"""
|
||||||
"""
|
|
||||||
|
|
||||||
context_object_name = 'part'
|
context_object_name = 'part'
|
||||||
queryset = Part.objects.all().select_related('category')
|
queryset = Part.objects.all().select_related('category')
|
||||||
@ -364,9 +360,7 @@ class PartDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
|||||||
|
|
||||||
# Add in some extra context information based on query params
|
# Add in some extra context information based on query params
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
"""
|
"""Provide extra context data to template"""
|
||||||
Provide extra context data to template
|
|
||||||
"""
|
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
part = self.get_object()
|
part = self.get_object()
|
||||||
@ -389,14 +383,14 @@ class PartDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
def get_quantity(self):
|
def get_quantity(self):
|
||||||
""" Return set quantity in decimal format """
|
"""Return set quantity in decimal format"""
|
||||||
return Decimal(self.request.POST.get('quantity', 1))
|
return Decimal(self.request.POST.get('quantity', 1))
|
||||||
|
|
||||||
def get_part(self):
|
def get_part(self):
|
||||||
return self.get_object()
|
return self.get_object()
|
||||||
|
|
||||||
def get_pricing(self, quantity=1, currency=None):
|
def get_pricing(self, quantity=1, currency=None):
|
||||||
""" returns context with pricing information """
|
"""Returns context with pricing information"""
|
||||||
ctx = PartPricing.get_pricing(self, quantity, currency)
|
ctx = PartPricing.get_pricing(self, quantity, currency)
|
||||||
part = self.get_part()
|
part = self.get_part()
|
||||||
default_currency = inventree_settings.currency_code_default()
|
default_currency = inventree_settings.currency_code_default()
|
||||||
@ -503,7 +497,7 @@ class PartDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
|||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
def get_initials(self):
|
def get_initials(self):
|
||||||
""" returns initials for form """
|
"""Returns initials for form"""
|
||||||
return {'quantity': self.get_quantity()}
|
return {'quantity': self.get_quantity()}
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
@ -518,7 +512,7 @@ class PartDetailFromIPN(PartDetail):
|
|||||||
slug_url_kwarg = 'slug'
|
slug_url_kwarg = 'slug'
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
""" Return Part object which IPN field matches the slug value """
|
"""Return Part object which IPN field matches the slug value"""
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
# Get slug
|
# Get slug
|
||||||
slug = self.kwargs.get(self.slug_url_kwarg)
|
slug = self.kwargs.get(self.slug_url_kwarg)
|
||||||
@ -541,7 +535,7 @@ class PartDetailFromIPN(PartDetail):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
""" Attempt to match slug to a Part, else redirect to PartIndex view """
|
"""Attempt to match slug to a Part, else redirect to PartIndex view"""
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
|
|
||||||
if not self.object:
|
if not self.object:
|
||||||
@ -551,15 +545,14 @@ class PartDetailFromIPN(PartDetail):
|
|||||||
|
|
||||||
|
|
||||||
class PartQRCode(QRCodeView):
|
class PartQRCode(QRCodeView):
|
||||||
""" View for displaying a QR code for a Part object """
|
"""View for displaying a QR code for a Part object"""
|
||||||
|
|
||||||
ajax_form_title = _("Part QR Code")
|
ajax_form_title = _("Part QR Code")
|
||||||
|
|
||||||
role_required = 'part.view'
|
role_required = 'part.view'
|
||||||
|
|
||||||
def get_qr_data(self):
|
def get_qr_data(self):
|
||||||
""" Generate QR code data for the Part """
|
"""Generate QR code data for the Part"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
part = Part.objects.get(id=self.pk)
|
part = Part.objects.get(id=self.pk)
|
||||||
return part.format_barcode()
|
return part.format_barcode()
|
||||||
@ -568,9 +561,7 @@ class PartQRCode(QRCodeView):
|
|||||||
|
|
||||||
|
|
||||||
class PartImageDownloadFromURL(AjaxUpdateView):
|
class PartImageDownloadFromURL(AjaxUpdateView):
|
||||||
"""
|
"""View for downloading an image from a provided URL"""
|
||||||
View for downloading an image from a provided URL
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = Part
|
model = Part
|
||||||
|
|
||||||
@ -579,12 +570,10 @@ class PartImageDownloadFromURL(AjaxUpdateView):
|
|||||||
ajax_form_title = _('Download Image')
|
ajax_form_title = _('Download Image')
|
||||||
|
|
||||||
def validate(self, part, form):
|
def validate(self, part, form):
|
||||||
"""
|
"""Validate that the image data are correct.
|
||||||
Validate that the image data are correct.
|
|
||||||
|
|
||||||
- Try to download the image!
|
- Try to download the image!
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# First ensure that the normal validation routines pass
|
# First ensure that the normal validation routines pass
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return
|
return
|
||||||
@ -628,10 +617,7 @@ class PartImageDownloadFromURL(AjaxUpdateView):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def save(self, part, form, **kwargs):
|
def save(self, part, form, **kwargs):
|
||||||
"""
|
"""Save the downloaded image to the part"""
|
||||||
Save the downloaded image to the part
|
|
||||||
"""
|
|
||||||
|
|
||||||
fmt = self.image.format
|
fmt = self.image.format
|
||||||
|
|
||||||
if not fmt:
|
if not fmt:
|
||||||
@ -651,7 +637,7 @@ class PartImageDownloadFromURL(AjaxUpdateView):
|
|||||||
|
|
||||||
|
|
||||||
class PartImageSelect(AjaxUpdateView):
|
class PartImageSelect(AjaxUpdateView):
|
||||||
""" View for selecting Part image from existing images. """
|
"""View for selecting Part image from existing images."""
|
||||||
|
|
||||||
model = Part
|
model = Part
|
||||||
ajax_template_name = 'part/select_image.html'
|
ajax_template_name = 'part/select_image.html'
|
||||||
@ -690,7 +676,7 @@ class PartImageSelect(AjaxUpdateView):
|
|||||||
|
|
||||||
|
|
||||||
class BomUpload(InvenTreeRoleMixin, DetailView):
|
class BomUpload(InvenTreeRoleMixin, DetailView):
|
||||||
""" View for uploading a BOM file, and handling BOM data importing. """
|
"""View for uploading a BOM file, and handling BOM data importing."""
|
||||||
|
|
||||||
context_object_name = 'part'
|
context_object_name = 'part'
|
||||||
queryset = Part.objects.all()
|
queryset = Part.objects.all()
|
||||||
@ -698,8 +684,8 @@ class BomUpload(InvenTreeRoleMixin, DetailView):
|
|||||||
|
|
||||||
|
|
||||||
class BomUploadTemplate(AjaxView):
|
class BomUploadTemplate(AjaxView):
|
||||||
"""
|
"""Provide a BOM upload template file for download.
|
||||||
Provide a BOM upload template file for download.
|
|
||||||
- Generates a template file in the provided format e.g. ?format=csv
|
- Generates a template file in the provided format e.g. ?format=csv
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -711,8 +697,8 @@ class BomUploadTemplate(AjaxView):
|
|||||||
|
|
||||||
|
|
||||||
class BomDownload(AjaxView):
|
class BomDownload(AjaxView):
|
||||||
"""
|
"""Provide raw download of a BOM file.
|
||||||
Provide raw download of a BOM file.
|
|
||||||
- File format should be passed as a query param e.g. ?format=csv
|
- File format should be passed as a query param e.g. ?format=csv
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -768,7 +754,7 @@ class BomDownload(AjaxView):
|
|||||||
|
|
||||||
|
|
||||||
class PartDelete(AjaxDeleteView):
|
class PartDelete(AjaxDeleteView):
|
||||||
""" View to delete a Part object """
|
"""View to delete a Part object"""
|
||||||
|
|
||||||
model = Part
|
model = Part
|
||||||
ajax_template_name = 'part/partial_delete.html'
|
ajax_template_name = 'part/partial_delete.html'
|
||||||
@ -784,7 +770,7 @@ class PartDelete(AjaxDeleteView):
|
|||||||
|
|
||||||
|
|
||||||
class PartPricing(AjaxView):
|
class PartPricing(AjaxView):
|
||||||
""" View for inspecting part pricing information """
|
"""View for inspecting part pricing information"""
|
||||||
|
|
||||||
model = Part
|
model = Part
|
||||||
ajax_template_name = "part/part_pricing.html"
|
ajax_template_name = "part/part_pricing.html"
|
||||||
@ -794,7 +780,7 @@ class PartPricing(AjaxView):
|
|||||||
role_required = ['sales_order.view', 'part.view']
|
role_required = ['sales_order.view', 'part.view']
|
||||||
|
|
||||||
def get_quantity(self):
|
def get_quantity(self):
|
||||||
""" Return set quantity in decimal format """
|
"""Return set quantity in decimal format"""
|
||||||
return Decimal(self.request.POST.get('quantity', 1))
|
return Decimal(self.request.POST.get('quantity', 1))
|
||||||
|
|
||||||
def get_part(self):
|
def get_part(self):
|
||||||
@ -804,7 +790,7 @@ class PartPricing(AjaxView):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_pricing(self, quantity=1, currency=None):
|
def get_pricing(self, quantity=1, currency=None):
|
||||||
""" returns context with pricing information """
|
"""Returns context with pricing information"""
|
||||||
if quantity <= 0:
|
if quantity <= 0:
|
||||||
quantity = 1
|
quantity = 1
|
||||||
|
|
||||||
@ -898,7 +884,7 @@ class PartPricing(AjaxView):
|
|||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
def get_initials(self):
|
def get_initials(self):
|
||||||
""" returns initials for form """
|
"""Returns initials for form"""
|
||||||
return {'quantity': self.get_quantity()}
|
return {'quantity': self.get_quantity()}
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
@ -931,9 +917,7 @@ class PartPricing(AjaxView):
|
|||||||
|
|
||||||
|
|
||||||
class PartParameterTemplateCreate(AjaxCreateView):
|
class PartParameterTemplateCreate(AjaxCreateView):
|
||||||
"""
|
"""View for creating a new PartParameterTemplate"""
|
||||||
View for creating a new PartParameterTemplate
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = PartParameterTemplate
|
model = PartParameterTemplate
|
||||||
form_class = part_forms.EditPartParameterTemplateForm
|
form_class = part_forms.EditPartParameterTemplateForm
|
||||||
@ -941,9 +925,7 @@ class PartParameterTemplateCreate(AjaxCreateView):
|
|||||||
|
|
||||||
|
|
||||||
class PartParameterTemplateEdit(AjaxUpdateView):
|
class PartParameterTemplateEdit(AjaxUpdateView):
|
||||||
"""
|
"""View for editing a PartParameterTemplate"""
|
||||||
View for editing a PartParameterTemplate
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = PartParameterTemplate
|
model = PartParameterTemplate
|
||||||
form_class = part_forms.EditPartParameterTemplateForm
|
form_class = part_forms.EditPartParameterTemplateForm
|
||||||
@ -951,14 +933,14 @@ class PartParameterTemplateEdit(AjaxUpdateView):
|
|||||||
|
|
||||||
|
|
||||||
class PartParameterTemplateDelete(AjaxDeleteView):
|
class PartParameterTemplateDelete(AjaxDeleteView):
|
||||||
""" View for deleting an existing PartParameterTemplate """
|
"""View for deleting an existing PartParameterTemplate"""
|
||||||
|
|
||||||
model = PartParameterTemplate
|
model = PartParameterTemplate
|
||||||
ajax_form_title = _("Delete Part Parameter Template")
|
ajax_form_title = _("Delete Part Parameter Template")
|
||||||
|
|
||||||
|
|
||||||
class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||||
""" Detail view for PartCategory """
|
"""Detail view for PartCategory"""
|
||||||
|
|
||||||
model = PartCategory
|
model = PartCategory
|
||||||
context_object_name = 'category'
|
context_object_name = 'category'
|
||||||
@ -990,9 +972,7 @@ class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
|||||||
|
|
||||||
|
|
||||||
class CategoryDelete(AjaxDeleteView):
|
class CategoryDelete(AjaxDeleteView):
|
||||||
"""
|
"""Delete view to delete a PartCategory"""
|
||||||
Delete view to delete a PartCategory
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = PartCategory
|
model = PartCategory
|
||||||
ajax_template_name = 'part/category_delete.html'
|
ajax_template_name = 'part/category_delete.html'
|
||||||
@ -1007,14 +987,14 @@ class CategoryDelete(AjaxDeleteView):
|
|||||||
|
|
||||||
|
|
||||||
class CategoryParameterTemplateCreate(AjaxCreateView):
|
class CategoryParameterTemplateCreate(AjaxCreateView):
|
||||||
""" View for creating a new PartCategoryParameterTemplate """
|
"""View for creating a new PartCategoryParameterTemplate"""
|
||||||
|
|
||||||
model = PartCategoryParameterTemplate
|
model = PartCategoryParameterTemplate
|
||||||
form_class = part_forms.EditCategoryParameterTemplateForm
|
form_class = part_forms.EditCategoryParameterTemplateForm
|
||||||
ajax_form_title = _('Create Category Parameter Template')
|
ajax_form_title = _('Create Category Parameter Template')
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
""" Get initial data for Category """
|
"""Get initial data for Category"""
|
||||||
initials = super().get_initial()
|
initials = super().get_initial()
|
||||||
|
|
||||||
category_id = self.kwargs.get('pk', None)
|
category_id = self.kwargs.get('pk', None)
|
||||||
@ -1028,11 +1008,10 @@ class CategoryParameterTemplateCreate(AjaxCreateView):
|
|||||||
return initials
|
return initials
|
||||||
|
|
||||||
def get_form(self):
|
def get_form(self):
|
||||||
""" Create a form to upload a new CategoryParameterTemplate
|
"""Create a form to upload a new CategoryParameterTemplate
|
||||||
- Hide the 'category' field (parent part)
|
- Hide the 'category' field (parent part)
|
||||||
- Display parameter templates which are not yet related
|
- Display parameter templates which are not yet related
|
||||||
"""
|
"""
|
||||||
|
|
||||||
form = super().get_form()
|
form = super().get_form()
|
||||||
|
|
||||||
form.fields['category'].widget = HiddenInput()
|
form.fields['category'].widget = HiddenInput()
|
||||||
@ -1062,14 +1041,13 @@ class CategoryParameterTemplateCreate(AjaxCreateView):
|
|||||||
return form
|
return form
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
""" Capture the POST request
|
"""Capture the POST request
|
||||||
|
|
||||||
- If the add_to_all_categories object is set, link parameter template to
|
- If the add_to_all_categories object is set, link parameter template to
|
||||||
all categories
|
all categories
|
||||||
- If the add_to_same_level_categories object is set, link parameter template to
|
- If the add_to_same_level_categories object is set, link parameter template to
|
||||||
same level categories
|
same level categories
|
||||||
"""
|
"""
|
||||||
|
|
||||||
form = self.get_form()
|
form = self.get_form()
|
||||||
|
|
||||||
valid = form.is_valid()
|
valid = form.is_valid()
|
||||||
@ -1108,7 +1086,7 @@ class CategoryParameterTemplateCreate(AjaxCreateView):
|
|||||||
|
|
||||||
|
|
||||||
class CategoryParameterTemplateEdit(AjaxUpdateView):
|
class CategoryParameterTemplateEdit(AjaxUpdateView):
|
||||||
""" View for editing a PartCategoryParameterTemplate """
|
"""View for editing a PartCategoryParameterTemplate"""
|
||||||
|
|
||||||
model = PartCategoryParameterTemplate
|
model = PartCategoryParameterTemplate
|
||||||
form_class = part_forms.EditCategoryParameterTemplateForm
|
form_class = part_forms.EditCategoryParameterTemplateForm
|
||||||
@ -1123,7 +1101,7 @@ class CategoryParameterTemplateEdit(AjaxUpdateView):
|
|||||||
return self.object
|
return self.object
|
||||||
|
|
||||||
def get_form(self):
|
def get_form(self):
|
||||||
""" Create a form to upload a new CategoryParameterTemplate
|
"""Create a form to upload a new CategoryParameterTemplate
|
||||||
- Hide the 'category' field (parent part)
|
- Hide the 'category' field (parent part)
|
||||||
- Display parameter templates which are not yet related
|
- Display parameter templates which are not yet related
|
||||||
"""
|
"""
|
||||||
@ -1165,7 +1143,7 @@ class CategoryParameterTemplateEdit(AjaxUpdateView):
|
|||||||
|
|
||||||
|
|
||||||
class CategoryParameterTemplateDelete(AjaxDeleteView):
|
class CategoryParameterTemplateDelete(AjaxDeleteView):
|
||||||
""" View for deleting an existing PartCategoryParameterTemplate """
|
"""View for deleting an existing PartCategoryParameterTemplate"""
|
||||||
|
|
||||||
model = PartCategoryParameterTemplate
|
model = PartCategoryParameterTemplate
|
||||||
ajax_form_title = _("Delete Category Parameter Template")
|
ajax_form_title = _("Delete Category Parameter Template")
|
||||||
|
@ -6,10 +6,7 @@ import plugin.registry as pl_registry
|
|||||||
|
|
||||||
|
|
||||||
def plugin_update(queryset, new_status: bool):
|
def plugin_update(queryset, new_status: bool):
|
||||||
"""
|
"""General function for bulk changing plugins"""
|
||||||
General function for bulk changing plugins
|
|
||||||
"""
|
|
||||||
|
|
||||||
apps_changed = False
|
apps_changed = False
|
||||||
|
|
||||||
# Run through all plugins in the queryset as the save method needs to be overridden
|
# Run through all plugins in the queryset as the save method needs to be overridden
|
||||||
@ -26,25 +23,18 @@ def plugin_update(queryset, new_status: bool):
|
|||||||
|
|
||||||
@admin.action(description='Activate plugin(s)')
|
@admin.action(description='Activate plugin(s)')
|
||||||
def plugin_activate(modeladmin, request, queryset):
|
def plugin_activate(modeladmin, request, queryset):
|
||||||
"""
|
"""Activate a set of plugins"""
|
||||||
Activate a set of plugins
|
|
||||||
"""
|
|
||||||
plugin_update(queryset, True)
|
plugin_update(queryset, True)
|
||||||
|
|
||||||
|
|
||||||
@admin.action(description='Deactivate plugin(s)')
|
@admin.action(description='Deactivate plugin(s)')
|
||||||
def plugin_deactivate(modeladmin, request, queryset):
|
def plugin_deactivate(modeladmin, request, queryset):
|
||||||
"""
|
"""Deactivate a set of plugins"""
|
||||||
Deactivate a set of plugins
|
|
||||||
"""
|
|
||||||
|
|
||||||
plugin_update(queryset, False)
|
plugin_update(queryset, False)
|
||||||
|
|
||||||
|
|
||||||
class PluginSettingInline(admin.TabularInline):
|
class PluginSettingInline(admin.TabularInline):
|
||||||
"""
|
"""Inline admin class for PluginSetting"""
|
||||||
Inline admin class for PluginSetting
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = models.PluginSetting
|
model = models.PluginSetting
|
||||||
|
|
||||||
@ -57,9 +47,7 @@ class PluginSettingInline(admin.TabularInline):
|
|||||||
|
|
||||||
|
|
||||||
class PluginConfigAdmin(admin.ModelAdmin):
|
class PluginConfigAdmin(admin.ModelAdmin):
|
||||||
"""
|
"""Custom admin with restricted id fields"""
|
||||||
Custom admin with restricted id fields
|
|
||||||
"""
|
|
||||||
|
|
||||||
readonly_fields = ["key", "name", ]
|
readonly_fields = ["key", "name", ]
|
||||||
list_display = ['name', 'key', '__str__', 'active', ]
|
list_display = ['name', 'key', '__str__', 'active', ]
|
||||||
@ -69,9 +57,7 @@ class PluginConfigAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
|
|
||||||
class NotificationUserSettingAdmin(admin.ModelAdmin):
|
class NotificationUserSettingAdmin(admin.ModelAdmin):
|
||||||
"""
|
"""Admin class for NotificationUserSetting"""
|
||||||
Admin class for NotificationUserSetting
|
|
||||||
"""
|
|
||||||
|
|
||||||
model = models.NotificationUserSetting
|
model = models.NotificationUserSetting
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user