예제 #1
0
class ArticleSerializer(TaggitSerializer, serializers.ModelSerializer):
    created_by = UserReadOnlySerializer()
    image = ResponsiveImageSerializer()
    tags = TagListSerializerField()
    absolute_url = serializers.CharField(source="get_absolute_url",
                                         read_only=True)

    class Meta:
        model = Article
        fields = (
            "absolute_url",
            "authors",
            "created_by",
            "changed_date",
            "content",
            "created_date",
            "featured",
            "heading",
            "id",
            "ingress",
            "ingress_short",
            "published_date",
            "slug",
            "tags",
            "video",
            "image",
        )
예제 #2
0
class TestModelSerializer(TaggitSerializer, serializers.ModelSerializer):

    tags = TagListSerializerField()

    class Meta:
        model = TestModel
        fields = "__all__"
예제 #3
0
class PhotoCreateOrUpdateSerializer(serializers.ModelSerializer):
    photographer = serializers.PrimaryKeyRelatedField(
        queryset=User.objects.all(), required=False)
    title = serializers.CharField(required=False, default=None)
    tags = TagListSerializerField(required=False)
    raw_image = ImageField(required=True)
    album = serializers.PrimaryKeyRelatedField(queryset=Album.objects.all(),
                                               required=True)

    class Meta:
        model = Photo
        fields = (
            "id",
            "album",
            "relative_id",
            "image",
            "created_date",
            "title",
            "description",
            "tags",
            "raw_image",
            "photographer_name",
            "photographer",
        )
        read_only_fields = ("image", "created_date")
예제 #4
0
class EpicSerializer(TaggitSerializer, FlexFieldsModelSerializer):
    name = serializers.CharField(max_length=200,
                                 validators=[
                                     UniqueValidator(
                                         queryset=Epic.objects.all(),
                                         lookup="iexact")
                                 ])
    tags = TagListSerializerField()

    class Meta:
        model = Epic
        fields = ("id", "name", "description", "external_reference",
                  "num_of_user_stories", "current_progress", "tags")
        read_only_fields = (
            "id",
            "num_of_user_stories",
            "current_progress",
            "creation_datetime",
            "creation_user",
            "modification_datetime",
            "modification_user",
        )
        expandable_fields = {
            "tags": (TagSerializer, {
                "many": True,
                "fields": ["name", "colour", "icon"]
            }),
        }
예제 #5
0
class EventSerializer(TaggitSerializer, FlexFieldsModelSerializer):
    tags = TagListSerializerField()

    def validate_type(self, value):
        if value.system_slug:
            raise serializers.ValidationError(
                _("No es posible crear un evento con un tipo reservado al sistema"
                  ))
        return value

    def validate(self, data):
        data = super().validate(data)
        if data.get("end_datetime") < data.get("start_datetime"):
            raise serializers.ValidationError(
                _("No es posible crear un evento con fecha de fin anterior a la de inicio"
                  ))
        return data

    class Meta:
        model = Event
        fields = (
            "id",
            "name",
            "type",
            "details",
            "start_datetime",
            "end_datetime",
            "all_day",
            "visibility",
            "location",
            "attendees",
            "groups",
            "tags",
            "creation_datetime",
            "creation_user",
            "modification_datetime",
            "modification_user",
        )
        read_only_fields = (
            "id",
            "creation_datetime",
            "creation_user",
            "modification_datetime",
            "modification_user",
        )
        expandable_fields = {
            "type":
            EventTypeSerializer,
            "attendees": (UserSerializer, {
                "many": True
            }),
            "groups": (GroupSerializer, {
                "many": True
            }),
            "tags": (TagSerializer, {
                "many": True,
                "fields": ["name", "colour", "icon"]
            }),
        }
예제 #6
0
class ResourceGroupSerializerRead(TaggitSerializer, serializers.ModelSerializer):
    attribute_definitions = ResourceGroupTextAttributeDefinitionSerializerRead(many=True, read_only=True)
    text_attribute_definitions = ResourceGroupTextAttributeDefinitionSerializerRead(many=True, read_only=True)
    tags = TagListSerializerField()

    class Meta:
        model = ResourceGroup
        fields = ["id", "name", "attribute_definitions", "text_attribute_definitions", "tags"]
예제 #7
0
class SlideshowSerializer(serializers.ModelSerializer):
    title_image = PhotographSerializer(required=False)
    pages = SlideshowPageSerializer(exclude="show", many=True, required=False)
    categories = TagListSerializerField()

    class Meta:
        model = Slideshow
        exclude = ["active"]
예제 #8
0
class TestModelSerializer(TaggitSerializer, serializers.ModelSerializer):

    tags = TagListSerializerField()

    class Meta:
        model = TestModel
        if django.VERSION >= (1, 11):
            fields = "__all__"
예제 #9
0
class TrainingSerializer(serializers.ModelSerializer):

    tags = TagListSerializerField()

    class Meta:
        model = Training
        fields = [
            'id', 'title', 'year_published', 'trainer', 'url', 'date_started',
            'rating', 'is_complete', 'notes', 'source', 'category', 'tags'
        ]
예제 #10
0
class SprintSerializer(TaggitSerializer, FlexFieldsModelSerializer):
    name = serializers.CharField(max_length=200,
                                 validators=[
                                     UniqueValidator(
                                         queryset=Sprint.objects.all(),
                                         lookup="iexact")
                                 ])
    tags = TagListSerializerField()

    def validate_end_date(self, value):
        if self.instance and self.instance.user_stories.filter(
                end_date__gt=value).exists():
            raise serializers.ValidationError(
                _("El sprint contiene historias de usuario con una fecha de fin posterior a la del sprint"
                  ))
        return value

    def validate(self, data):
        data = super().validate(data)
        if data.get("end_date") < data.get("start_date"):
            raise serializers.ValidationError(
                _("Fecha de fin anterior a la de inicio"))
        return data

    class Meta:
        model = Sprint
        fields = (
            "id",
            "name",
            "start_date",
            "end_date",
            "ongoing",
            "accountable_user",
            "num_of_user_stories",
            "current_progress",
            "tags",
        )
        read_only_fields = (
            "id",
            "ongoing",
            "num_of_user_stories",
            "current_progress",
            "creation_datetime",
            "creation_user",
            "modification_datetime",
            "modification_user",
        )
        expandable_fields = {
            "accountable_user":
            UserSerializer,
            "tags": (TagSerializer, {
                "many": True,
                "fields": ["name", "colour", "icon"]
            }),
        }
예제 #11
0
class BookmarkSerializer(TaggitSerializer, serializers.ModelSerializer):
    tags = TagListSerializerField()

    class Meta:
        model = Bookmark
        fields = (
            'title',
            'description',
            'date_added',
            'tags',
            'private',
            'url',
        )
예제 #12
0
class TrainingFullSerializer(serializers.ModelSerializer):

    training_source = TrainingSourceSerializer(source='source', many=False)
    training_category = TrainingCategorySerializer(source='category',
                                                   many=False)

    tags = TagListSerializerField()

    class Meta:
        model = Training
        fields = [
            'id', 'title', 'year_published', 'trainer', 'url', 'date_started',
            'rating', 'is_complete', 'notes', 'training_source',
            'training_category', 'tags'
        ]
class ResourcePoolSerializer(TaggitSerializer, serializers.ModelSerializer):
    attribute_definitions = ResourcePoolAttributeDefinitionSerializerRead(
        many=True)
    tags = TagListSerializerField()

    class Meta:
        model = ResourcePool
        fields = ["id", "name", "attribute_definitions", "tags"]

    def create(self, validated_data):
        tags = validated_data.pop('tags')
        attribute_definitions_data = validated_data.pop(
            'attribute_definitions', [])
        resource_pool = ResourcePool.objects.create(**validated_data)
        resource_pool.tags.set(tags)
        for attribute_definition in attribute_definitions_data:
            resource_pool.add_attribute_definition(**attribute_definition)
        return resource_pool
예제 #14
0
class AlbumListSerializer(serializers.ModelSerializer):
    tags = TagListSerializerField()
    cover_photo = PhotoListSerializer()

    class Meta:
        model = Album
        fields = (
            "id",
            "title",
            "description",
            "created_date",
            "published_date",
            "tags",
            "public",
            "created_by",
            "cover_photo",
        )
        read_only = True
예제 #15
0
class ResourceGroupSerializer(TaggitSerializer, serializers.ModelSerializer):
    attribute_definitions = ResourceGroupAttributeDefinitionSerializerRead(many=True)
    text_attribute_definitions = ResourceGroupTextAttributeDefinitionSerializerRead(many=True)
    tags = TagListSerializerField()

    class Meta:
        model = ResourceGroup
        fields = ["id", "name", "attribute_definitions", "text_attribute_definitions", "tags"]

    def create(self, validated_data):
        tags = validated_data.pop('tags')
        attribute_definitions_data = validated_data.pop('attribute_definitions')
        text_attribute_definitions_data = validated_data.pop('text_attribute_definitions')
        resource_group = ResourceGroup.objects.create(**validated_data)
        resource_group.tags.set(tags)
        for attribute_definition in attribute_definitions_data:
            resource_group.add_attribute_definition(**attribute_definition)
        for text_attribute_definition in text_attribute_definitions_data:
            resource_group.add_text_attribute_definition(**text_attribute_definition)
        return resource_group
예제 #16
0
class AlbumCreateOrUpdateSerializer(serializers.ModelSerializer):
    created_by = serializers.HiddenField(
        default=serializers.CurrentUserDefault())
    tags = TagListSerializerField(required=False)
    cover_photo = PhotoRetrieveSerializer(required=False)
    published_date = serializers.DateTimeField(required=False)
    public = serializers.BooleanField(default=False)

    class Meta:
        model = Album
        fields = (
            "id",
            "title",
            "description",
            "created_date",
            "published_date",
            "tags",
            "public",
            "created_by",
            "cover_photo",
        )
예제 #17
0
class PhotoRetrieveSerializer(serializers.ModelSerializer):
    photographer = UserNameSerializer()
    tags = TagListSerializerField()
    image = ResponsiveImageSerializer()

    class Meta:
        model = Photo
        fields = (
            "id",
            "album",
            "relative_id",
            "image",
            "created_date",
            "title",
            "description",
            "tags",
            "photographer_name",
            "photographer",
            "user_tags",
        )
        read_only = True
예제 #18
0
class ResponsiveImageSerializer(TaggitSerializer, serializers.ModelSerializer):
    preset_display = serializers.CharField(source="get_preset_display")
    tags = TagListSerializerField()

    class Meta:
        model = ResponsiveImage
        fields = (
            "id",
            "name",
            "timestamp",
            "description",
            "thumb",
            "original",
            "wide",
            "lg",
            "md",
            "sm",
            "xs",
            "tags",
            "photographer",
            "preset",
            "preset_display",
        )
예제 #19
0
class TaggableSerializer(TaggitSerializer, serializers.HyperlinkedModelSerializer):
    tags = TagListSerializerField(required=False)
예제 #20
0
class UserStorySerializer(TaggitSerializer, FlexFieldsModelSerializer):
    tags = TagListSerializerField()

    def validate(self, data):
        data = super().validate(data)
        if data.get("end_date") and data.get(
                "start_date") and data["end_date"] < data["start_date"]:
            raise serializers.ValidationError(
                _("Fecha de fin anterior a la de inicio"))
        if data.get("sprint"):
            if not data.get("start_date") or not data.get("end_date"):
                raise serializers.ValidationError(
                    _("Es necesario asignar fechas a las historias de usuario asignadas a un sprint"
                      ))
            if data["end_date"] > data["sprint"].end_date:
                raise serializers.ValidationError(
                    _("La fecha de fin debe ser anterior a la del sprint"))
            if not data.get("development_user"):
                raise serializers.ValidationError(
                    _("No es posible incluir una historia de usuario en un sprint sin un responsable asignado."
                      ))
        return data

    class Meta:
        model = UserStory
        fields = (
            "id",
            "name",
            "type",
            "epic",
            "sprint",
            "functional_description",
            "technical_description",
            "external_resource",
            "start_date",
            "end_date",
            "current_progress",
            "current_progress_changed",
            "validated",
            "validated_changed",
            "status",
            "planned_effort",
            "actual_effort",
            "priority",
            "development_user",
            "development_comments",
            "validation_user",
            "validation_comments",
            "support_user",
            "support_comments",
            "cvs_reference",
            "risk_level",
            "risk_comments",
            "use_migrations",
            "deployment_notes",
            "tags",
            "creation_datetime",
            "creation_user",
            "modification_datetime",
            "modification_user",
        )
        read_only_fields = (
            "id",
            "creation_datetime",
            "creation_user",
            "modification_datetime",
            "modification_user",
            "current_progress",
            "current_progress_changed",
            "validated_changed",
            "status",
            "actual_effort",
            "creation_datetime",
            "creation_user",
            "modification_datetime",
            "modification_user",
        )
        expandable_fields = {
            "type":
            UserStoryTypeSerializer,
            "epic":
            EpicSerializer,
            "sprint":
            SprintSerializer,
            "development_user":
            UserSerializer,
            "validation_user":
            UserSerializer,
            "support_user":
            UserSerializer,
            "progress_log": (ProgressSerializer, {
                "many": True
            }),
            "effort_allocation": (EffortSerializer, {
                "many": True
            }),
            "creation_user":
            UserSerializer,
            "modification_user":
            UserSerializer,
            "tags": (TagSerializer, {
                "many": True,
                "fields": ["name", "colour", "icon"]
            }),
        }
        validators = [
            UniqueTogetherValidator(queryset=UserStory.objects.all(),
                                    fields=["name", "sprint"]),
            UniqueTogetherValidator(queryset=UserStory.objects.all(),
                                    fields=["name", "epic"]),
        ]