* chore: traige state in intake * chore: triage state changes * feat: implement intake state dropdown component and integrate into issue properties * chore: added the triage state validation * chore: added triage state filter * chore: added workspace filter * fix: migration file * chore: added triage group state check * chore: updated the filters * chore: updated the filters * chore: added variables for intake state * fix: import error * refactor: improve project intake state retrieval logic and update TriageGroupIcon component * chore: changed the intake validation logic * refactor: update intake state types and clean up unused interfaces * chore: changed the state color * chore: changed the update serializer * chore: updated with current instance * chore: update TriageGroupIcon color to match new intake state group color * chore: stringified value * chore: added validation in serializer * chore: added logger instead of print * fix: correct component closing syntax in ActiveProjectItem * chore: updated the migration file * chore: added noop in migation --------- Co-authored-by: b-saikrishnakanth <bsaikrishnakanth97@gmail.com>
93 lines
3 KiB
Python
93 lines
3 KiB
Python
# Django imports
|
|
from django.db import models
|
|
from django.template.defaultfilters import slugify
|
|
from django.db.models import Q
|
|
|
|
# Module imports
|
|
from .project import ProjectBaseModel
|
|
|
|
|
|
class StateManager(models.Manager):
|
|
"""Default manager - excludes triage states"""
|
|
|
|
def get_queryset(self):
|
|
return super().get_queryset().exclude(group=State.TRIAGE)
|
|
|
|
|
|
class TriageStateManager(models.Manager):
|
|
"""Manager for triage states only"""
|
|
|
|
def get_queryset(self):
|
|
return super().get_queryset().filter(group=State.TRIAGE)
|
|
|
|
|
|
class State(ProjectBaseModel):
|
|
BACKLOG = "backlog"
|
|
UNSTARTED = "unstarted"
|
|
STARTED = "started"
|
|
COMPLETED = "completed"
|
|
CANCELLED = "cancelled"
|
|
TRIAGE = "triage"
|
|
|
|
GROUP_CHOICES = (
|
|
(BACKLOG, "Backlog"),
|
|
(UNSTARTED, "Unstarted"),
|
|
(STARTED, "Started"),
|
|
(COMPLETED, "Completed"),
|
|
(CANCELLED, "Cancelled"),
|
|
(TRIAGE, "Triage"),
|
|
)
|
|
name = models.CharField(max_length=255, verbose_name="State Name")
|
|
description = models.TextField(verbose_name="State Description", blank=True)
|
|
color = models.CharField(max_length=255, verbose_name="State Color")
|
|
slug = models.SlugField(max_length=100, blank=True)
|
|
sequence = models.FloatField(default=65535)
|
|
group = models.CharField(
|
|
choices=(
|
|
("backlog", "Backlog"),
|
|
("unstarted", "Unstarted"),
|
|
("started", "Started"),
|
|
("completed", "Completed"),
|
|
("cancelled", "Cancelled"),
|
|
("triage", "Triage"),
|
|
),
|
|
default="backlog",
|
|
max_length=20,
|
|
)
|
|
is_triage = models.BooleanField(default=False)
|
|
default = models.BooleanField(default=False)
|
|
external_source = models.CharField(max_length=255, null=True, blank=True)
|
|
external_id = models.CharField(max_length=255, blank=True, null=True)
|
|
|
|
objects = StateManager()
|
|
all_state_objects = models.Manager()
|
|
triage_objects = TriageStateManager()
|
|
|
|
def __str__(self):
|
|
"""Return name of the state"""
|
|
return f"{self.name} <{self.project.name}>"
|
|
|
|
class Meta:
|
|
unique_together = ["name", "project", "deleted_at"]
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["name", "project"],
|
|
condition=Q(deleted_at__isnull=True),
|
|
name="state_unique_name_project_when_deleted_at_null",
|
|
)
|
|
]
|
|
verbose_name = "State"
|
|
verbose_name_plural = "States"
|
|
db_table = "states"
|
|
ordering = ("sequence",)
|
|
|
|
def save(self, *args, **kwargs):
|
|
self.slug = slugify(self.name)
|
|
if self._state.adding:
|
|
# Get the maximum sequence value from the database
|
|
last_id = State.objects.filter(project=self.project).aggregate(largest=models.Max("sequence"))["largest"]
|
|
# if last_id is not None
|
|
if last_id is not None:
|
|
self.sequence = last_id + 15000
|
|
|
|
return super().save(*args, **kwargs)
|