<commit_before>from datetime import datetime
from django.db.transaction import atomic

from river.models.approvement import APPROVED, REJECTED, Approvement, PENDING
from river.services.approvement import ApprovementService
from river.services.state import StateService
from river.signals import workflow_is_completed, on_transition
from river.utils.error_code import ErrorCode
from river.utils.exceptions import RiverException

__author__ = 'ahmetdal'


class TransitionService(object):
    def __init__(self):
        pass

    @staticmethod
    @atomic
    def approve_transition(workflow_object, field, user, next_state=None, god_mod=False):
        approvement = TransitionService.process(workflow_object, field, user, APPROVED, next_state, god_mod)

        current_state = getattr(workflow_object, field)
        # Any other approvement is left?
        required_approvements = ApprovementService.get_approvements_object_waiting_for_approval(workflow_object, field, [current_state], destination_state=next_state, god_mod=god_mod)
        if required_approvements.count() == 0:
            setattr(workflow_object, field, approvement.meta.transition.destination_state)
            workflow_object.save()

            # Next states should be PENDING back again if there is circle.
            Approvement.objects.filter(workflow_object=workflow_object, field=field, meta__transition__source_state=approvement.meta.transition.destination_state).update(status=PENDING)

        if current_state != getattr(workflow_object, field):
            on_transition.send(sender=TransitionService.__class__, workflow_object=workflow_object, field=field, approvement=approvement, source_state=current_state,
                               destination_state=getattr(workflow_object, field))
        if workflow_object.on_final_state:
            workflow_is_completed.send(sender=TransitionService, workflow_object=workflow_object, field=field)

    @staticmethod
    @atomic
    def reject_transition(workflow_object, field, user, next_state=None):
        TransitionService.process(workflow_object, field, user, REJECTED, next_state)

    @staticmethod
    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()<commit_msg>next states are all PENDING when it is approved<commit_after>from datetime import datetime
from django.db.transaction import atomic

from river.models.approvement import APPROVED, REJECTED, Approvement, PENDING
from river.services.approvement import ApprovementService
from river.services.state import StateService
from river.signals import workflow_is_completed, on_transition
from river.utils.error_code import ErrorCode
from river.utils.exceptions import RiverException

__author__ = 'ahmetdal'


class TransitionService(object):
    def __init__(self):
        pass

    @staticmethod
    @atomic
    def approve_transition(workflow_object, field, user, next_state=None, god_mod=False):
        approvement = TransitionService.process(workflow_object, field, user, APPROVED, next_state, god_mod)

        current_state = getattr(workflow_object, field)
        # Any other approvement is left?
        required_approvements = ApprovementService.get_approvements_object_waiting_for_approval(workflow_object, field, [current_state], destination_state=next_state, god_mod=god_mod)
        if required_approvements.count() == 0:
            setattr(workflow_object, field, approvement.meta.transition.destination_state)
            workflow_object.save()

            # Next states should be PENDING back again if there is circle.
            ApprovementService.get_next_approvements(workflow_object, field).update(status=PENDING)

        if current_state != getattr(workflow_object, field):
            on_transition.send(sender=TransitionService.__class__, workflow_object=workflow_object, field=field, approvement=approvement, source_state=current_state,
                               destination_state=getattr(workflow_object, field))
        if workflow_object.on_final_state:
            workflow_is_completed.send(sender=TransitionService, workflow_object=workflow_object, field=field)

    @staticmethod
    @atomic
    def reject_transition(workflow_object, field, user, next_state=None):
        TransitionService.process(workflow_object, field, user, REJECTED, next_state)

    @staticmethod
    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()
{'fraction_non_alphanumeric': 0.07229894394800974, 'fraction_numerical': 0.00040617384240454913, 'mean_word_length': 4.713457076566125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5804183', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1353, 'n_words': 286}