[WEB-5245] feat: auto-populate logo_props in project creation #8013
This commit is contained in:
parent
c4dd4bd02f
commit
1d4cde9ba0
1 changed files with 53 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
# Third party imports
|
# Third party imports
|
||||||
|
import random
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
|
|
@ -24,6 +25,47 @@ class ProjectCreateSerializer(BaseSerializer):
|
||||||
and workspace association for new project initialization.
|
and workspace association for new project initialization.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
PROJECT_ICON_DEFAULT_COLORS = [
|
||||||
|
"#95999f",
|
||||||
|
"#6d7b8a",
|
||||||
|
"#5e6ad2",
|
||||||
|
"#02b5ed",
|
||||||
|
"#02b55c",
|
||||||
|
"#f2be02",
|
||||||
|
"#e57a00",
|
||||||
|
"#f38e82",
|
||||||
|
]
|
||||||
|
PROJECT_ICON_DEFAULT_ICONS = [
|
||||||
|
"home",
|
||||||
|
"apps",
|
||||||
|
"settings",
|
||||||
|
"star",
|
||||||
|
"favorite",
|
||||||
|
"done",
|
||||||
|
"check_circle",
|
||||||
|
"add_task",
|
||||||
|
"create_new_folder",
|
||||||
|
"dataset",
|
||||||
|
"terminal",
|
||||||
|
"key",
|
||||||
|
"rocket",
|
||||||
|
"public",
|
||||||
|
"quiz",
|
||||||
|
"mood",
|
||||||
|
"gavel",
|
||||||
|
"eco",
|
||||||
|
"diamond",
|
||||||
|
"forest",
|
||||||
|
"bolt",
|
||||||
|
"sync",
|
||||||
|
"cached",
|
||||||
|
"library_add",
|
||||||
|
"view_timeline",
|
||||||
|
"view_kanban",
|
||||||
|
"empty_dashboard",
|
||||||
|
"cycle",
|
||||||
|
]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Project
|
model = Project
|
||||||
fields = [
|
fields = [
|
||||||
|
|
@ -44,7 +86,6 @@ class ProjectCreateSerializer(BaseSerializer):
|
||||||
"archive_in",
|
"archive_in",
|
||||||
"close_in",
|
"close_in",
|
||||||
"timezone",
|
"timezone",
|
||||||
"logo_props",
|
|
||||||
"external_source",
|
"external_source",
|
||||||
"external_id",
|
"external_id",
|
||||||
"is_issue_type_enabled",
|
"is_issue_type_enabled",
|
||||||
|
|
@ -57,6 +98,7 @@ class ProjectCreateSerializer(BaseSerializer):
|
||||||
"updated_at",
|
"updated_at",
|
||||||
"created_by",
|
"created_by",
|
||||||
"updated_by",
|
"updated_by",
|
||||||
|
"logo_props",
|
||||||
]
|
]
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
|
|
@ -86,6 +128,16 @@ class ProjectCreateSerializer(BaseSerializer):
|
||||||
if ProjectIdentifier.objects.filter(name=identifier, workspace_id=self.context["workspace_id"]).exists():
|
if ProjectIdentifier.objects.filter(name=identifier, workspace_id=self.context["workspace_id"]).exists():
|
||||||
raise serializers.ValidationError(detail="Project Identifier is taken")
|
raise serializers.ValidationError(detail="Project Identifier is taken")
|
||||||
|
|
||||||
|
if validated_data.get("logo_props", None) is None:
|
||||||
|
# Generate a random icon and color for the project icon
|
||||||
|
validated_data["logo_props"] = {
|
||||||
|
"in_use": "icon",
|
||||||
|
"icon": {
|
||||||
|
"name": random.choice(self.PROJECT_ICON_DEFAULT_ICONS),
|
||||||
|
"color": random.choice(self.PROJECT_ICON_DEFAULT_COLORS),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
project = Project.objects.create(**validated_data, workspace_id=self.context["workspace_id"])
|
project = Project.objects.create(**validated_data, workspace_id=self.context["workspace_id"])
|
||||||
return project
|
return project
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue