How to use the workflows.utils.set_workflow_for_object 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 diefenbach / django-workflows / workflows / tests.py View on Github external
result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, None)

        wp = Workflow.objects.create(name="Portal")

        # Set for model
        workflows.utils.set_workflow_for_model(ctype, wp)

        result = workflows.utils.get_workflow_for_model(ctype)
        self.assertEqual(result, wp)

        result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, wp)

        # Set for object
        workflows.utils.set_workflow_for_object(self.user, self.w)
        result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, self.w)

        # The model still have wp
        result = workflows.utils.get_workflow_for_model(ctype)
        self.assertEqual(result, wp)
github diefenbach / django-workflows / workflows / tests.py View on Github external
def test_remove_workflow_2(self):
        """Removes workflow from object
        """
        result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, None)

        workflows.utils.set_workflow_for_object(self.user, self.w)

        result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, self.w)

        result = workflows.utils.remove_workflow(self.user)
        self.assertEqual(result, None)
github diefenbach / django-workflows / workflows / tests.py View on Github external
result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, None)

        wp = Workflow.objects.create(name="Portal")

        # Set for model
        workflows.utils.set_workflow_for_model(ctype, "Portal")

        result = workflows.utils.get_workflow_for_model(ctype)
        self.assertEqual(result, wp)

        result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, wp)

        # Set for object
        workflows.utils.set_workflow_for_object(self.user, "Standard")
        result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, self.w)

        # The model still have wp
        result = workflows.utils.get_workflow_for_model(ctype)
        self.assertEqual(result, wp)

        # Workflow which does not exist
        result = workflows.utils.set_workflow_for_model(ctype, "Wrong")
        self.assertEqual(result, False)

        result = workflows.utils.set_workflow_for_object(self.user, "Wrong")
        self.assertEqual(result, False)
github diefenbach / django-workflows / workflows / tests.py View on Github external
def test_get_workflow_for_object(self):
        """
        """
        result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, None)
        
        # Set workflow for a user
        workflows.utils.set_workflow_for_object(self.user, self.w)
        
        # Get workflow for the user        
        result = workflows.utils.get_workflow_for_object(self.user)
        self.assertEqual(result, self.w)

        # Set workflow for a FlatPage
        page_1 = FlatPage.objects.create(url="/page-1/", title="Page 1")
        workflows.utils.set_workflow_for_object(page_1, self.w)

        result = workflows.utils.get_workflow_for_object(self.user)
        self.assertEqual(result, self.w)

        result = workflows.utils.get_workflow_for_object(page_1)
        self.assertEqual(result, self.w)
github diefenbach / django-workflows / workflows / tests.py View on Github external
def test_get_workflow_for_object(self):
        """
        """
        result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, None)
        
        # Set workflow for a user
        workflows.utils.set_workflow_for_object(self.user, self.w)
        
        # Get workflow for the user        
        result = workflows.utils.get_workflow_for_object(self.user)
        self.assertEqual(result, self.w)

        # Set workflow for a FlatPage
        page_1 = FlatPage.objects.create(url="/page-1/", title="Page 1")
        workflows.utils.set_workflow_for_object(page_1, self.w)

        result = workflows.utils.get_workflow_for_object(self.user)
        self.assertEqual(result, self.w)

        result = workflows.utils.get_workflow_for_object(page_1)
        self.assertEqual(result, self.w)
github diefenbach / django-workflows / workflows / tests.py View on Github external
self.assertEqual(result, wp)

        # Set for object
        workflows.utils.set_workflow_for_object(self.user, "Standard")
        result = workflows.utils.get_workflow(self.user)
        self.assertEqual(result, self.w)

        # The model still have wp
        result = workflows.utils.get_workflow_for_model(ctype)
        self.assertEqual(result, wp)

        # Workflow which does not exist
        result = workflows.utils.set_workflow_for_model(ctype, "Wrong")
        self.assertEqual(result, False)

        result = workflows.utils.set_workflow_for_object(self.user, "Wrong")
        self.assertEqual(result, False)
github diefenbach / django-workflows / workflows / __init__.py View on Github external
"""Sets the passed workflow to the object. This will set the local
        workflow for the object.

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

        **Parameters:**

        workflow
            The workflow which should be set to the object. Can be a Workflow
            instance or a string with the workflow name.
        obj
            The object which gets the passed workflow.
        """
        return workflows.utils.set_workflow_for_object(self, workflow)
github unistra / django-workflow-activity / workflow_activity / models.py View on Github external
def set_workflow(self, workflow):
        """ Initiate a workflow for instance. """
        if self.state is None:
            if not workflow:
                ctype = ContentType.objects.get_for_model(self)
                workflow = get_workflow_for_model(ctype)
            set_workflow_for_object(self, workflow)