當前位置: 首頁>>代碼示例>>Python>>正文


Python StateService.get_available_states方法代碼示例

本文整理匯總了Python中river.services.state.StateService.get_available_states方法的典型用法代碼示例。如果您正苦於以下問題:Python StateService.get_available_states方法的具體用法?Python StateService.get_available_states怎麽用?Python StateService.get_available_states使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在river.services.state.StateService的用法示例。


在下文中一共展示了StateService.get_available_states方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process

# 需要導入模塊: from river.services.state import StateService [as 別名]
# 或者: from river.services.state.StateService import get_available_states [as 別名]
        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
開發者ID:DjangoBD,項目名稱:django-river,代碼行數:32,代碼來源:transition.py

示例2: process

# 需要導入模塊: from river.services.state import StateService [as 別名]
# 或者: from river.services.state.StateService import get_available_states [as 別名]
    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
開發者ID:h3,項目名稱:django-river,代碼行數:28,代碼來源:transition.py

示例3: test_get_available_states

# 需要導入模塊: from river.services.state import StateService [as 別名]
# 或者: from river.services.state.StateService import get_available_states [as 別名]
    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])
開發者ID:h3,項目名稱:django-river,代碼行數:40,代碼來源:test__state_service.py

示例4: test_get_available_states

# 需要導入模塊: from river.services.state import StateService [as 別名]
# 或者: from river.services.state.StateService import get_available_states [as 別名]
    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])
開發者ID:javrasya,項目名稱:django-river,代碼行數:42,代碼來源:test__state_service.py


注:本文中的river.services.state.StateService.get_available_states方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。