Skip to content

Commit

Permalink
Merge branch 'master' into return-status
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat authored Nov 27, 2024
2 parents 92db895 + af39189 commit d949d93
Show file tree
Hide file tree
Showing 28 changed files with 1,278 additions and 11 deletions.
10 changes: 10 additions & 0 deletions docs/docs/part/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Parameter templates are used to define the different types of parameters which a
| Units | Optional units field (*must be a valid [physical unit](#parameter-units)*) |
| Choices | A comma-separated list of valid choices for parameter values linked to this template. |
| Checkbox | If set, parameters linked to this template can only be assigned values *true* or *false* |
| Selection List | If set, parameters linked to this template can only be assigned values from the linked [selection list](#selection-lists) |

### Create Template

Expand Down Expand Up @@ -105,3 +106,12 @@ Parameter sorting takes unit conversion into account, meaning that values provid
{% with id="sort_by_param_units", url="part/part_sorting_units.png", description="Sort by Parameter Units" %}
{% include 'img.html' %}
{% endwith %}

### Selection Lists

Selection Lists can be used to add a large number of predefined values to a parameter template. This can be useful for parameters which must be selected from a large predefined list of values (e.g. a list of standardised colo codes). Choices on templates are limited to 5000 characters, selection lists can be used to overcome this limitation.

It is possible that plugins lock selection lists to ensure a known state.


Administration of lists can be done through the Part Parameter section in the Admin Center or via the API.
5 changes: 4 additions & 1 deletion src/backend/InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""InvenTree API version information."""

# InvenTree API version
INVENTREE_API_VERSION = 285
INVENTREE_API_VERSION = 286

"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""


INVENTREE_API_TEXT = """
v286 - 2024-11-26 : https://github.com/inventree/InvenTree/pull/8054
- Adds "SelectionList" and "SelectionListEntry" API endpoints
v285 - 2024-11-25 : https://github.com/inventree/InvenTree/pull/8559
- Adds better description for registration endpoints
Expand Down
78 changes: 78 additions & 0 deletions src/backend/InvenTree/common/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,82 @@ def get_queryset(self):
return get_icon_packs().values()


class SelectionListList(ListCreateAPI):
"""List view for SelectionList objects."""

queryset = common.models.SelectionList.objects.all()
serializer_class = common.serializers.SelectionListSerializer
permission_classes = [permissions.IsAuthenticated]

def get_queryset(self):
"""Override the queryset method to include entry count."""
return self.serializer_class.annotate_queryset(super().get_queryset())


class SelectionListDetail(RetrieveUpdateDestroyAPI):
"""Detail view for a SelectionList object."""

queryset = common.models.SelectionList.objects.all()
serializer_class = common.serializers.SelectionListSerializer
permission_classes = [permissions.IsAuthenticated]


class EntryMixin:
"""Mixin for SelectionEntry views."""

queryset = common.models.SelectionListEntry.objects.all()
serializer_class = common.serializers.SelectionEntrySerializer
permission_classes = [permissions.IsAuthenticated]
lookup_url_kwarg = 'entrypk'

def get_queryset(self):
"""Prefetch related fields."""
pk = self.kwargs.get('pk', None)
queryset = super().get_queryset().filter(list=pk)
queryset = queryset.prefetch_related('list')
return queryset


class SelectionEntryList(EntryMixin, ListCreateAPI):
"""List view for SelectionEntry objects."""


class SelectionEntryDetail(EntryMixin, RetrieveUpdateDestroyAPI):
"""Detail view for a SelectionEntry object."""


selection_urls = [
path(
'<int:pk>/',
include([
# Entries
path(
'entry/',
include([
path(
'<int:entrypk>/',
include([
path(
'',
SelectionEntryDetail.as_view(),
name='api-selectionlistentry-detail',
)
]),
),
path(
'',
SelectionEntryList.as_view(),
name='api-selectionlistentry-list',
),
]),
),
path('', SelectionListDetail.as_view(), name='api-selectionlist-detail'),
]),
),
path('', SelectionListList.as_view(), name='api-selectionlist-list'),
]

# API URL patterns
settings_api_urls = [
# User settings
path(
Expand Down Expand Up @@ -1016,6 +1092,8 @@ def get_queryset(self):
),
# Icons
path('icons/', IconList.as_view(), name='api-icon-list'),
# Selection lists
path('selection/', include(selection_urls)),
]

admin_api_urls = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Generated by Django 4.2.16 on 2024-11-24 12:41

import django.db.models.deletion
from django.db import migrations, models

import InvenTree.models


class Migration(migrations.Migration):
dependencies = [
('plugin', '0009_alter_pluginconfig_key'),
('common', '0031_auto_20241026_0024'),
]

operations = [
migrations.CreateModel(
name='SelectionList',
fields=[
(
'id',
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
),
),
(
'metadata',
models.JSONField(
blank=True,
help_text='JSON metadata field, for use by external plugins',
null=True,
verbose_name='Plugin Metadata',
),
),
(
'name',
models.CharField(
help_text='Name of the selection list',
max_length=100,
unique=True,
verbose_name='Name',
),
),
(
'description',
models.CharField(
blank=True,
help_text='Description of the selection list',
max_length=250,
verbose_name='Description',
),
),
(
'locked',
models.BooleanField(
default=False,
help_text='Is this selection list locked?',
verbose_name='Locked',
),
),
(
'active',
models.BooleanField(
default=True,
help_text='Can this selection list be used?',
verbose_name='Active',
),
),
(
'source_string',
models.CharField(
blank=True,
help_text='Optional string identifying the source used for this list',
max_length=1000,
verbose_name='Source String',
),
),
(
'created',
models.DateTimeField(
auto_now_add=True,
help_text='Date and time that the selection list was created',
verbose_name='Created',
),
),
(
'last_updated',
models.DateTimeField(
auto_now=True,
help_text='Date and time that the selection list was last updated',
verbose_name='Last Updated',
),
),
],
options={
'verbose_name': 'Selection List',
'verbose_name_plural': 'Selection Lists',
},
bases=(InvenTree.models.PluginValidationMixin, models.Model),
),
migrations.CreateModel(
name='SelectionListEntry',
fields=[
(
'id',
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
),
),
(
'value',
models.CharField(
help_text='Value of the selection list entry',
max_length=255,
verbose_name='Value',
),
),
(
'label',
models.CharField(
help_text='Label for the selection list entry',
max_length=255,
verbose_name='Label',
),
),
(
'description',
models.CharField(
blank=True,
help_text='Description of the selection list entry',
max_length=250,
verbose_name='Description',
),
),
(
'active',
models.BooleanField(
default=True,
help_text='Is this selection list entry active?',
verbose_name='Active',
),
),
(
'list',
models.ForeignKey(
blank=True,
help_text='Selection list to which this entry belongs',
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name='entries',
to='common.selectionlist',
verbose_name='Selection List',
),
),
],
options={
'verbose_name': 'Selection List Entry',
'verbose_name_plural': 'Selection List Entries',
'unique_together': {('list', 'value')},
},
),
migrations.AddField(
model_name='selectionlist',
name='default',
field=models.ForeignKey(
blank=True,
help_text='Default entry for this selection list',
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to='common.selectionlistentry',
verbose_name='Default Entry',
),
),
migrations.AddField(
model_name='selectionlist',
name='source_plugin',
field=models.ForeignKey(
blank=True,
help_text='Plugin which provides the selection list',
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to='plugin.pluginconfig',
verbose_name='Source Plugin',
),
),
]
Loading

0 comments on commit d949d93

Please sign in to comment.