Пример #1
0
def _get_logic_environment(ev):
    # Every change to our supported JSON logic must be done
    # * in pretix.base.services.checkin
    # * in pretix.base.models.checkin
    # * in checkinrules.js
    # * in libpretixsync

    def is_before(t1, t2, tolerance=None):
        if tolerance:
            return t1 < t2 + timedelta(minutes=float(tolerance))
        else:
            return t1 < t2

    logic = Logic()
    logic.add_operation('objectList', lambda *objs: list(objs))
    logic.add_operation('lookup', lambda model, pk, str: int(pk))
    logic.add_operation('inList', lambda a, b: a in b)
    logic.add_operation('buildTime', partial(_build_time, ev=ev))
    logic.add_operation('isBefore', is_before)
    logic.add_operation('isAfter',
                        lambda t1, t2, tol=None: is_before(t2, t1, tol))
    return logic
Пример #2
0
def get_logic_environment(ev):
    def build_time(t=None, value=None):
        if t == "custom":
            return dateutil.parser.parse(value)
        elif t == 'date_from':
            return ev.date_from
        elif t == 'date_to':
            return ev.date_to or ev.date_from
        elif t == 'date_admission':
            return ev.date_admission or ev.date_from

    def is_before(t1, t2, tolerance=None):
        if tolerance:
            return t1 < t2 + timedelta(minutes=float(tolerance))
        else:
            return t1 < t2

    logic = Logic()
    logic.add_operation('objectList', lambda *objs: list(objs))
    logic.add_operation('lookup', lambda model, pk, str: int(pk))
    logic.add_operation('inList', lambda a, b: a in b)
    logic.add_operation('buildTime', build_time)
    logic.add_operation('isBefore', is_before)
    logic.add_operation('isAfter',
                        lambda t1, t2, tol=None: is_before(t2, t1, tol))
    return logic
Пример #3
0
def get_logic_environment(ev):
    # Every change to our supported JSON logic must be done
    # * in pretix.base.services.checkin
    # * in pretix.base.models.checkin
    # * in checkinrules.js
    # * in libpretixsync
    def build_time(t=None, value=None):
        if t == "custom":
            return dateutil.parser.parse(value)
        elif t == 'date_from':
            return ev.date_from
        elif t == 'date_to':
            return ev.date_to or ev.date_from
        elif t == 'date_admission':
            return ev.date_admission or ev.date_from

    def is_before(t1, t2, tolerance=None):
        if tolerance:
            return t1 < t2 + timedelta(minutes=float(tolerance))
        else:
            return t1 < t2

    logic = Logic()
    logic.add_operation('objectList', lambda *objs: list(objs))
    logic.add_operation('lookup', lambda model, pk, str: int(pk))
    logic.add_operation('inList', lambda a, b: a in b)
    logic.add_operation('buildTime', build_time)
    logic.add_operation('isBefore', is_before)
    logic.add_operation('isAfter', lambda t1, t2, tol=None: is_before(t2, t1, tol))
    return logic
Пример #4
0
def test_custom_operation():
    logic = Logic()
    logic.add_operation('double', lambda a: a * 2)
    assert logic.apply({'double': [{'var': 'value'}]}, {'value': 3}) == 6