mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 21:15:41 +00:00
[CI] docstrings (#6172)
* Squashed commit of the following: commit52d7ff0f65
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 23:03:20 2024 +0100 fixed lookup commit0d076eaea8
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 23:03:08 2024 +0100 switched to pathlib for lookup commit473e75eda2
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 22:52:30 2024 +0100 fix wrong url response commitfd74f8d703
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 21:14:38 2024 +0100 switched to ruff for import sorting commitf83fedbbb8
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 21:03:14 2024 +0100 switched to single quotes everywhere commita92442e60e
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:58:23 2024 +0100 added autofixes commitcc66c93136
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:56:47 2024 +0100 enable autoformat commit1f343606ec
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:42:14 2024 +0100 Squashed commit of the following: commitf5cf7b2e78
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:36:57 2024 +0100 fixed reqs commit9d845bee98
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:32:35 2024 +0100 disable autofix/format commitaff5f27148
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:28:50 2024 +0100 adjust checks commit47271cf1ef
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:28:22 2024 +0100 reorder order of operations commite1bf178b40
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:01:09 2024 +0100 adapted ruff settings to better fit code base commitad7d88a6f4
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:59:45 2024 +0100 auto fixed docstring commita2e54a760e
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:46:35 2024 +0100 fix getattr useage commitcb80c73bc6
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:25:09 2024 +0100 fix requirements file commitb7780bbd21
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:42:28 2024 +0100 fix removed sections commit71f1681f55
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:41:21 2024 +0100 fix djlint syntax commita0bcf1bcce
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:35:28 2024 +0100 remove flake8 from code base commit22475b31cc
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:34:56 2024 +0100 remove flake8 from code base commit0413350f14
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:24:39 2024 +0100 moved ruff section commitd90c48a0bf
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:24:24 2024 +0100 move djlint config to pyproject commitc5ce55d511
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:20:39 2024 +0100 added isort again commit42a41d23af
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:19:02 2024 +0100 move config section commit8569233181
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:17:52 2024 +0100 fix codespell error commit2897c6704d
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 17:29:21 2024 +0100 replaced flake8 with ruff mostly for speed improvements * enable docstring checks * fix docstrings * fixed D417 Missing argument description * Squashed commit of the following: commitd3b795824b
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 22:56:17 2024 +0100 fixed source path commit0bac0c19b8
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 22:47:53 2024 +0100 fixed req commit9f61f01d9c
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 22:45:18 2024 +0100 added missing toml req commit91b71ed24a
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:49:50 2024 +0100 moved isort config commit12460b0419
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:43:22 2024 +0100 remove flake8 section from setup.cfg commitf5cf7b2e78
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:36:57 2024 +0100 fixed reqs commit9d845bee98
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:32:35 2024 +0100 disable autofix/format commitaff5f27148
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:28:50 2024 +0100 adjust checks commit47271cf1ef
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:28:22 2024 +0100 reorder order of operations commite1bf178b40
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 20:01:09 2024 +0100 adapted ruff settings to better fit code base commitad7d88a6f4
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:59:45 2024 +0100 auto fixed docstring commita2e54a760e
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:46:35 2024 +0100 fix getattr useage commitcb80c73bc6
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 19:25:09 2024 +0100 fix requirements file commitb7780bbd21
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:42:28 2024 +0100 fix removed sections commit71f1681f55
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:41:21 2024 +0100 fix djlint syntax commita0bcf1bcce
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:35:28 2024 +0100 remove flake8 from code base commit22475b31cc
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:34:56 2024 +0100 remove flake8 from code base commit0413350f14
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:24:39 2024 +0100 moved ruff section commitd90c48a0bf
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:24:24 2024 +0100 move djlint config to pyproject commitc5ce55d511
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:20:39 2024 +0100 added isort again commit42a41d23af
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:19:02 2024 +0100 move config section commit8569233181
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 18:17:52 2024 +0100 fix codespell error commit2897c6704d
Author: Matthias Mair <code@mjmair.com> Date: Sun Jan 7 17:29:21 2024 +0100 replaced flake8 with ruff mostly for speed improvements * fix pyproject * make docstrings more uniform * auto-format * fix order * revert url change
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
"""Admin functionality for the 'label' app"""
|
||||
"""Admin functionality for the 'label' app."""
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
@ -6,7 +6,7 @@ import label.models
|
||||
|
||||
|
||||
class LabelAdmin(admin.ModelAdmin):
|
||||
"""Admin class for the various label models"""
|
||||
"""Admin class for the various label models."""
|
||||
|
||||
list_display = ('name', 'description', 'label', 'filters', 'enabled')
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""API functionality for the 'label' app"""
|
||||
"""API functionality for the 'label' app."""
|
||||
|
||||
from django.core.exceptions import FieldError, ValidationError
|
||||
from django.http import JsonResponse
|
||||
@ -42,7 +42,7 @@ class LabelFilterMixin:
|
||||
ITEM_KEY = 'item'
|
||||
|
||||
def get_items(self):
|
||||
"""Return a list of database objects from query parameter"""
|
||||
"""Return a list of database objects from query parameter."""
|
||||
ids = []
|
||||
|
||||
# Construct a list of possible query parameter value options
|
||||
@ -140,7 +140,7 @@ class LabelPrintMixin(LabelFilterMixin):
|
||||
|
||||
@method_decorator(never_cache)
|
||||
def dispatch(self, *args, **kwargs):
|
||||
"""Prevent caching when printing report templates"""
|
||||
"""Prevent caching when printing report templates."""
|
||||
return super().dispatch(*args, **kwargs)
|
||||
|
||||
def get_serializer(self, *args, **kwargs):
|
||||
@ -160,7 +160,7 @@ class LabelPrintMixin(LabelFilterMixin):
|
||||
return serializer
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""Perform a GET request against this endpoint to print labels"""
|
||||
"""Perform a GET request against this endpoint to print labels."""
|
||||
common.models.InvenTreeUserSetting.set_setting(
|
||||
'DEFAULT_' + self.ITEM_KEY.upper() + '_LABEL_TEMPLATE',
|
||||
self.get_object().pk,
|
||||
@ -170,7 +170,7 @@ class LabelPrintMixin(LabelFilterMixin):
|
||||
return self.print(request, self.get_items())
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""Perform a GET request against this endpoint to print labels"""
|
||||
"""Perform a GET request against this endpoint to print labels."""
|
||||
return self.get(request, *args, **kwargs)
|
||||
|
||||
def get_plugin(self, request):
|
||||
@ -245,7 +245,7 @@ class LabelPrintMixin(LabelFilterMixin):
|
||||
|
||||
|
||||
class StockItemLabelMixin:
|
||||
"""Mixin for StockItemLabel endpoints"""
|
||||
"""Mixin for StockItemLabel endpoints."""
|
||||
|
||||
queryset = label.models.StockItemLabel.objects.all()
|
||||
serializer_class = label.serializers.StockItemLabelSerializer
|
||||
@ -280,7 +280,7 @@ class StockItemLabelPrint(StockItemLabelMixin, LabelPrintMixin, RetrieveAPI):
|
||||
|
||||
|
||||
class StockLocationLabelMixin:
|
||||
"""Mixin for StockLocationLabel endpoints"""
|
||||
"""Mixin for StockLocationLabel endpoints."""
|
||||
|
||||
queryset = label.models.StockLocationLabel.objects.all()
|
||||
serializer_class = label.serializers.StockLocationLabelSerializer
|
||||
@ -315,7 +315,7 @@ class StockLocationLabelPrint(StockLocationLabelMixin, LabelPrintMixin, Retrieve
|
||||
|
||||
|
||||
class PartLabelMixin:
|
||||
"""Mixin for PartLabel endpoints"""
|
||||
"""Mixin for PartLabel endpoints."""
|
||||
|
||||
queryset = label.models.PartLabel.objects.all()
|
||||
serializer_class = label.serializers.PartLabelSerializer
|
||||
@ -343,7 +343,7 @@ class PartLabelPrint(PartLabelMixin, LabelPrintMixin, RetrieveAPI):
|
||||
|
||||
|
||||
class BuildLineLabelMixin:
|
||||
"""Mixin class for BuildLineLabel endpoints"""
|
||||
"""Mixin class for BuildLineLabel endpoints."""
|
||||
|
||||
queryset = label.models.BuildLineLabel.objects.all()
|
||||
serializer_class = label.serializers.BuildLineLabelSerializer
|
||||
@ -353,19 +353,19 @@ class BuildLineLabelMixin:
|
||||
|
||||
|
||||
class BuildLineLabelList(BuildLineLabelMixin, LabelListView):
|
||||
"""API endpoint for viewing a list of BuildLineLabel objects"""
|
||||
"""API endpoint for viewing a list of BuildLineLabel objects."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class BuildLineLabelDetail(BuildLineLabelMixin, RetrieveUpdateDestroyAPI):
|
||||
"""API endpoint for a single BuildLineLabel object"""
|
||||
"""API endpoint for a single BuildLineLabel object."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class BuildLineLabelPrint(BuildLineLabelMixin, LabelPrintMixin, RetrieveAPI):
|
||||
"""API endpoint for printing a BuildLineLabel object"""
|
||||
"""API endpoint for printing a BuildLineLabel object."""
|
||||
|
||||
pass
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""label app specification"""
|
||||
"""label app specification."""
|
||||
|
||||
import hashlib
|
||||
import logging
|
||||
@ -29,7 +29,7 @@ def hashFile(filename):
|
||||
|
||||
|
||||
class LabelConfig(AppConfig):
|
||||
"""App configuration class for the 'label' app"""
|
||||
"""App configuration class for the 'label' app."""
|
||||
|
||||
name = 'label'
|
||||
|
||||
|
@ -48,28 +48,28 @@ def rename_label_output(instance, filename):
|
||||
|
||||
|
||||
def validate_stock_item_filters(filters):
|
||||
"""Validate query filters for the StockItemLabel model"""
|
||||
"""Validate query filters for the StockItemLabel model."""
|
||||
filters = validateFilterString(filters, model=stock.models.StockItem)
|
||||
|
||||
return filters
|
||||
|
||||
|
||||
def validate_stock_location_filters(filters):
|
||||
"""Validate query filters for the StockLocationLabel model"""
|
||||
"""Validate query filters for the StockLocationLabel model."""
|
||||
filters = validateFilterString(filters, model=stock.models.StockLocation)
|
||||
|
||||
return filters
|
||||
|
||||
|
||||
def validate_part_filters(filters):
|
||||
"""Validate query filters for the PartLabel model"""
|
||||
"""Validate query filters for the PartLabel model."""
|
||||
filters = validateFilterString(filters, model=part.models.Part)
|
||||
|
||||
return filters
|
||||
|
||||
|
||||
def validate_build_line_filters(filters):
|
||||
"""Validate query filters for the BuildLine model"""
|
||||
"""Validate query filters for the BuildLine model."""
|
||||
filters = validateFilterString(filters, model=build.models.BuildLine)
|
||||
|
||||
return filters
|
||||
@ -82,7 +82,7 @@ class WeasyprintLabelMixin(WeasyTemplateResponseMixin):
|
||||
pdf_attachment = True
|
||||
|
||||
def __init__(self, request, template, **kwargs):
|
||||
"""Initialize a label mixin with certain properties"""
|
||||
"""Initialize a label mixin with certain properties."""
|
||||
self.request = request
|
||||
self.template_name = template
|
||||
self.pdf_filename = kwargs.get('filename', 'label.pdf')
|
||||
@ -104,11 +104,11 @@ class LabelTemplate(MetadataMixin, models.Model):
|
||||
|
||||
@property
|
||||
def template(self):
|
||||
"""Return the file path of the template associated with this label instance"""
|
||||
"""Return the file path of the template associated with this label instance."""
|
||||
return self.label.path
|
||||
|
||||
def __str__(self):
|
||||
"""Format a string representation of a label instance"""
|
||||
"""Format a string representation of a label instance."""
|
||||
return f'{self.name} - {self.description}'
|
||||
|
||||
name = models.CharField(
|
||||
@ -196,7 +196,6 @@ class LabelTemplate(MetadataMixin, models.Model):
|
||||
|
||||
This is inserted at the top of the style block for a given label
|
||||
"""
|
||||
|
||||
width = kwargs.get('width', self.width)
|
||||
height = kwargs.get('height', self.height)
|
||||
margin = kwargs.get('margin', 0)
|
||||
@ -215,7 +214,6 @@ class LabelTemplate(MetadataMixin, models.Model):
|
||||
request: The HTTP request object
|
||||
kwargs: Additional keyword arguments
|
||||
"""
|
||||
|
||||
context = self.get_context_data(request)
|
||||
|
||||
# By default, each label is supplied with '@page' data
|
||||
@ -242,8 +240,7 @@ class LabelTemplate(MetadataMixin, models.Model):
|
||||
return context
|
||||
|
||||
def render_as_string(self, request, target_object=None, **kwargs):
|
||||
"""Render the label to a HTML string"""
|
||||
|
||||
"""Render the label to a HTML string."""
|
||||
if target_object:
|
||||
self.object_to_print = target_object
|
||||
|
||||
@ -256,7 +253,6 @@ class LabelTemplate(MetadataMixin, models.Model):
|
||||
|
||||
Uses django-weasyprint plugin to render HTML template
|
||||
"""
|
||||
|
||||
if target_object:
|
||||
self.object_to_print = target_object
|
||||
|
||||
@ -275,7 +271,7 @@ class LabelTemplate(MetadataMixin, models.Model):
|
||||
|
||||
|
||||
class LabelOutput(models.Model):
|
||||
"""Class representing a label output file
|
||||
"""Class representing a label output file.
|
||||
|
||||
'Printing' a label may generate a file object (such as PDF)
|
||||
which is made available for download.
|
||||
@ -301,7 +297,7 @@ class StockItemLabel(LabelTemplate):
|
||||
|
||||
@staticmethod
|
||||
def get_api_url():
|
||||
"""Return the API URL associated with the StockItemLabel model"""
|
||||
"""Return the API URL associated with the StockItemLabel model."""
|
||||
return reverse('api-stockitem-label-list') # pragma: no cover
|
||||
|
||||
SUBDIR = 'stockitem'
|
||||
@ -340,7 +336,7 @@ class StockLocationLabel(LabelTemplate):
|
||||
|
||||
@staticmethod
|
||||
def get_api_url():
|
||||
"""Return the API URL associated with the StockLocationLabel model"""
|
||||
"""Return the API URL associated with the StockLocationLabel model."""
|
||||
return reverse('api-stocklocation-label-list') # pragma: no cover
|
||||
|
||||
SUBDIR = 'stocklocation'
|
||||
@ -365,7 +361,7 @@ class PartLabel(LabelTemplate):
|
||||
|
||||
@staticmethod
|
||||
def get_api_url():
|
||||
"""Return the API url associated with the PartLabel model"""
|
||||
"""Return the API url associated with the PartLabel model."""
|
||||
return reverse('api-part-label-list') # pragma: no cover
|
||||
|
||||
SUBDIR = 'part'
|
||||
@ -396,11 +392,11 @@ class PartLabel(LabelTemplate):
|
||||
|
||||
|
||||
class BuildLineLabel(LabelTemplate):
|
||||
"""Template for printing labels against BuildLine objects"""
|
||||
"""Template for printing labels against BuildLine objects."""
|
||||
|
||||
@staticmethod
|
||||
def get_api_url():
|
||||
"""Return the API URL associated with the BuildLineLabel model"""
|
||||
"""Return the API URL associated with the BuildLineLabel model."""
|
||||
return reverse('api-buildline-label-list')
|
||||
|
||||
SUBDIR = 'buildline'
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""API serializers for the label app"""
|
||||
"""API serializers for the label app."""
|
||||
|
||||
import label.models
|
||||
from InvenTree.serializers import (
|
||||
@ -8,13 +8,13 @@ from InvenTree.serializers import (
|
||||
|
||||
|
||||
class LabelSerializerBase(InvenTreeModelSerializer):
|
||||
"""Base class for label serializer"""
|
||||
"""Base class for label serializer."""
|
||||
|
||||
label = InvenTreeAttachmentSerializerField(required=True)
|
||||
|
||||
@staticmethod
|
||||
def label_fields():
|
||||
"""Generic serializer fields for a label template"""
|
||||
"""Generic serializer fields for a label template."""
|
||||
return ['pk', 'name', 'description', 'label', 'filters', 'enabled']
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ class PartLabelSerializer(LabelSerializerBase):
|
||||
|
||||
|
||||
class BuildLineLabelSerializer(LabelSerializerBase):
|
||||
"""Serializes a BuildLineLabel object"""
|
||||
"""Serializes a BuildLineLabel object."""
|
||||
|
||||
class Meta:
|
||||
"""Metaclass options."""
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""Background tasks for the label app"""
|
||||
"""Background tasks for the label app."""
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
@ -10,6 +10,6 @@ from label.models import LabelOutput
|
||||
|
||||
@scheduled_task(ScheduledTask.DAILY)
|
||||
def cleanup_old_label_outputs():
|
||||
"""Remove old label outputs from the database"""
|
||||
"""Remove old label outputs from the database."""
|
||||
# Remove any label outputs which are older than 30 days
|
||||
LabelOutput.objects.filter(created__lte=timezone.now() - timedelta(days=5)).delete()
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""Unit tests for label API"""
|
||||
"""Unit tests for label API."""
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
@ -15,7 +15,7 @@ class TestReportTests(InvenTreeAPITestCase):
|
||||
list_url = reverse('api-stockitem-testreport-list')
|
||||
|
||||
def do_list(self, filters=None):
|
||||
"""Helper function to request list of labels with provided filters"""
|
||||
"""Helper function to request list of labels with provided filters."""
|
||||
# Set default - see B006
|
||||
if filters is None:
|
||||
filters = {}
|
||||
@ -27,7 +27,7 @@ class TestReportTests(InvenTreeAPITestCase):
|
||||
return response.data
|
||||
|
||||
def test_list(self):
|
||||
"""Test the API list endpoint"""
|
||||
"""Test the API list endpoint."""
|
||||
response = self.do_list()
|
||||
|
||||
# TODO - Add some report templates to the fixtures
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""Tests for labels"""
|
||||
"""Tests for labels."""
|
||||
|
||||
import io
|
||||
import json
|
||||
@ -22,13 +22,13 @@ from .models import PartLabel, StockItemLabel, StockLocationLabel
|
||||
|
||||
|
||||
class LabelTest(InvenTreeAPITestCase):
|
||||
"""Unit test class for label models"""
|
||||
"""Unit test class for label models."""
|
||||
|
||||
fixtures = ['category', 'part', 'location', 'stock']
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
"""Ensure that some label instances exist as part of init routine"""
|
||||
"""Ensure that some label instances exist as part of init routine."""
|
||||
super().setUpTestData()
|
||||
apps.get_app_config('label').create_labels()
|
||||
|
||||
|
Reference in New Issue
Block a user