chore: start date for issues (#1075)

This commit is contained in:
pablohashescobar 2023-05-19 12:36:12 +05:30 committed by GitHub
parent 09cffd5498
commit bb79c9de96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 9 deletions

View File

@ -204,7 +204,21 @@ def update_integration_verified():
Integration.objects.bulk_update( Integration.objects.bulk_update(
updated_integrations, ["verified"], batch_size=10 updated_integrations, ["verified"], batch_size=10
) )
print("Sucess") print("Success")
except Exception as e:
print(e)
print("Failed")
def update_start_date():
try:
issues = Issue.objects.filter(state__group__in=["started", "completed"])
updated_issues = []
for issue in issues:
issue.start_date = issue.created_at.date()
updated_issues.append(issue)
Issue.objects.bulk_update(updated_issues, ["start_date"], batch_size=500)
print("Success")
except Exception as e: except Exception as e:
print(e) print(e)
print("Failed") print("Failed")

View File

@ -85,8 +85,13 @@ class Issue(ProjectBaseModel):
).first() ).first()
# if there is no default state assign any random state # if there is no default state assign any random state
if default_state is None: if default_state is None:
self.state = State.objects.filter(project=self.project).first() random_state = State.objects.filter(project=self.project).first()
self.state = random_state
if random_state.group == "started":
self.start_date = timezone.now().date()
else: else:
if default_state.group == "started":
self.start_date = timezone.now().date()
self.state = default_state self.state = default_state
except ImportError: except ImportError:
pass pass
@ -94,18 +99,15 @@ class Issue(ProjectBaseModel):
try: try:
from plane.db.models import State, PageBlock from plane.db.models import State, PageBlock
# Get the completed states of the project
completed_states = State.objects.filter(
group="completed", project=self.project
).values_list("pk", flat=True)
# Check if the current issue state and completed state id are same # Check if the current issue state and completed state id are same
if self.state.id in completed_states: if self.state.group == "completed":
self.completed_at = timezone.now() self.completed_at = timezone.now()
# check if there are any page blocks # check if there are any page blocks
PageBlock.objects.filter(issue_id=self.id).filter().update( PageBlock.objects.filter(issue_id=self.id).filter().update(
completed_at=timezone.now() completed_at=timezone.now()
) )
elif self.state.group == "started":
self.start_date = timezone.now().date()
else: else:
PageBlock.objects.filter(issue_id=self.id).filter().update( PageBlock.objects.filter(issue_id=self.id).filter().update(
completed_at=None completed_at=None
@ -116,7 +118,6 @@ class Issue(ProjectBaseModel):
pass pass
if self._state.adding: if self._state.adding:
# Get the maximum display_id value from the database # Get the maximum display_id value from the database
last_id = IssueSequence.objects.filter(project=self.project).aggregate( last_id = IssueSequence.objects.filter(project=self.project).aggregate(
largest=models.Max("sequence") largest=models.Max("sequence")
)["largest"] )["largest"]
@ -131,6 +132,9 @@ class Issue(ProjectBaseModel):
if largest_sort_order is not None: if largest_sort_order is not None:
self.sort_order = largest_sort_order + 10000 self.sort_order = largest_sort_order + 10000
# If adding it to started state
if self.state.group == "started":
self.start_date = timezone.now().date()
# Strip the html tags using html parser # Strip the html tags using html parser
self.description_stripped = ( self.description_stripped = (
None None