Skip to content

Commit df710e0

Browse files
[WEB-5666] chore: set project timezone same as workspace timezone in project (#8340)
1 parent e8047b6 commit df710e0

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

apps/api/plane/api/serializers/project.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
from rest_framework import serializers
44

55
# Module imports
6-
from plane.db.models import (
7-
Project,
8-
ProjectIdentifier,
9-
WorkspaceMember,
10-
State,
11-
Estimate,
12-
)
6+
from plane.db.models import Project, ProjectIdentifier, WorkspaceMember, State, Estimate
137

148
from plane.utils.content_validator import (
159
validate_html_content,
@@ -123,6 +117,7 @@ def validate(self, data):
123117

124118
def create(self, validated_data):
125119
identifier = validated_data.get("identifier", "").strip().upper()
120+
126121
if identifier == "":
127122
raise serializers.ValidationError(detail="Project Identifier is required")
128123

apps/api/plane/api/views/project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ def post(self, request, slug):
210210
"""
211211
try:
212212
workspace = Workspace.objects.get(slug=slug)
213+
213214
serializer = ProjectCreateSerializer(data={**request.data}, context={"workspace_id": workspace.id})
215+
214216
if serializer.is_valid():
215217
serializer.save()
216218

apps/api/plane/app/serializers/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ProjectIdentifier,
1414
DeployBoard,
1515
ProjectPublicMember,
16-
IssueSequence
16+
IssueSequence,
1717
)
1818
from plane.utils.content_validator import (
1919
validate_html_content,

apps/api/plane/db/models/project.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ class Project(BaseModel):
116116
external_source = models.CharField(max_length=255, null=True, blank=True)
117117
external_id = models.CharField(max_length=255, blank=True, null=True)
118118

119+
def __init__(self, *args, **kwargs):
120+
# Track if timezone is provided, if so, don't override it with the workspace timezone when saving
121+
self.is_timezone_provided = kwargs.get("timezone") is not None
122+
super().__init__(*args, **kwargs)
123+
119124
@property
120125
def cover_image_url(self):
121126
# Return cover image url
@@ -155,7 +160,15 @@ class Meta:
155160
ordering = ("-created_at",)
156161

157162
def save(self, *args, **kwargs):
163+
from plane.db.models import Workspace
164+
158165
self.identifier = self.identifier.strip().upper()
166+
is_creating = self._state.adding
167+
168+
if is_creating and not self.is_timezone_provided:
169+
workspace = Workspace.objects.get(id=self.workspace_id)
170+
self.timezone = workspace.timezone
171+
159172
return super().save(*args, **kwargs)
160173

161174

0 commit comments

Comments
 (0)