How to use the workflows.models.WorkflowObjectRelation.objects.get function in workflows

To help you get started, we’ve selected a few workflows examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github unistra / django-workflow-activity / workflow_activity / models.py View on Github external
def remove_workflow(self):
        """ Remove entirely a worflow for an instance. """

        ctype = ContentType.objects.get_for_model(self)
        try:
            workflow = self.state.workflow
            wor = workflows.models.WorkflowObjectRelation.objects.get(
                content_type=ctype, content_id=self.pk
            )
            sor = workflows.models.StateObjectRelation.objects.get(
                content_type=ctype, content_id=self.pk
            )
        except workflows.models.WorkflowObjectRelation.DoesNotExist:
            pass
        except workflows.models.StateObjectRelation.DoesNotExist:
            pass

        with transaction.atomic():
            wor.delete()
            sor.delete()
github diefenbach / django-workflows / workflows / utils.py View on Github external
def get_workflow_for_object(obj):
    """Returns the workflow for the passed object.

    **Parameters:**

    obj
        The object for which the workflow should be returned. Can be any
        Django model instance.
    """
    try:
        ctype = ContentType.objects.get_for_model(obj)
        wor = WorkflowObjectRelation.objects.get(content_id=obj.id, content_type=ctype)
    except WorkflowObjectRelation.DoesNotExist:
        return None
    else:
        return wor.workflow
github diefenbach / django-workflows / workflows / models.py View on Github external
"""Sets the workflow to the passed object.

        If the object has already the given workflow nothing happens. Otherwise
        the workflow is set to the objectthe state is set to the workflow's
        initial state.

        **Parameters:**

        obj
            The object which gets the workflow.
        """
        import workflows.utils

        ctype = ContentType.objects.get_for_model(obj)
        try:
            wor = WorkflowObjectRelation.objects.get(content_type=ctype, content_id=obj.id)
        except WorkflowObjectRelation.DoesNotExist:
            WorkflowObjectRelation.objects.create(content=obj, workflow=self)
            workflows.utils.set_state(obj, self.initial_state)
        else:
            if wor.workflow != self:
                wor.workflow = self
                wor.save()
                workflows.utils.set_state(self.initial_state)