Exemple #1
0
    def set_to_object(self, obj):
        """
        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.            
        """
        
        from dynflows import 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)
            utils.set_state(obj, self.initial_state)
        else:
            if wor.workflow != self:
                wor.workflow = self
                wor.save()
                utils.set_state(self.initial_state)
Exemple #2
0
    def set_state(self, state):
        """
        Sets the workflow state of the object.
        """

        return utils.set_state(self, state)