Skip to content

Commit 649079c

Browse files
committed
Remove state functionallity in base workflows. Fixes ietf-tools#572
- Legacy-Id: 2756
1 parent a241c20 commit 649079c

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

workflows/utils.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,35 @@ def set_state(obj, state):
253253
state
254254
The state which should be set to the passed object.
255255
"""
256+
if not state:
257+
remove_state(obj)
258+
else:
259+
ctype = ContentType.objects.get_for_model(obj)
260+
try:
261+
sor = StateObjectRelation.objects.get(content_type=ctype, content_id=obj.pk)
262+
except StateObjectRelation.DoesNotExist:
263+
sor = StateObjectRelation.objects.create(content=obj, state=state)
264+
else:
265+
sor.state = state
266+
sor.save()
267+
update_permissions(obj)
268+
269+
def remove_state(obj):
270+
"""Removes the current state for the passed object.
271+
272+
**Parameters:**
273+
274+
obj
275+
The object for which the workflow state should be set. Can be any
276+
Django model instance.
277+
278+
"""
256279
ctype = ContentType.objects.get_for_model(obj)
257280
try:
258281
sor = StateObjectRelation.objects.get(content_type=ctype, content_id=obj.pk)
282+
sor.delete()
259283
except StateObjectRelation.DoesNotExist:
260-
sor = StateObjectRelation.objects.create(content=obj, state=state)
261-
else:
262-
sor.state = state
263-
sor.save()
284+
pass
264285
update_permissions(obj)
265286

266287
def set_initial_state(obj):

0 commit comments

Comments
 (0)