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())
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())
def test_init(self): self.initialize_normal_scenario() ObjectService.register_object(self.objects[0]) ObjectService.register_object(self.objects[1]) initial_state = StateService.get_initial_state(self.content_type) self.assertEqual(initial_state, self.objects[0].get_state()) self.assertEqual(18, Proceeding.objects.count())
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()
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))
def get_initial_state(self): from river.services.state import StateService return StateService.get_initial_state( ContentType.objects.get_for_model(self), name)
def test_get_initial_state(self): self.initialize_normal_scenario() self.assertEqual(State.objects.get(label='s1'), StateService.get_initial_state(self.content_type))
def test_get_initial_state(self): self.assertEqual( State.objects.get(label='s1'), StateService.get_initial_state(self.content_type, self.field))
def get_initial_state(self): from river.services.state import StateService return StateService.get_initial_state(ContentType.objects.get_for_model(self), name)
def test_get_initial_state(self): self.assertEqual(State.objects.get(label='s1'), StateService.get_initial_state(self.content_type, self.field))
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)