mirror of
https://github.com/inventree/InvenTree.git
synced 2026-10-02 00:20:44 +00:00
* add generic api helper * align name better * fix name change * allign returncodes and internal names * fix serializer class assumptions * remove now unneeded serializers * fix parameter mixin handeling * fix context parsing * bump API version * add transition overview * fix serializer augumentation * remove dead code * change path prefix back * extend test for introspection * add legacy warning again * check permissions for introspection endpoint (allowed indirect discovery of state) * add sample * helpers for complex and well described endpoints * add more testing for state features shipped with common * fix tests * remove problematic many2many that does not work without database model * remove samples; will be submitted as a larger sample app * Update api_helpers.py
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""Serializer classes for handling generic state information."""
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
class GenericStateValueSerializer(serializers.Serializer):
|
|
"""API serializer for generic state information."""
|
|
|
|
class Meta:
|
|
"""Meta class for GenericStateValueSerializer."""
|
|
|
|
fields = ['key', 'logical_key', 'name', 'label', 'color', 'custom']
|
|
|
|
key = serializers.IntegerField(label=_('Key'), required=True)
|
|
|
|
logical_key = serializers.CharField(label=_('Logical Key'), required=False)
|
|
|
|
name = serializers.CharField(label=_('Name'), required=True)
|
|
|
|
label = serializers.CharField(label=_('Label'), required=True)
|
|
|
|
color = serializers.CharField(label=_('Color'), required=False)
|
|
|
|
custom = serializers.BooleanField(label=_('Custom'), required=False)
|
|
|
|
|
|
class GenericStateClassSerializer(serializers.Serializer):
|
|
"""API serializer for generic state class information."""
|
|
|
|
class Meta:
|
|
"""Meta class for GenericStateClassSerializer."""
|
|
|
|
fields = ['status_class', 'values']
|
|
|
|
status_class = serializers.CharField(label=_('Class'), read_only=True)
|
|
|
|
values = serializers.DictField(
|
|
child=GenericStateValueSerializer(), label=_('Values'), required=True
|
|
)
|
|
|
|
|
|
class AvailableTransitionSerializer(serializers.Serializer):
|
|
"""Listing of available transitions for a given object."""
|
|
|
|
name = serializers.CharField(read_only=True)
|
|
url_path = serializers.CharField(read_only=True)
|
|
target = serializers.CharField(read_only=True)
|
|
label = serializers.CharField(read_only=True)
|
|
blocked = serializers.BooleanField(read_only=True)
|
|
blocking_reason = serializers.CharField(read_only=True, allow_null=True)
|