File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
266287def set_initial_state (obj ):
You can’t perform that action at this time.
0 commit comments