1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-28 14:32:26 +00:00
bramw_baserow/backend/src/baserow/contrib/builder/api/pages/serializers.py
2023-04-11 13:41:43 +00:00

56 lines
1.7 KiB
Python

from rest_framework import serializers
from baserow.contrib.builder.pages.constants import PAGE_PATH_PARAM_TYPE_CHOICES
from baserow.contrib.builder.pages.models import Page
from baserow.contrib.builder.pages.validators import path_param_name_validation
class PathParamSerializer(serializers.Serializer):
name = serializers.CharField(
required=True,
validators=[path_param_name_validation],
help_text="The name of the parameter.",
max_length=255,
)
type = serializers.ChoiceField(
choices=PAGE_PATH_PARAM_TYPE_CHOICES, help_text="The type of the parameter."
)
class PageSerializer(serializers.ModelSerializer):
path_params = PathParamSerializer(many=True, required=False)
class Meta:
model = Page
fields = ("id", "name", "path", "path_params", "order", "builder_id")
extra_kwargs = {
"id": {"read_only": True},
"builder_id": {"read_only": True},
"order": {"help_text": "Lowest first."},
}
class CreatePageSerializer(serializers.ModelSerializer):
path_params = PathParamSerializer(many=True, required=False)
class Meta:
model = Page
fields = ("name", "path", "path_params")
class UpdatePageSerializer(serializers.ModelSerializer):
path_params = PathParamSerializer(many=True, required=False)
class Meta:
model = Page
fields = ("name", "path", "path_params")
extra_kwargs = {"name": {"required": False}, "path": {"required": False}}
class OrderPagesSerializer(serializers.Serializer):
page_ids = serializers.ListField(
child=serializers.IntegerField(),
help_text="The ids of the pages in the order they are supposed to be set in",
)