本文整理匯總了Python中river.services.state.StateService類的典型用法代碼示例。如果您正苦於以下問題:Python StateService類的具體用法?Python StateService怎麽用?Python StateService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了StateService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: process
def process(workflow_object, field, user, action, next_state=None, god_mod=False):
current_state = getattr(workflow_object, field)
approvements = ApprovementService.get_approvements_object_waiting_for_approval(workflow_object, field, [current_state], user=user, god_mod=god_mod)
c = approvements.count()
if c == 0:
raise RiverException(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, "There is no available state for destination for the user.")
if c > 1:
if next_state:
approvements = approvements.filter(meta__transition__destination_state=next_state)
if approvements.count() == 0:
available_states = StateService.get_available_states(workflow_object, field, user)
raise RiverException(ErrorCode.INVALID_NEXT_STATE_FOR_USER,
"Invalid state is given(%s). Valid states is(are) %s" % (next_state.__unicode__(), ','.join([ast.__unicode__() for ast in available_states])))
else:
raise RiverException(ErrorCode.NEXT_STATE_IS_REQUIRED, "State must be given when there are multiple states for destination")
approvement = approvements[0]
approvement.status = action
approvement.transactioner = user
approvement.transaction_date = datetime.now()
approvement.save()
c = False
track = workflow_object.approvement_track
while not c:
track, c = approvement.tracks.get_or_create(previous_track=track)
return approvement, track
示例2: process
def process(workflow_object, field, user, action, next_state=None, god_mod=False):
current_state = getattr(workflow_object, field)
proceedings = ProceedingService.get_available_proceedings(workflow_object, field, [current_state],
user=user, god_mod=god_mod)
c = proceedings.count()
if c == 0:
raise RiverException(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER,
"There is no available state for destination for the user.")
if c > 1:
if next_state:
proceedings = proceedings.filter(meta__transition__destination_state=next_state)
if proceedings.count() == 0:
available_states = StateService.get_available_states(workflow_object, field, user)
raise RiverException(ErrorCode.INVALID_NEXT_STATE_FOR_USER,
"Invalid state is given(%s). Valid states is(are) %s" % (
next_state.__unicode__(),
','.join([ast.__unicode__() for ast in available_states])))
else:
raise RiverException(ErrorCode.NEXT_STATE_IS_REQUIRED,
"State must be given when there are multiple states for destination")
proceeding = proceedings[0]
proceeding.status = action
proceeding.transactioner = user
proceeding.transaction_date = datetime.now()
if workflow_object.proceeding:
proceeding.previous = workflow_object.proceeding
proceeding.save()
return proceeding
示例3: test_init
def test_init(self):
ObjectService.register_object(self.objects[0], self.field)
ObjectService.register_object(self.objects[1], self.field)
initial_state = StateService.get_initial_state(self.content_type, self.field)
self.assertEqual(initial_state, getattr(self.objects[0], self.field))
self.assertEqual(18, Approvement.objects.count())
示例4: test_init
def test_init(self):
self.initialize_normal_scenario()
ObjectService.register_object(self.objects[0], self.field)
ObjectService.register_object(self.objects[1], self.field)
initial_state = StateService.get_initial_state(self.content_type, self.field)
self.assertEqual(initial_state, getattr(self.objects[0], self.field))
self.assertEqual(18, Proceeding.objects.count())
示例5: _post_save
def _post_save(sender, instance, created, *args, **kwargs): # signal, sender, instance):
"""
Desc: Generate TransitionProceedings according to ProceedingMeta of the content type at the beginning.
:param kwargs:
:return:
"""
from river.services.state import StateService
if created:
ObjectService.register_object(instance)
if not instance.get_state():
init_state = StateService.get_initial_state(ContentType.objects.get_for_model(instance))
instance.set_state(init_state)
instance.save()
示例6: init_approvements
def init_approvements(workflow_object, field):
content_type = RiverConfig.CONTENT_TYPE_CLASS.objects.get_for_model(workflow_object)
for approvement_meta in ApprovementMeta.objects.filter(transition__content_type=content_type, transition__field=field):
approvement, created = Approvement.objects.update_or_create(
meta=approvement_meta,
workflow_object=workflow_object,
field=field,
defaults={
'order': approvement_meta.order,
'status': PENDING,
}
)
approvement.permissions.add(*approvement_meta.permissions.all())
approvement.groups.add(*approvement_meta.groups.all())
init_state = StateService.get_initial_state(content_type, field)
setattr(workflow_object, field, init_state)
workflow_object.save()
LOGGER.debug("Approvements are initialized for workflow object %s and field %s" % (workflow_object, field))
示例7: get_initial_state
def get_initial_state(self):
from river.services.state import StateService
return StateService.get_initial_state(ContentType.objects.get_for_model(self), name)
示例8: on_final_state
def on_final_state(self):
from river.services.state import StateService
return getattr(self, name) in StateService.get_final_states(ContentType.objects.get_for_model(self), name)
示例9: test_get_final_states
def test_get_final_states(self):
self.assertListEqual(list(State.objects.filter(label__in=['s4.1', 's4.2', 's5.1', 's5.2'])), list(StateService.get_final_states(self.content_type, self.field)))
示例10: test_get_initial_state
def test_get_initial_state(self):
self.assertEqual(State.objects.get(label='s1'), StateService.get_initial_state(self.content_type, self.field))
示例11: test_get_available_states
def test_get_available_states(self):
ObjectService.register_object(self.objects[0], self.field)
ObjectService.register_object(self.objects[1], self.field)
available_states = StateService.get_available_states(self.objects[0], self.field, self.user2, include_user=False)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.field, self.user2, include_user=True)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.field, self.user2)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.field, self.user3, include_user=False)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.field, self.user3, include_user=True)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.field, self.user3)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.field, self.user4, include_user=False)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.field, self.user4, include_user=True)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.field, self.user4)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.field, self.user1, include_user=False)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.field, self.user1, include_user=True)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.field, self.user1)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
示例12: get_final_approvements
def get_final_approvements(content_type, field):
final_states = StateService.get_final_states(content_type, field)
return Approvement.objects.filter(meta__transition__destination_state__in=final_states, meta__transition__direction=FORWARD)
示例13: get_initial_approvements
def get_initial_approvements(content_type, field):
initial_state = StateService.get_initial_state(content_type, field)
return Approvement.objects.filter(meta__transition__source_state=initial_state, meta__transition__direction=FORWARD)
示例14: test_get_available_states
def test_get_available_states(self):
self.initialize_normal_scenario()
ObjectService.register_object(self.objects[0])
ObjectService.register_object(self.objects[1])
available_states = StateService.get_available_states(self.objects[0], self.user2, include_user=False)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.user2, include_user=True)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.user2)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.user3, include_user=False)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.user3, include_user=True)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.user3)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.user4, include_user=False)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.user4, include_user=True)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.user4)
self.assertEqual(0, available_states.count())
available_states = StateService.get_available_states(self.objects[0], self.user1, include_user=False)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.user1, include_user=True)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
available_states = StateService.get_available_states(self.objects[0], self.user1)
self.assertEqual(1, available_states.count())
self.assertEqual(State.objects.get(label='s2'), available_states[0])
示例15: test_get_final_states
def test_get_final_states(self):
self.initialize_normal_scenario()
self.assertListEqual(list(State.objects.filter(label__in=['s4.1', 's4.2', 's5.1', 's5.2'])), list(StateService.get_final_states(self.content_type)))