Fixed the Task pre_save signal

remotes/origin/enhancement/email-actions
David Barragán Merino 2013-10-16 23:36:19 +02:00
parent e3d8259644
commit 8239519a90
2 changed files with 40 additions and 18 deletions

View File

@ -54,16 +54,16 @@ class Command(BaseCommand):
role = Role.objects.all()[0]
# projects
for x in range(3):
for x in range(7):
project = self.create_project(x)
for user in self.users:
Membership.objects.create(project=project, role=role, user=user)
start_date = now() - datetime.timedelta(35)
start_date = now() - datetime.timedelta(70)
# create random milestones
for y in range(self.sd.int(1, 5)):
for y in range(self.sd.int(1, 10)):
end_date = start_date + datetime.timedelta(15)
milestone = self.create_milestone(project, start_date, end_date)
@ -71,7 +71,8 @@ class Command(BaseCommand):
for z in range(self.sd.int(3, 7)):
us = self.create_us(project, milestone)
for w in range(self.sd.int(0,6)):
rang = (1, 6) if start_date <= now() and end_date <= now() else (0, 6)
for w in range(self.sd.int(*rang)):
if start_date <= now() and end_date <= now():
task = self.create_task(project, milestone, us, start_date, end_date, closed=True)
elif start_date <= now() and end_date >= now():
@ -149,7 +150,7 @@ class Command(BaseCommand):
owner=self.sd.choice(self.users),
description=self.sd.paragraph(),
milestone=milestone,
status=self.sd.db_object_from_queryset(project.us_statuses.all()),
status=self.sd.db_object_from_queryset(project.us_statuses.filter(is_closed=False)),
tags=self.sd.words(1, 3).split(" ")
)

View File

@ -99,30 +99,51 @@ reversion.register(Task)
# Model related signals handlers
@receiver(models.signals.pre_save, sender=Task, dispatch_uid="task_ref_handler")
def task_ref_handler(sender, instance, **kwargs):
"""
Automatically assignes a seguent reference code to a
user story if that is not created.
"""
if not instance.id and instance.project:
instance.ref = ref_uniquely(instance.project, "last_task_ref", instance.__class__)
@receiver(models.signals.pre_save, sender=Task, dispatch_uid="tasks_close_handler")
def tasks_close_handler(sender, instance, **kwargs):
"""
Automatically assignes a seguent reference code to a
user story if that is not created.
"""
if instance.id:
if instance.id: # Edit task
if (sender.objects.get(id=instance.id).status.is_closed == False and
instance.status.is_closed == True):
instance.status.is_closed == True): # Closed task
instance.finished_date = timezone.now()
if (all([task.status.is_closed for task in
instance.user_story.tasks.exclude(id=instance.id)])):
if instance.user_story and (all([task.status.is_closed for task in
instance.user_story.tasks.exclude(id=instance.id)])): # All us's tasks are close
us_closed_status = instance.project.us_statuses.filter(is_closed=True).order_by("order")[0]
instance.user_story.status = us_closed_status
instance.user_story.finish_date = timezone.now()
instance.user_story.save()
elif (sender.objects.get(id=instance.id).status.is_closed == True and
instance.status.is_closed == False):
instance.status.is_closed == False): # Opened task
instance.finished_date = None
if instance.user_story:
if instance.user_story and instance.user_story.status.is_closed == True: # Us is close
us_opened_status = instance.project.us_statuses.filter(is_closed=False).order_by("-order")[0]
instance.user_story.status = us_opened_status
instance.user_story.finish_date = None
instance.user_story.save()
else: # Create Task
if instance.status.is_closed == True: # Task is close
instance.finished_date = timezone.now()
if instance.user_story:
if instance.user_story.status.is_closed == True: # Us is close
instance.user_story.finish_date = timezone.now()
instance.user_story.save()
elif all([task.status.is_closed for task in instance.user_story.tasks.all()]): # All us's tasks are close
# if any stupid robot/machine/user/alien create an open US
us_closed_status = instance.project.us_statuses.filter(is_closed=True).order_by("order")[0]
instance.user_story.status = us_closed_status
instance.user_story.finish_date = timezone.now()
instance.user_story.save()
else: # Task is opene
instance.finished_date = None
if instance.user_story and instance.user_story.status.is_closed == True: # US is close
us_opened_status = instance.project.us_statuses.filter(is_closed=False).order_by("-order")[0]
instance.user_story.status = us_opened_status
instance.user_story.finish_date = None
instance.user_story.save()
elif instance.user_story:
instance.user_story.finish_date = None
instance.user_story.save()