utils.py 929 Bytes
Newer Older
Janez K's avatar
Janez K committed
1
from workflows.models import *
2
from workflows.toposort import toposort
Janez K's avatar
Janez K committed
3 4

def checkForCycles(widget,targetWidget):
5 6 7 8 9 10 11 12 13 14 15
    pairs = []
    for c in widget.workflow.connections.select_related("output","input").defer("output__value","input__value").all():
        if not (c.output.widget_id,c.input.widget_id) in pairs:
            pairs.append((c.output.widget_id,c.input.widget_id))
    try:
        toposort(pairs,None,True,True)
    except:
        return False
    return True

def slowCheckForCycles(widget,targetWidget):
Janez K's avatar
Janez K committed
16 17
    noCycles = True
    for c in Connection.objects.filter(input__widget=widget):
18
        if Widget.objects.get(outputs__pk=c.output_id)==targetWidget:
Janez K's avatar
Janez K committed
19 20
            noCycles = False
            return False
21
        noCycles = noCycles and checkForCycles(Widget.objects.get(outputs__pk=c.output_id),targetWidget)
Janez K's avatar
Janez K committed
22 23 24
        if noCycles == False:
            return False
    return noCycles