Fixed wrong increment of ref value on tasks and user stories.

remotes/origin/enhancement/email-actions
Andrey Antukh 2013-05-15 19:07:37 +02:00
parent 69bd2f5746
commit b1b23c9f6b
3 changed files with 13 additions and 29 deletions

View File

@ -30,20 +30,6 @@ def attach_uuid(sender, instance, **kwargs):
instance.uuid = unicode(uuid.uuid1())
# Centraliced reference assignation.
@receiver(signals.pre_save, sender=Task)
@receiver(signals.pre_save, sender=UserStory)
def attach_unique_reference(sender, instance, **kwargs):
project = Project.objects.select_for_update().filter(pk=instance.project_id).get()
if isinstance(instance, Task):
project.last_task_ref += 1
instance.ref = project.last_task_ref
else:
project.last_us_ref += 1
instance.ref = project.last_us_ref
project.save()
class User(AbstractUser):
color = models.CharField(max_length=9, null=False, blank=False, default="#669933",

View File

@ -25,9 +25,6 @@ def slugify_uniquely(value, model, slugfield="slug"):
def ref_uniquely(p, seq_field, model, field='ref'):
"""
Returns a unique reference code based on base64 and time.
"""
project = p.__class__.objects.select_for_update().get(pk=p.pk)
ref = getattr(project, seq_field) + 1

View File

@ -505,9 +505,6 @@ class Task(models.Model):
if self.id:
self.modified_date = timezone.now()
if not self.ref:
self.ref = ref_uniquely(self.project, 'last_task_ref', self.__class__)
super(Task, self).save(*args, **kwargs)
@ -578,9 +575,6 @@ class Issue(models.Model):
if self.id:
self.modified_date = timezone.now()
if not self.ref:
self.ref = ref_uniquely(self.project, 'last_issue_ref', self.__class__)
super(Issue, self).save(*args, **kwargs)
@property
@ -626,13 +620,20 @@ def project_post_save(sender, instance, created, **kwargs):
IssueType.objects.create(project=instance, name=name, order=order)
@receiver(models.signals.pre_save, sender=UserStory, dispatch_uid='user_story_ref_handler')
def user_story_ref_handler(sender, instance, **kwargs):
"""
Automatically assignes a seguent reference code to a
user story if that is not created.
"""
@receiver(models.signals.pre_save, sender=Task, dispatch_uid='task_ref_handler')
def task_ref_handler(sender, instance, **kwargs):
if not instance.id and instance.project:
instance.ref = ref_uniquely(instance.project, 'last_task_ref', instance.__class__)
@receiver(models.signals.pre_save, sender=Issue, dispatch_uid='issue_ref_handler')
def issue_ref_handler(sender, instance, **kwargs):
if not instance.id and instance.project:
instance.ref = ref_uniquely(instance.project, 'last_issue_ref', instance.__class__)
@receiver(models.signals.pre_save, sender=UserStory, dispatch_uid='user_story_ref_handler')
def us_ref_handler(sender, instance, **kwargs):
if not instance.id and instance.project:
instance.ref = ref_uniquely(instance.project, 'last_us_ref', instance.__class__)