2022-10-25 04:57:34 +00:00
|
|
|
from rest_framework import serializers
|
2022-10-25 11:31:13 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2022-11-03 08:55:38 +00:00
|
|
|
from django.db import models
|
2022-10-25 04:57:34 +00:00
|
|
|
|
2022-10-25 11:31:13 +00:00
|
|
|
from common.drf.fields import ObjectRelatedField, LabeledChoiceField
|
2022-11-01 12:37:04 +00:00
|
|
|
from ..models import Applet, AppletPublication, AppletHost
|
2022-10-25 04:57:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'AppletSerializer', 'AppletPublicationSerializer',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class AppletPublicationSerializer(serializers.ModelSerializer):
|
2022-11-03 08:55:38 +00:00
|
|
|
class Status(models.TextChoices):
|
|
|
|
PUBLISHED = 'published', _('Published')
|
|
|
|
UNPUBLISHED = 'unpublished', _('Unpublished')
|
|
|
|
NOT_MATCH = 'not_match', _('Not match')
|
|
|
|
|
2022-11-07 12:41:18 +00:00
|
|
|
applet = ObjectRelatedField(attrs=('id', 'name', 'display_name', 'icon', 'version'), queryset=Applet.objects.all())
|
2022-10-25 04:57:34 +00:00
|
|
|
host = ObjectRelatedField(queryset=AppletHost.objects.all())
|
2022-11-02 03:08:13 +00:00
|
|
|
status = LabeledChoiceField(choices=Status.choices, label=_("Status"))
|
2022-10-25 04:57:34 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AppletPublication
|
|
|
|
fields_mini = ['id', 'applet', 'host']
|
|
|
|
read_only_fields = ['date_created', 'date_updated']
|
2022-11-02 03:08:13 +00:00
|
|
|
fields = fields_mini + ['status', 'comment'] + read_only_fields
|
2022-10-25 04:57:34 +00:00
|
|
|
|
|
|
|
|
2022-11-01 12:37:04 +00:00
|
|
|
class AppletSerializer(serializers.ModelSerializer):
|
|
|
|
icon = serializers.ReadOnlyField(label=_("Icon"))
|
|
|
|
type = LabeledChoiceField(choices=Applet.Type.choices, label=_("Type"))
|
2022-11-01 03:52:51 +00:00
|
|
|
|
|
|
|
class Meta:
|
2022-11-01 12:37:04 +00:00
|
|
|
model = Applet
|
|
|
|
fields_mini = ['id', 'name', 'display_name']
|
2022-11-01 03:52:51 +00:00
|
|
|
read_only_fields = [
|
2022-11-02 06:13:45 +00:00
|
|
|
'icon', 'date_created', 'date_updated',
|
2022-11-01 03:52:51 +00:00
|
|
|
]
|
2022-11-01 12:37:04 +00:00
|
|
|
fields = fields_mini + [
|
|
|
|
'version', 'author', 'type', 'protocols',
|
|
|
|
'tags', 'comment'
|
|
|
|
] + read_only_fields
|