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", )
class TestModelSerializer(TaggitSerializer, serializers.ModelSerializer): tags = TagListSerializerField() class Meta: model = TestModel fields = "__all__"
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")
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"] }), }
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"] }), }
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"]
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"]
class TestModelSerializer(TaggitSerializer, serializers.ModelSerializer): tags = TagListSerializerField() class Meta: model = TestModel if django.VERSION >= (1, 11): fields = "__all__"
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' ]
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"] }), }
class BookmarkSerializer(TaggitSerializer, serializers.ModelSerializer): tags = TagListSerializerField() class Meta: model = Bookmark fields = ( 'title', 'description', 'date_added', 'tags', 'private', 'url', )
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
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
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
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", )
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
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", )
class TaggableSerializer(TaggitSerializer, serializers.HyperlinkedModelSerializer): tags = TagListSerializerField(required=False)
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"]), ]