<commit_before>from DateTime import DateTime
from Products.Archetypes.config import REFERENCE_CATALOG
from Products.CMFCore.WorkflowCore import WorkflowException
from Products.CMFCore.utils import getToolByName
from bika.lims import bikaMessageFactory as _
import transaction

def AfterTransitionEventHandler(instance, event):

    # creation doesn't have a 'transition'
    if not event.transition:
        return

    wf = getToolByName(instance, 'portal_workflow')
    pc = getToolByName(instance, 'portal_catalog')
    rc = getToolByName(instance, REFERENCE_CATALOG)
    pu = getToolByName(instance, 'plone_utils')

    if event.action == "deactivate":
        # A service cannot be deactivated if "active" calculations list it
        # as a dependency.
        calculations = (c.getObject() for c in \
                        pc(portal_type='Calculation', inactive_state="active"))
        for calc in calculations:
            deps = [dep.UID() for dep in calc.getDependentServices()]
            if instance.UID() in deps:
                message = _("This Analysis Service cannot be deactivated "
                            "because one or more active calculations list "
                            "it as a dependency")
                pu.addPortalMessage(message, 'error')
                transaction.get().abort()
                raise WorkflowException

    if event.action == "activate":
        # A service cannot be activated if it's calculation is inactive
        calc = instance.getCalculation()
        if calc and \
           wf.getInfoFor(calc, "inactive_state") == "inactive":
            message = _("This Analysis Service cannot be activated "
                        "because it's calculation is inactive.")
            pu.addPortalMessage(message, 'error')
            transaction.get().abort()
            raise WorkflowException
<commit_msg>Fix #89<commit_after>from DateTime import DateTime
from Products.Archetypes.config import REFERENCE_CATALOG
from Products.CMFCore.WorkflowCore import WorkflowException
from Products.CMFCore.utils import getToolByName
from bika.lims import bikaMessageFactory as _
import transaction

def AfterTransitionEventHandler(instance, event):

    # creation doesn't have a 'transition'
    if not event.transition:
        return

    wf = getToolByName(instance, 'portal_workflow')
    pc = getToolByName(instance, 'portal_catalog')
    rc = getToolByName(instance, REFERENCE_CATALOG)
    pu = getToolByName(instance, 'plone_utils')

    if event.transition.id == "deactivate":
        # A service cannot be deactivated if "active" calculations list it
        # as a dependency.
        calculations = (c.getObject() for c in \
                        pc(portal_type='Calculation', inactive_state="active"))
        for calc in calculations:
            deps = [dep.UID() for dep in calc.getDependentServices()]
            if instance.UID() in deps:
                message = _("This Analysis Service cannot be deactivated "
                            "because one or more active calculations list "
                            "it as a dependency")
                pu.addPortalMessage(message, 'error')
                transaction.get().abort()
                raise WorkflowException

    if event.transition.id == "activate":
        # A service cannot be activated if it's calculation is inactive
        calc = instance.getCalculation()
        if calc and \
           wf.getInfoFor(calc, "inactive_state") == "inactive":
            message = _("This Analysis Service cannot be activated "
                        "because it's calculation is inactive.")
            pu.addPortalMessage(message, 'error')
            transaction.get().abort()
            raise WorkflowException

{'fraction_non_alphanumeric': 0.08018114011720831, 'fraction_numerical': 0.0005327650506126798, 'mean_word_length': 2.4323583180987205, 'pattern_counts': {'":': 6, '<': 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': '2636287', 'n_tokens_mistral': 958, 'n_tokens_neox': 936, 'n_words': 299}