Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load_handler_backend():
handler_module, handler_cls = app_config.HANDLER_BACKEND_CLASS.rsplit('.', 1)
return getattr(__import__(handler_module, fromlist=[handler_cls]), handler_cls)(**app_config.HANDLER_BACKEND_CONFIG)
from river.config import app_config
__author__ = 'ahmetdal'
handler_module, hooking_cls = app_config.HOOKING_BACKEND_CLASS.rsplit('.', 1)
callback_backend = getattr(__import__(handler_module, fromlist=[hooking_cls]), hooking_cls)(**app_config.HOOKING_BACKEND_CONFIG)
def load_handler_backend():
handler_module, handler_cls = app_config.HANDLER_BACKEND_CLASS.rsplit('.', 1)
return getattr(__import__(handler_module, fromlist=[handler_cls]), handler_cls)(**app_config.HANDLER_BACKEND_CONFIG)
class TransitionApprovalMeta(BaseModel):
class Meta:
app_label = 'river'
verbose_name = _("Transition Approval Meta")
verbose_name_plural = _("Transition Approval Meta")
unique_together = [('workflow', 'transition_meta', 'priority')]
objects = TransitionApprovalMetadataManager()
workflow = models.ForeignKey(Workflow, verbose_name=_("Workflow"), related_name='transition_approval_metas', on_delete=PROTECT)
transition_meta = models.ForeignKey(TransitionMeta, verbose_name=_("Transition Meta"), related_name='transition_approval_meta', on_delete=PROTECT)
permissions = models.ManyToManyField(app_config.PERMISSION_CLASS, verbose_name=_('Permissions'), blank=True)
groups = models.ManyToManyField(app_config.GROUP_CLASS, verbose_name=_('Groups'), blank=True)
priority = models.IntegerField(default=0, verbose_name=_('Priority'), null=True)
parents = models.ManyToManyField('self', verbose_name='parents', related_name='children', symmetrical=False, db_index=True, blank=True)
def __str__(self):
return 'Transition: %s,Permissions: %s, Groups: %s, Order: %s' % (
self.transition_meta,
','.join(self.permissions.values_list('name', flat=True)),
','.join(self.groups.values_list('name', flat=True)), self.priority)
def post_save_model(sender, instance, *args, **kwargs):
parents = TransitionApprovalMeta.objects \
.filter(workflow=instance.workflow, transition_meta__destination_state=instance.transition_meta.source_state) \
.exclude(pk__in=instance.parents.values_list('pk', flat=True)) \
.exclude(pk=instance.pk)
class TransitionApprovalMeta(BaseModel):
class Meta:
app_label = 'river'
verbose_name = _("Transition Approval Meta")
verbose_name_plural = _("Transition Approval Meta")
unique_together = [('workflow', 'transition_meta', 'priority')]
objects = TransitionApprovalMetadataManager()
workflow = models.ForeignKey(Workflow, verbose_name=_("Workflow"), related_name='transition_approval_metas', on_delete=PROTECT)
transition_meta = models.ForeignKey(TransitionMeta, verbose_name=_("Transition Meta"), related_name='transition_approval_meta', on_delete=PROTECT)
permissions = models.ManyToManyField(app_config.PERMISSION_CLASS, verbose_name=_('Permissions'), blank=True)
groups = models.ManyToManyField(app_config.GROUP_CLASS, verbose_name=_('Groups'), blank=True)
priority = models.IntegerField(default=0, verbose_name=_('Priority'), null=True)
parents = models.ManyToManyField('self', verbose_name='parents', related_name='children', symmetrical=False, db_index=True, blank=True)
def __str__(self):
return 'Transition: %s,Permissions: %s, Groups: %s, Order: %s' % (
self.transition_meta,
','.join(self.permissions.values_list('name', flat=True)),
','.join(self.groups.values_list('name', flat=True)), self.priority)
def post_save_model(sender, instance, *args, **kwargs):
parents = TransitionApprovalMeta.objects \
.filter(workflow=instance.workflow, transition_meta__destination_state=instance.transition_meta.source_state) \
.exclude(pk__in=instance.parents.values_list('pk', flat=True)) \
.exclude(pk=instance.pk)
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)
transition = models.ForeignKey(Transition, verbose_name=_("Transition"), related_name='transition_approvals', 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)
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'))
previous = TreeOneToOneField("self", verbose_name=_('Previous Transition'), related_name="next_transition", null=True, blank=True, on_delete=CASCADE)
@property
def peers(self):
return TransitionApproval.objects.filter(
workflow_object=self.workflow_object,
workflow=self.workflow,
transition=self.transition,
).exclude(pk=self.pk)
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)
skipped_from = models.ManyToManyField("self", verbose_name=_("Skipped from"), related_name='created_after_skipped')
@transaction.atomic
def skip(self):
if self.skipped:
LOGGER.info("TransitionApproval with id %s is already skipped.")
return
self.skipped = True
self.save()