Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_available_states(self, as_user=None):
all_destination_state_ids = self.get_available_approvals(as_user=as_user).values_list('transition__destination_state', flat=True)
return State.objects.filter(pk__in=all_destination_state_ids)
app_label = 'river'
verbose_name = _("Transition Approval")
verbose_name_plural = _("Transition Approvals")
objects = TransitionApprovalManager()
content_type = models.ForeignKey(app_config.CONTENT_TYPE_CLASS, verbose_name=_('Content Type'), on_delete=CASCADE)
object_id = models.CharField(max_length=50, verbose_name=_('Related Object'))
workflow_object = GenericForeignKey('content_type', 'object_id')
meta = models.ForeignKey(TransitionApprovalMeta, verbose_name=_('Meta'), related_name="transition_approvals", null=True, blank=True, on_delete=SET_NULL)
workflow = models.ForeignKey(Workflow, verbose_name=_("Workflow"), related_name='transition_approvals', on_delete=PROTECT)
source_state = models.ForeignKey(State, verbose_name=_("Source State"), related_name='transition_approvals_as_source', on_delete=PROTECT)
destination_state = models.ForeignKey(State, verbose_name=_("Next State"), related_name='transition_approvals_as_destination', on_delete=PROTECT)
transactioner = models.ForeignKey(app_config.USER_CLASS, verbose_name=_('Transactioner'), null=True, blank=True, on_delete=SET_NULL)
transaction_date = models.DateTimeField(null=True, blank=True)
status = models.CharField(_('Status'), choices=STATUSES, max_length=100, default=PENDING)
skipped = models.BooleanField(_('Skip'), default=False)
permissions = models.ManyToManyField(app_config.PERMISSION_CLASS, verbose_name=_('Permissions'))
groups = models.ManyToManyField(app_config.GROUP_CLASS, verbose_name=_('Groups'))
priority = models.IntegerField(default=0, verbose_name=_('Priority'))
enabled = models.BooleanField(_('Enabled?'), default=True)
previous = TreeOneToOneField("self", verbose_name=_('Previous Transition'), related_name="next_transition", null=True, blank=True, on_delete=CASCADE)
from river.admin.function_admin import *
from river.admin.hook_admins import *
from river.admin.transitionapprovalmeta import *
from river.admin.transitionmeta import *
from river.admin.workflow import *
from river.models import State
admin.site.register(State)
class Transition(BaseModel):
class Meta:
app_label = 'river'
verbose_name = _("Transition")
verbose_name_plural = _("Transitions")
objects = TransitionApprovalManager()
content_type = models.ForeignKey(app_config.CONTENT_TYPE_CLASS, verbose_name=_('Content Type'), on_delete=CASCADE)
object_id = models.CharField(max_length=50, verbose_name=_('Related Object'))
workflow_object = GenericForeignKey('content_type', 'object_id')
meta = models.ForeignKey(TransitionMeta, verbose_name=_('Meta'), related_name="transitions", on_delete=PROTECT)
workflow = models.ForeignKey(Workflow, verbose_name=_("Workflow"), related_name='transitions', on_delete=PROTECT)
source_state = models.ForeignKey(State, verbose_name=_("Source State"), related_name='transition_as_source', on_delete=PROTECT)
destination_state = models.ForeignKey(State, verbose_name=_("Destination State"), related_name='transition_as_destination', on_delete=PROTECT)
status = models.CharField(_('Status'), choices=STATUSES, max_length=100, default=PENDING)
iteration = models.IntegerField(default=0, verbose_name=_('Priority'))
@property
def next_transitions(self):
return Transition.objects.filter(
workflow=self.workflow,
workflow_object=self.workflow_object,
source_state=self.destination_state,
iteration=self.iteration + 1
)
@property
def peers(self):
class Meta:
app_label = 'river'
verbose_name = _("Transition Approval")
verbose_name_plural = _("Transition Approvals")
objects = TransitionApprovalManager()
content_type = models.ForeignKey(app_config.CONTENT_TYPE_CLASS, verbose_name=_('Content Type'), on_delete=CASCADE)
object_id = models.CharField(max_length=50, verbose_name=_('Related Object'))
workflow_object = GenericForeignKey('content_type', 'object_id')
meta = models.ForeignKey(TransitionApprovalMeta, verbose_name=_('Meta'), related_name="transition_approvals", null=True, blank=True, on_delete=SET_NULL)
workflow = models.ForeignKey(Workflow, verbose_name=_("Workflow"), related_name='transition_approvals', on_delete=PROTECT)
source_state = models.ForeignKey(State, verbose_name=_("Source State"), related_name='transition_approvals_as_source', on_delete=PROTECT)
destination_state = models.ForeignKey(State, verbose_name=_("Next State"), related_name='transition_approvals_as_destination', on_delete=PROTECT)
transactioner = models.ForeignKey(app_config.USER_CLASS, verbose_name=_('Transactioner'), null=True, blank=True, on_delete=SET_NULL)
transaction_date = models.DateTimeField(null=True, blank=True)
status = models.CharField(_('Status'), choices=STATUSES, max_length=100, default=PENDING)
skipped = models.BooleanField(_('Skip'), default=False)
permissions = models.ManyToManyField(app_config.PERMISSION_CLASS, verbose_name=_('Permissions'))
groups = models.ManyToManyField(app_config.GROUP_CLASS, verbose_name=_('Groups'))
priority = models.IntegerField(default=0, verbose_name=_('Priority'))
enabled = models.BooleanField(_('Enabled?'), default=True)
previous = TreeOneToOneField("self", verbose_name=_('Previous Transition'), related_name="next_transition", null=True, blank=True, on_delete=CASCADE)
def final_states(self):
final_approvals = TransitionApprovalMeta.objects.filter(workflow=self.workflow, children__isnull=True)
return State.objects.filter(pk__in=final_approvals.values_list("transition_meta__destination_state", flat=True))
from river.models import BaseModel, State
from river.models.managers.workflowmetada import WorkflowManager
class Workflow(BaseModel):
class Meta:
app_label = 'river'
verbose_name = _("Workflow")
verbose_name_plural = _("Workflows")
unique_together = [("content_type", "field_name")]
objects = WorkflowManager()
content_type = models.ForeignKey(app_config.CONTENT_TYPE_CLASS, verbose_name=_('Content Type'), on_delete=PROTECT)
field_name = models.CharField(_("Field Name"), max_length=200)
initial_state = models.ForeignKey(State, verbose_name=_("Initial State"), related_name='workflow_this_set_as_initial_state', on_delete=PROTECT)
def natural_key(self):
return self.content_type, self.field_name
def __str__(self):
return "%s.%s" % (self.content_type.model, self.field_name)