mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	versioning for the tags API
This commit is contained in:
		| @@ -88,7 +88,40 @@ class DocumentTypeSerializer(MatchingModelSerializer): | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class TagSerializer(MatchingModelSerializer): | ||||
| class ColorField(serializers.Field): | ||||
|  | ||||
|     COLOURS = ( | ||||
|         (1, "#a6cee3"), | ||||
|         (2, "#1f78b4"), | ||||
|         (3, "#b2df8a"), | ||||
|         (4, "#33a02c"), | ||||
|         (5, "#fb9a99"), | ||||
|         (6, "#e31a1c"), | ||||
|         (7, "#fdbf6f"), | ||||
|         (8, "#ff7f00"), | ||||
|         (9, "#cab2d6"), | ||||
|         (10, "#6a3d9a"), | ||||
|         (11, "#b15928"), | ||||
|         (12, "#000000"), | ||||
|         (13, "#cccccc") | ||||
|     ) | ||||
|  | ||||
|     def to_internal_value(self, data): | ||||
|         for id, color in self.COLOURS: | ||||
|             if id == data: | ||||
|                 return color | ||||
|         return "#a6cee3" | ||||
|  | ||||
|     def to_representation(self, value): | ||||
|         for id, color in self.COLOURS: | ||||
|             if color == value: | ||||
|                 return id | ||||
|         return 1 | ||||
|  | ||||
|  | ||||
| class TagSerializerVersion1(MatchingModelSerializer): | ||||
|  | ||||
|     colour = ColorField(source='color') | ||||
|  | ||||
|     class Meta: | ||||
|         model = Tag | ||||
| @@ -105,6 +138,23 @@ class TagSerializer(MatchingModelSerializer): | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class TagSerializer(MatchingModelSerializer): | ||||
|  | ||||
|     class Meta: | ||||
|         model = Tag | ||||
|         fields = ( | ||||
|             "id", | ||||
|             "slug", | ||||
|             "name", | ||||
|             "color", | ||||
|             "match", | ||||
|             "matching_algorithm", | ||||
|             "is_insensitive", | ||||
|             "is_inbox_tag", | ||||
|             "document_count" | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class CorrespondentField(serializers.PrimaryKeyRelatedField): | ||||
|     def get_queryset(self): | ||||
|         return Correspondent.objects.all() | ||||
|   | ||||
| @@ -50,6 +50,7 @@ from .parsers import get_parser_class_for_mime_type | ||||
| from .serialisers import ( | ||||
|     CorrespondentSerializer, | ||||
|     DocumentSerializer, | ||||
|     TagSerializerVersion1, | ||||
|     TagSerializer, | ||||
|     DocumentTypeSerializer, | ||||
|     PostDocumentSerializer, | ||||
| @@ -118,7 +119,12 @@ class TagViewSet(ModelViewSet): | ||||
|     queryset = Tag.objects.annotate( | ||||
|         document_count=Count('documents')).order_by(Lower('name')) | ||||
|  | ||||
|     serializer_class = TagSerializer | ||||
|     def get_serializer_class(self): | ||||
|         if int(self.request.version) == 1: | ||||
|             return TagSerializerVersion1 | ||||
|         else: | ||||
|             return TagSerializer | ||||
|  | ||||
|     pagination_class = StandardPagination | ||||
|     permission_classes = (IsAuthenticated,) | ||||
|     filter_backends = (DjangoFilterBackend, OrderingFilter) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler