A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
add text color generation based on luminance
jonaswinkler7cc940a16c66
diff --git a/src/documents/serialisers.py b/src/documents/serialisers.pyindex e6aef3627..4d52f496b 100644--- a/src/documents/serialisers.py+++ b/src/documents/serialisers.py@@ -1,6 +1,7 @@import reimport magic+import mathfrom django.utils.text import slugifyfrom rest_framework import serializersfrom rest_framework.fields import SerializerMethodField@@ -140,6 +141,21 @@ class TagSerializerVersion1(MatchingModelSerializer):class TagSerializer(MatchingModelSerializer):+ def get_text_color(self, obj):+ if obj.color:+ h = obj.color.lstrip('#')+ rgb = tuple(int(h[i:i + 2], 16)/256 for i in (0, 2, 4))+ luminance = math.sqrt(+ 0.299 * math.pow(rgb[0], 2) ++ 0.587 * math.pow(rgb[1], 2) ++ 0.114 * math.pow(rgb[2], 2)+ )+ return "#ffffff" if luminance < 0.5 else "#000000"+ else:+ return "#000000"++ text_color = serializers.SerializerMethodField()+class Meta:model = Tagfields = (@@ -147,6 +163,7 @@ class TagSerializer(MatchingModelSerializer):"slug","name","color",+ "text_color","match","matching_algorithm","is_insensitive",