How to use the river.models.proceeding.Proceeding.objects function in river

To help you get started, we’ve selected a few river examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github javrasya / django-river / river / services / proceeding.py View on Github external
permission_q = Q()
            for p in permissions:
                label, codename = p.split('.')
                permission_q = permission_q | Q(permissions__content_type__app_label=label,
                                                permissions__codename=codename)

            return proceedings.filter(
                (
                    (Q(transactioner__isnull=True) | Q(transactioner=user)) &
                    (Q(permissions__isnull=True) | permission_q) &
                    (Q(groups__isnull=True) | group_q)
                )
            )

        proceedings = Proceeding.objects.filter(
            workflow_object=workflow_object,
            meta__transition__source_state__in=source_states,
            status=PENDING,
            enabled=True
        )

        suitable_proceedings = get_proceeding(proceedings.filter(skip=False))

        if user and not god_mod:
            suitable_proceedings = authorize_proceedings(suitable_proceedings)

        skipped_proceedings = get_proceeding(proceedings.filter(skip=True))
        if skipped_proceedings:
            source_state_pks = list(skipped_proceedings.values_list('meta__transition__destination_state', flat=True))
            suitable_proceedings = suitable_proceedings | ProceedingService.get_available_proceedings(workflow_object,
                                                                                                      State.objects.filter(
github javrasya / django-river / river / services / proceeding.py View on Github external
def get_next_proceedings(workflow_object, proceeding_pks=None, current_states=None, index=0, limit=None):
        if not proceeding_pks:
            proceeding_pks = []
        index += 1
        current_states = list(current_states.values_list('pk', flat=True)) if current_states else [workflow_object.get_state()]
        next_proceedings = Proceeding.objects.filter(workflow_object=workflow_object, meta__transition__source_state__in=current_states)
        if workflow_object.proceeding:
            next_proceedings = next_proceedings.exclude(pk=workflow_object.proceeding.pk)
        if next_proceedings.exists() and not next_proceedings.filter(pk__in=proceeding_pks).exists() and (
                    not limit or index < limit):
            proceedings = ProceedingService.get_next_proceedings(
                workflow_object,
                proceeding_pks=proceeding_pks + list(next_proceedings.values_list('pk', flat=True)),
                current_states=State.objects.filter(
                    pk__in=next_proceedings.values_list('meta__transition__destination_state', flat=True)),
                index=index,
                limit=limit
            )
        else:
            proceedings = Proceeding.objects.filter(pk__in=proceeding_pks)

        return proceedings
github javrasya / django-river / river / services / state.py View on Github external
def get_available_states(workflow_object, user, include_user=True):
        proceedings = Proceeding.objects.filter(
            workflow_object=workflow_object,
            meta__transition__source_state=workflow_object.get_state(),
        )
        if include_user:
            proceedings = proceedings.filter(
                meta__permissions__in=user.user_permissions.all()
            )
        destination_states = proceedings.values_list('meta__transition__destination_state', flat=True)
        return State.objects.filter(pk__in=destination_states)
github javrasya / django-river / river / services / object.py View on Github external
def is_workflow_completed(workflow_object):
        return Proceeding.objects.filter(workflow_object=workflow_object, meta__transition__source_state=workflow_object.get_state()).count() == 0
github javrasya / django-river / river / services / object.py View on Github external
def register_object(workflow_object):
        proceedings = Proceeding.objects.filter(workflow_object=workflow_object)
        if proceedings.count() == 0:
            ProceedingService.init_proceedings(workflow_object)
github javrasya / django-river / river / services / proceeding_meta.py View on Github external
def apply_new_proceeding_meta(new_proceeding_meta):
        if new_proceeding_meta.proceedings.count() == 0:
            content_type = new_proceeding_meta.content_type
            WorkflowObjectClass = content_type.model_class()
            Proceeding.objects.bulk_create(
                list(
                    Proceeding(
                        workflow_object=workflow_object,
                        meta=new_proceeding_meta,
                        content_type=content_type
                    )
                    for workflow_object in WorkflowObjectClass.objects.all()
                )
github javrasya / django-river / river / services / proceeding.py View on Github external
def init_proceedings(workflow_object):

        content_type = app_config.CONTENT_TYPE_CLASS.objects.get_for_model(workflow_object)
        for proceeding_meta in ProceedingMeta.objects.filter(content_type=content_type):
            proceeding, created = Proceeding.objects.update_or_create(
                meta=proceeding_meta,
                workflow_object=workflow_object,
                defaults={
                    'order': proceeding_meta.order,
                    'status': PENDING,
                }
            )
            proceeding.permissions.add(*proceeding_meta.permissions.all())
            proceeding.groups.add(*proceeding_meta.groups.all())

        workflow_object.save()
        LOGGER.debug("Proceedings are initialized for workflow object %s" % workflow_object)