63 lines
1.4 KiB
Python
63 lines
1.4 KiB
Python
from django.db import models
|
|
|
|
from evolus.models import Version
|
|
|
|
|
|
class Process(models.Model):
|
|
process_type = models.CharField(max_length=50)
|
|
document_version = models.ForeignKey(Version)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
if not self.pk and not self.process_type:
|
|
self.process_type = self.PROCESS_TYPE
|
|
|
|
def __str__(self):
|
|
return '{}: {}'.format(self.process_type, self.document_version)
|
|
|
|
def create_task(self, assigned_to):
|
|
task, created = Task.objects.get_or_create(status=1, assigned_to=assigned_to, process=self)
|
|
|
|
if created:
|
|
task.save()
|
|
|
|
def allow_tasks_delegation(self):
|
|
return True
|
|
|
|
|
|
TASK_STATUS = (
|
|
(1, 'Created'),
|
|
(3, 'Completed')
|
|
)
|
|
|
|
|
|
class Task(models.Model):
|
|
assigned_to = models.EmailField()
|
|
process = models.ForeignKey(Process)
|
|
status = models.IntegerField(choices=TASK_STATUS)
|
|
|
|
def __str__(self):
|
|
return '{} - {}'.format(self.process, self.assigned_to)
|
|
|
|
|
|
class Review(Process):
|
|
PROCESS_TYPE = 'Review'
|
|
|
|
def __str__(self):
|
|
return 'Review: {}'.format(self.document_version)
|
|
|
|
|
|
class Approval(Process):
|
|
PROCESS_TYPE = 'Approval'
|
|
|
|
|
|
class GatherComments(Process):
|
|
PROCESS_TYPE = 'GatherComments'
|
|
|
|
|
|
class Knowledge(Process):
|
|
PROCESS_TYPE = 'Knowledge'
|
|
|
|
def allow_tasks_delegation(self):
|
|
return False
|