mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 11:05:41 +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:
|
||||
|
||||
|
@ -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 os
|
||||
@ -33,26 +28,22 @@ logger = logging.getLogger('inventree')
|
||||
|
||||
@register.simple_tag()
|
||||
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 %}
|
||||
|
||||
Ref: https://stackoverflow.com/questions/1070398/how-to-set-a-value-of-a-variable-inside-a-template-code
|
||||
"""
|
||||
|
||||
return value
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
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,
|
||||
which differs from the python formatting!
|
||||
"""
|
||||
|
||||
if date_object is None:
|
||||
return None
|
||||
|
||||
@ -105,27 +96,25 @@ def render_date(context, date_object):
|
||||
|
||||
@register.simple_tag()
|
||||
def decimal(x, *args, **kwargs):
|
||||
""" Simplified rendering of a decimal number """
|
||||
|
||||
"""Simplified rendering of a decimal number"""
|
||||
return InvenTree.helpers.decimal2string(x)
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def str2bool(x, *args, **kwargs):
|
||||
""" Convert a string to a boolean value """
|
||||
|
||||
"""Convert a string to a boolean value"""
|
||||
return InvenTree.helpers.str2bool(x)
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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)
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def multiply(x, y, *args, **kwargs):
|
||||
""" Multiply two numbers together """
|
||||
"""Multiply two numbers together"""
|
||||
return InvenTree.helpers.decimal2string(x * y)
|
||||
|
||||
|
||||
@ -137,27 +126,25 @@ def add(x, y, *args, **kwargs):
|
||||
|
||||
@register.simple_tag()
|
||||
def to_list(*args):
|
||||
""" Return the input arguments as list """
|
||||
"""Return the input arguments as list"""
|
||||
return args
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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))
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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:
|
||||
return False
|
||||
return True
|
||||
@ -165,22 +152,19 @@ def inventree_show_about(user, *args, **kwargs):
|
||||
|
||||
@register.simple_tag()
|
||||
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
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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']
|
||||
|
||||
engine = db.get('ENGINE', _('Unknown database'))
|
||||
@ -192,33 +176,31 @@ def inventree_db_engine(*args, **kwargs):
|
||||
|
||||
@register.simple_tag()
|
||||
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()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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')
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def python_version(*args, **kwargs):
|
||||
"""
|
||||
Return the current python version
|
||||
"""
|
||||
"""Return the current python version"""
|
||||
return sys.version.split(' ')[0]
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def inventree_version(shortstring=False, *args, **kwargs):
|
||||
""" Return InvenTree version string """
|
||||
"""Return InvenTree version string"""
|
||||
if shortstring:
|
||||
return _("{title} v{version}".format(
|
||||
title=version.inventreeInstanceTitle(),
|
||||
@ -244,38 +226,37 @@ def inventree_docs_version(*args, **kwargs):
|
||||
|
||||
@register.simple_tag()
|
||||
def inventree_api_version(*args, **kwargs):
|
||||
""" Return InvenTree API version """
|
||||
"""Return InvenTree API version"""
|
||||
return version.inventreeApiVersion()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def django_version(*args, **kwargs):
|
||||
""" Return Django version string """
|
||||
"""Return Django version string"""
|
||||
return version.inventreeDjangoVersion()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def inventree_commit_hash(*args, **kwargs):
|
||||
""" Return InvenTree git commit hash string """
|
||||
"""Return InvenTree git commit hash string"""
|
||||
return version.inventreeCommitHash()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def inventree_commit_date(*args, **kwargs):
|
||||
""" Return InvenTree git commit date string """
|
||||
"""Return InvenTree git commit date string"""
|
||||
return version.inventreeCommitDate()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def inventree_github_url(*args, **kwargs):
|
||||
""" Return URL for InvenTree github site """
|
||||
"""Return URL for InvenTree github site"""
|
||||
return "https://github.com/InvenTree/InvenTree/"
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def inventree_docs_url(*args, **kwargs):
|
||||
""" Return URL for InvenTree documenation site """
|
||||
|
||||
"""Return URL for InvenTree documenation site"""
|
||||
tag = version.inventreeDocsVersion()
|
||||
|
||||
return f"https://inventree.readthedocs.io/en/{tag}"
|
||||
@ -283,24 +264,22 @@ def inventree_docs_url(*args, **kwargs):
|
||||
|
||||
@register.simple_tag()
|
||||
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/"
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def default_currency(*args, **kwargs):
|
||||
""" Returns the default currency code """
|
||||
"""Returns the default currency code"""
|
||||
return currency_code_default()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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)
|
||||
if a user-setting was requested return that
|
||||
"""
|
||||
|
||||
if 'plugin' in kwargs:
|
||||
# Note, 'plugin' is an instance of an InvenTreePlugin class
|
||||
|
||||
@ -319,10 +298,7 @@ def setting_object(key, *args, **kwargs):
|
||||
|
||||
@register.simple_tag()
|
||||
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 not kwargs['user'] or (kwargs['user'] and kwargs['user'].is_authenticated is False):
|
||||
return InvenTreeUserSetting.get_setting(key)
|
||||
@ -333,37 +309,25 @@ def settings_value(key, *args, **kwargs):
|
||||
|
||||
@register.simple_tag()
|
||||
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)
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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()
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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)
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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')
|
||||
|
||||
val = InvenTree.helpers.normalize(val)
|
||||
@ -414,7 +378,7 @@ def get_color_theme_css(username):
|
||||
|
||||
@register.simple_tag()
|
||||
def get_user_color_theme(username):
|
||||
""" Get current user color theme """
|
||||
"""Get current user color theme"""
|
||||
try:
|
||||
user_theme = ColorTheme.objects.filter(user=username).get()
|
||||
user_theme_name = user_theme.name
|
||||
@ -428,10 +392,7 @@ def get_user_color_theme(username):
|
||||
|
||||
@register.simple_tag()
|
||||
def get_available_themes(*args, **kwargs):
|
||||
"""
|
||||
Return the available theme choices
|
||||
"""
|
||||
|
||||
"""Return the available theme choices"""
|
||||
themes = []
|
||||
|
||||
for key, name in ColorTheme.get_color_themes_choices():
|
||||
@ -445,13 +406,11 @@ def get_available_themes(*args, **kwargs):
|
||||
|
||||
@register.simple_tag()
|
||||
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
|
||||
'hello' -> '"hello"'
|
||||
"""
|
||||
|
||||
if type(primitive) is bool:
|
||||
return str(primitive).lower()
|
||||
|
||||
@ -465,10 +424,9 @@ def primitive_to_javascript(primitive):
|
||||
|
||||
@register.filter
|
||||
def keyvalue(dict, key):
|
||||
"""
|
||||
access to key of supplied dict
|
||||
"""Access to key of supplied dict
|
||||
|
||||
usage:
|
||||
Usage:
|
||||
{% mydict|keyvalue:mykey %}
|
||||
"""
|
||||
return dict.get(key)
|
||||
@ -476,10 +434,9 @@ def keyvalue(dict, key):
|
||||
|
||||
@register.simple_tag()
|
||||
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 %}
|
||||
"""
|
||||
method = getattr(obj, method_name)
|
||||
@ -488,8 +445,7 @@ def call_method(obj, method_name, *args):
|
||||
|
||||
@register.simple_tag()
|
||||
def authorized_owners(group):
|
||||
""" Return authorized owners """
|
||||
|
||||
"""Return authorized owners"""
|
||||
owners = []
|
||||
|
||||
try:
|
||||
@ -507,39 +463,37 @@ def authorized_owners(group):
|
||||
|
||||
@register.simple_tag()
|
||||
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})
|
||||
return mark_safe('<b><a href="{}">{}</a></b>'.format(ref_url, ref))
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def mail_configured():
|
||||
""" Return if mail is configured """
|
||||
"""Return if mail is configured"""
|
||||
return bool(settings.EMAIL_HOST)
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
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, '')
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def inventree_logo(*args, **kwargs):
|
||||
""" Return the path to the logo-file """
|
||||
|
||||
"""Return the path to the logo-file"""
|
||||
if settings.CUSTOM_LOGO:
|
||||
return default_storage.url(settings.CUSTOM_LOGO)
|
||||
return static('img/inventree.png')
|
||||
|
||||
|
||||
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
|
||||
|
||||
self.original = getattr(self, 'original', None)
|
||||
@ -561,17 +515,16 @@ if settings.DEBUG:
|
||||
|
||||
@register.simple_tag()
|
||||
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)
|
||||
|
||||
else: # pragma: no cover
|
||||
|
||||
@register.tag('i18n_static')
|
||||
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] %}
|
||||
"""
|
||||
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.utils.safestring import mark_safe
|
||||
@ -13,19 +11,19 @@ register = template.Library()
|
||||
|
||||
@register.simple_tag
|
||||
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)))
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
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)))
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
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)))
|
||||
|
||||
|
||||
@ -36,5 +34,5 @@ def stock_status_text(key, *args, **kwargs):
|
||||
|
||||
@register.simple_tag
|
||||
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)))
|
||||
|
@ -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 Part
|
||||
- Create / Edit / Delete PartAttachment
|
||||
- Display / Create / Edit / Delete SupplierPart
|
||||
|
||||
"""
|
||||
|
||||
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 os
|
||||
@ -43,8 +41,7 @@ from .models import (Part, PartCategory, PartCategoryParameterTemplate,
|
||||
|
||||
|
||||
class PartIndex(InvenTreeRoleMixin, ListView):
|
||||
""" View for displaying list of Part objects
|
||||
"""
|
||||
"""View for displaying list of Part objects"""
|
||||
|
||||
model = Part
|
||||
template_name = 'part/category.html'
|
||||
@ -68,7 +65,7 @@ class PartIndex(InvenTreeRoleMixin, ListView):
|
||||
|
||||
|
||||
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_form_title = _('Set Part Category')
|
||||
@ -80,7 +77,7 @@ class PartSetCategory(AjaxUpdateView):
|
||||
parts = []
|
||||
|
||||
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
|
||||
|
||||
@ -92,7 +89,7 @@ class PartSetCategory(AjaxUpdateView):
|
||||
return self.renderJsonResponse(request, form=self.get_form(), context=self.get_context_data())
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
""" Respond to a POST request to this view """
|
||||
"""Respond to a POST request to this view"""
|
||||
|
||||
self.parts = []
|
||||
|
||||
@ -135,7 +132,7 @@ class PartSetCategory(AjaxUpdateView):
|
||||
part.set_category(self.category)
|
||||
|
||||
def get_context_data(self):
|
||||
""" Return context data for rendering in the form """
|
||||
"""Return context data for rendering in the form"""
|
||||
ctx = {}
|
||||
|
||||
ctx['parts'] = self.parts
|
||||
@ -146,7 +143,7 @@ class PartSetCategory(AjaxUpdateView):
|
||||
|
||||
|
||||
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'
|
||||
|
||||
class PartFileManager(FileManager):
|
||||
@ -226,7 +223,7 @@ class PartImport(FileManagementFormView):
|
||||
file_manager_class = PartFileManager
|
||||
|
||||
def get_field_selection(self):
|
||||
""" Fill the form fields for step 3 """
|
||||
"""Fill the form fields for step 3"""
|
||||
# fetch available elements
|
||||
self.allowed_items = {}
|
||||
self.matches = {}
|
||||
@ -269,7 +266,7 @@ class PartImport(FileManagementFormView):
|
||||
row[idx.lower()] = data
|
||||
|
||||
def done(self, form_list, **kwargs):
|
||||
""" Create items """
|
||||
"""Create items"""
|
||||
items = self.get_clean_items()
|
||||
|
||||
import_done = 0
|
||||
@ -354,8 +351,7 @@ class PartImportAjax(FileManagementAjaxView, PartImport):
|
||||
|
||||
|
||||
class PartDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
""" Detail view for Part object
|
||||
"""
|
||||
"""Detail view for Part object"""
|
||||
|
||||
context_object_name = 'part'
|
||||
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
|
||||
def get_context_data(self, **kwargs):
|
||||
"""
|
||||
Provide extra context data to template
|
||||
"""
|
||||
"""Provide extra context data to template"""
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
part = self.get_object()
|
||||
@ -389,14 +383,14 @@ class PartDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
return context
|
||||
|
||||
def get_quantity(self):
|
||||
""" Return set quantity in decimal format """
|
||||
"""Return set quantity in decimal format"""
|
||||
return Decimal(self.request.POST.get('quantity', 1))
|
||||
|
||||
def get_part(self):
|
||||
return self.get_object()
|
||||
|
||||
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)
|
||||
part = self.get_part()
|
||||
default_currency = inventree_settings.currency_code_default()
|
||||
@ -503,7 +497,7 @@ class PartDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
return ctx
|
||||
|
||||
def get_initials(self):
|
||||
""" returns initials for form """
|
||||
"""Returns initials for form"""
|
||||
return {'quantity': self.get_quantity()}
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
@ -518,7 +512,7 @@ class PartDetailFromIPN(PartDetail):
|
||||
slug_url_kwarg = 'slug'
|
||||
|
||||
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()
|
||||
# Get slug
|
||||
slug = self.kwargs.get(self.slug_url_kwarg)
|
||||
@ -541,7 +535,7 @@ class PartDetailFromIPN(PartDetail):
|
||||
return None
|
||||
|
||||
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()
|
||||
|
||||
if not self.object:
|
||||
@ -551,15 +545,14 @@ class PartDetailFromIPN(PartDetail):
|
||||
|
||||
|
||||
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")
|
||||
|
||||
role_required = 'part.view'
|
||||
|
||||
def get_qr_data(self):
|
||||
""" Generate QR code data for the Part """
|
||||
|
||||
"""Generate QR code data for the Part"""
|
||||
try:
|
||||
part = Part.objects.get(id=self.pk)
|
||||
return part.format_barcode()
|
||||
@ -568,9 +561,7 @@ class PartQRCode(QRCodeView):
|
||||
|
||||
|
||||
class PartImageDownloadFromURL(AjaxUpdateView):
|
||||
"""
|
||||
View for downloading an image from a provided URL
|
||||
"""
|
||||
"""View for downloading an image from a provided URL"""
|
||||
|
||||
model = Part
|
||||
|
||||
@ -579,12 +570,10 @@ class PartImageDownloadFromURL(AjaxUpdateView):
|
||||
ajax_form_title = _('Download Image')
|
||||
|
||||
def validate(self, part, form):
|
||||
"""
|
||||
Validate that the image data are correct.
|
||||
"""Validate that the image data are correct.
|
||||
|
||||
- Try to download the image!
|
||||
"""
|
||||
|
||||
# First ensure that the normal validation routines pass
|
||||
if not form.is_valid():
|
||||
return
|
||||
@ -628,10 +617,7 @@ class PartImageDownloadFromURL(AjaxUpdateView):
|
||||
return
|
||||
|
||||
def save(self, part, form, **kwargs):
|
||||
"""
|
||||
Save the downloaded image to the part
|
||||
"""
|
||||
|
||||
"""Save the downloaded image to the part"""
|
||||
fmt = self.image.format
|
||||
|
||||
if not fmt:
|
||||
@ -651,7 +637,7 @@ class PartImageDownloadFromURL(AjaxUpdateView):
|
||||
|
||||
|
||||
class PartImageSelect(AjaxUpdateView):
|
||||
""" View for selecting Part image from existing images. """
|
||||
"""View for selecting Part image from existing images."""
|
||||
|
||||
model = Part
|
||||
ajax_template_name = 'part/select_image.html'
|
||||
@ -690,7 +676,7 @@ class PartImageSelect(AjaxUpdateView):
|
||||
|
||||
|
||||
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'
|
||||
queryset = Part.objects.all()
|
||||
@ -698,8 +684,8 @@ class BomUpload(InvenTreeRoleMixin, DetailView):
|
||||
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
@ -711,8 +697,8 @@ class BomUploadTemplate(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
|
||||
"""
|
||||
|
||||
@ -768,7 +754,7 @@ class BomDownload(AjaxView):
|
||||
|
||||
|
||||
class PartDelete(AjaxDeleteView):
|
||||
""" View to delete a Part object """
|
||||
"""View to delete a Part object"""
|
||||
|
||||
model = Part
|
||||
ajax_template_name = 'part/partial_delete.html'
|
||||
@ -784,7 +770,7 @@ class PartDelete(AjaxDeleteView):
|
||||
|
||||
|
||||
class PartPricing(AjaxView):
|
||||
""" View for inspecting part pricing information """
|
||||
"""View for inspecting part pricing information"""
|
||||
|
||||
model = Part
|
||||
ajax_template_name = "part/part_pricing.html"
|
||||
@ -794,7 +780,7 @@ class PartPricing(AjaxView):
|
||||
role_required = ['sales_order.view', 'part.view']
|
||||
|
||||
def get_quantity(self):
|
||||
""" Return set quantity in decimal format """
|
||||
"""Return set quantity in decimal format"""
|
||||
return Decimal(self.request.POST.get('quantity', 1))
|
||||
|
||||
def get_part(self):
|
||||
@ -804,7 +790,7 @@ class PartPricing(AjaxView):
|
||||
return None
|
||||
|
||||
def get_pricing(self, quantity=1, currency=None):
|
||||
""" returns context with pricing information """
|
||||
"""Returns context with pricing information"""
|
||||
if quantity <= 0:
|
||||
quantity = 1
|
||||
|
||||
@ -898,7 +884,7 @@ class PartPricing(AjaxView):
|
||||
return ctx
|
||||
|
||||
def get_initials(self):
|
||||
""" returns initials for form """
|
||||
"""Returns initials for form"""
|
||||
return {'quantity': self.get_quantity()}
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
@ -931,9 +917,7 @@ class PartPricing(AjaxView):
|
||||
|
||||
|
||||
class PartParameterTemplateCreate(AjaxCreateView):
|
||||
"""
|
||||
View for creating a new PartParameterTemplate
|
||||
"""
|
||||
"""View for creating a new PartParameterTemplate"""
|
||||
|
||||
model = PartParameterTemplate
|
||||
form_class = part_forms.EditPartParameterTemplateForm
|
||||
@ -941,9 +925,7 @@ class PartParameterTemplateCreate(AjaxCreateView):
|
||||
|
||||
|
||||
class PartParameterTemplateEdit(AjaxUpdateView):
|
||||
"""
|
||||
View for editing a PartParameterTemplate
|
||||
"""
|
||||
"""View for editing a PartParameterTemplate"""
|
||||
|
||||
model = PartParameterTemplate
|
||||
form_class = part_forms.EditPartParameterTemplateForm
|
||||
@ -951,14 +933,14 @@ class PartParameterTemplateEdit(AjaxUpdateView):
|
||||
|
||||
|
||||
class PartParameterTemplateDelete(AjaxDeleteView):
|
||||
""" View for deleting an existing PartParameterTemplate """
|
||||
"""View for deleting an existing PartParameterTemplate"""
|
||||
|
||||
model = PartParameterTemplate
|
||||
ajax_form_title = _("Delete Part Parameter Template")
|
||||
|
||||
|
||||
class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
""" Detail view for PartCategory """
|
||||
"""Detail view for PartCategory"""
|
||||
|
||||
model = PartCategory
|
||||
context_object_name = 'category'
|
||||
@ -990,9 +972,7 @@ class CategoryDetail(InvenTreeRoleMixin, InvenTreePluginViewMixin, DetailView):
|
||||
|
||||
|
||||
class CategoryDelete(AjaxDeleteView):
|
||||
"""
|
||||
Delete view to delete a PartCategory
|
||||
"""
|
||||
"""Delete view to delete a PartCategory"""
|
||||
|
||||
model = PartCategory
|
||||
ajax_template_name = 'part/category_delete.html'
|
||||
@ -1007,14 +987,14 @@ class CategoryDelete(AjaxDeleteView):
|
||||
|
||||
|
||||
class CategoryParameterTemplateCreate(AjaxCreateView):
|
||||
""" View for creating a new PartCategoryParameterTemplate """
|
||||
"""View for creating a new PartCategoryParameterTemplate"""
|
||||
|
||||
model = PartCategoryParameterTemplate
|
||||
form_class = part_forms.EditCategoryParameterTemplateForm
|
||||
ajax_form_title = _('Create Category Parameter Template')
|
||||
|
||||
def get_initial(self):
|
||||
""" Get initial data for Category """
|
||||
"""Get initial data for Category"""
|
||||
initials = super().get_initial()
|
||||
|
||||
category_id = self.kwargs.get('pk', None)
|
||||
@ -1028,11 +1008,10 @@ class CategoryParameterTemplateCreate(AjaxCreateView):
|
||||
return initials
|
||||
|
||||
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)
|
||||
- Display parameter templates which are not yet related
|
||||
"""
|
||||
|
||||
form = super().get_form()
|
||||
|
||||
form.fields['category'].widget = HiddenInput()
|
||||
@ -1062,14 +1041,13 @@ class CategoryParameterTemplateCreate(AjaxCreateView):
|
||||
return form
|
||||
|
||||
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
|
||||
all categories
|
||||
- If the add_to_same_level_categories object is set, link parameter template to
|
||||
same level categories
|
||||
"""
|
||||
|
||||
form = self.get_form()
|
||||
|
||||
valid = form.is_valid()
|
||||
@ -1108,7 +1086,7 @@ class CategoryParameterTemplateCreate(AjaxCreateView):
|
||||
|
||||
|
||||
class CategoryParameterTemplateEdit(AjaxUpdateView):
|
||||
""" View for editing a PartCategoryParameterTemplate """
|
||||
"""View for editing a PartCategoryParameterTemplate"""
|
||||
|
||||
model = PartCategoryParameterTemplate
|
||||
form_class = part_forms.EditCategoryParameterTemplateForm
|
||||
@ -1123,7 +1101,7 @@ class CategoryParameterTemplateEdit(AjaxUpdateView):
|
||||
return self.object
|
||||
|
||||
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)
|
||||
- Display parameter templates which are not yet related
|
||||
"""
|
||||
@ -1165,7 +1143,7 @@ class CategoryParameterTemplateEdit(AjaxUpdateView):
|
||||
|
||||
|
||||
class CategoryParameterTemplateDelete(AjaxDeleteView):
|
||||
""" View for deleting an existing PartCategoryParameterTemplate """
|
||||
"""View for deleting an existing PartCategoryParameterTemplate"""
|
||||
|
||||
model = PartCategoryParameterTemplate
|
||||
ajax_form_title = _("Delete Category Parameter Template")
|
||||
|
@ -6,10 +6,7 @@ import plugin.registry as pl_registry
|
||||
|
||||
|
||||
def plugin_update(queryset, new_status: bool):
|
||||
"""
|
||||
General function for bulk changing plugins
|
||||
"""
|
||||
|
||||
"""General function for bulk changing plugins"""
|
||||
apps_changed = False
|
||||
|
||||
# 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)')
|
||||
def plugin_activate(modeladmin, request, queryset):
|
||||
"""
|
||||
Activate a set of plugins
|
||||
"""
|
||||
"""Activate a set of plugins"""
|
||||
plugin_update(queryset, True)
|
||||
|
||||
|
||||
@admin.action(description='Deactivate plugin(s)')
|
||||
def plugin_deactivate(modeladmin, request, queryset):
|
||||
"""
|
||||
Deactivate a set of plugins
|
||||
"""
|
||||
|
||||
"""Deactivate a set of plugins"""
|
||||
plugin_update(queryset, False)
|
||||
|
||||
|
||||
class PluginSettingInline(admin.TabularInline):
|
||||
"""
|
||||
Inline admin class for PluginSetting
|
||||
"""
|
||||
"""Inline admin class for PluginSetting"""
|
||||
|
||||
model = models.PluginSetting
|
||||
|
||||
@ -57,9 +47,7 @@ class PluginSettingInline(admin.TabularInline):
|
||||
|
||||
|
||||
class PluginConfigAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Custom admin with restricted id fields
|
||||
"""
|
||||
"""Custom admin with restricted id fields"""
|
||||
|
||||
readonly_fields = ["key", "name", ]
|
||||
list_display = ['name', 'key', '__str__', 'active', ]
|
||||
@ -69,9 +57,7 @@ class PluginConfigAdmin(admin.ModelAdmin):
|
||||
|
||||
|
||||
class NotificationUserSettingAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Admin class for NotificationUserSetting
|
||||
"""
|
||||
"""Admin class for NotificationUserSetting"""
|
||||
|
||||
model = models.NotificationUserSetting
|
||||
|
||||
|
Reference in New Issue
Block a user