From 649079c59311afbdeb74273f3430729d6aa21e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20A=2E=20S=C3=A1nchez=20L=C3=B3pez?= Date: Sat, 22 Jan 2011 09:07:11 +0000 Subject: [PATCH] Remove state functionallity in base workflows. Fixes #572 - Legacy-Id: 2756 --- workflows/utils.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/workflows/utils.py b/workflows/utils.py index a51635dce..ef2d32596 100644 --- a/workflows/utils.py +++ b/workflows/utils.py @@ -253,14 +253,35 @@ def set_state(obj, state): state The state which should be set to the passed object. """ + if not state: + remove_state(obj) + else: + ctype = ContentType.objects.get_for_model(obj) + try: + sor = StateObjectRelation.objects.get(content_type=ctype, content_id=obj.pk) + except StateObjectRelation.DoesNotExist: + sor = StateObjectRelation.objects.create(content=obj, state=state) + else: + sor.state = state + sor.save() + update_permissions(obj) + +def remove_state(obj): + """Removes the current state for the passed object. + + **Parameters:** + + obj + The object for which the workflow state should be set. Can be any + Django model instance. + + """ ctype = ContentType.objects.get_for_model(obj) try: sor = StateObjectRelation.objects.get(content_type=ctype, content_id=obj.pk) + sor.delete() except StateObjectRelation.DoesNotExist: - sor = StateObjectRelation.objects.create(content=obj, state=state) - else: - sor.state = state - sor.save() + pass update_permissions(obj) def set_initial_state(obj):