Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_unicode(self):
"""
"""
# WorkflowObjectRelation
workflows.utils.set_workflow(self.page_1, self.w)
wor = WorkflowObjectRelation.objects.filter()[0]
self.assertEqual(wor.__unicode__(), "flat page 1 - Standard")
# StateObjectRelation
workflows.utils.set_state(self.page_1, self.public)
sor = StateObjectRelation.objects.filter()[0]
self.assertEqual(sor.__unicode__(), "flat page 1 - Public")
# WorkflowModelRelation
ctype = ContentType.objects.get_for_model(self.page_1)
workflows.utils.set_workflow(ctype, self.w)
wmr = WorkflowModelRelation.objects.filter()[0]
self.assertEqual(wmr.__unicode__(), "flat page - Standard")
# WorkflowPermissionRelation
self.view = permissions.utils.register_permission("View", "view")
wpr = WorkflowPermissionRelation.objects.create(workflow=self.w, permission=self.view)
self.assertEqual(wpr.__unicode__(), "Standard View")
# StatePermissionRelation
self.owner = permissions.utils.register_role("Owner")
# Permissions
result = permissions.utils.has_permission(self.page_1, self.user, "edit")
self.assertEqual(result, True)
result = permissions.utils.has_permission(self.page_1, self.user, "view")
self.assertEqual(result, True)
# Inheritance
result = permissions.utils.is_inherited(self.page_1, "view")
self.assertEqual(result, False)
result = permissions.utils.is_inherited(self.page_1, "edit")
self.assertEqual(result, False)
# Change state
workflows.utils.set_state(self.page_1, self.public)
# Permissions
result = permissions.utils.has_permission(self.page_1, self.user, "edit")
self.assertEqual(result, False)
result = permissions.utils.has_permission(self.page_1, self.user, "view")
self.assertEqual(result, True)
# Inheritance
result = permissions.utils.is_inherited(self.page_1, "view")
self.assertEqual(result, True)
result = permissions.utils.is_inherited(self.page_1, "edit")
self.assertEqual(result, False)
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)
def set_state(self, state):
"""Sets the workflow state of the object.
"""
return workflows.utils.set_state(self, state)
def change_state(self, transition, actor):
""" Set new state for the instance of the workflow managed model
:param transition: a transition object
:type transition: `workflows.models.Transition `_
:param actor: a user object
:type actor: `django.contrib.auth.User `_
This method send a signal to the application to notify a managed
instance is changing state. The signal provides several arguments as
the previous state, the executed transition and the actor.
"""
actual_state = self.state
set_state(self, transition.destination)
changed_state.send_robust(sender=self, transition=transition,
actor=actor, previous_state=actual_state)
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)