Roundup Tracker - Issues

Message8172

Author schlatterbeck
Recipients rouilj, schlatterbeck
Date 2024-10-28.14:30:08
Message-id <20241028142957.plklq2juztpdymjn@runtux.com>
In-reply-to <20241027191700.oq6l2wmcz3fqzidw@runtux.com>
On Sun, Oct 27, 2024 at 07:17:04PM +0000, Ralf Schlatterbeck wrote:
> Yes, the filter function *always* duplicates the check function.
> I don't know if this makes the check function redundant and if we could
> automagically derive a check function from a filter function. I guess it
> could be done by passing the current itemid through the filter,
> something along the lines of
> 
> def check (db, userid, itemid, klass, filter_function):
>     args = filter_function (db, userid, klass)
>     if klass.filter ([itemid], **args):
>         return True

This would need to be a loop:
def check (db, userid, itemid, klass, filter_function):
    args = filter_function (db, userid, klass)
    for a in args:
        if klass.filter ([itemid], **a):
            return True

> 
> Note that the check function currently has no knowledge of the klass and
> the filter function. But it would certainly be possible to write a
> factory that can return a check function from a given filter function,
> and klass according to the recipe above. Like so:
> 
> def check_factory (klass, filter_function):
>     def check (db, userid, itemid):
>         args = filter_function (db, userid, klass)
>         if klass.filter ([itemid], **args):
>             return True
>     return check

Same here, need to loop over filter args:
def check_factory (klass, filter_function):
    def check (db, userid, itemid):
        args = filter_function (db, userid, klass)
        for a in args:
            if klass.filter ([itemid], **a):
                return True
    return check

KR, Ralf
-- 
Dr. Ralf Schlatterbeck                  Tel:   +43/2243/26465-16
Open Source Consulting                  www:   www.runtux.com
Reichergasse 131, A-3411 Weidling       email: office@runtux.com
History
Date User Action Args
2024-10-28 14:30:09schlatterbecksetrecipients: + schlatterbeck, rouilj
2024-10-28 14:30:08schlatterbecklinkissue2551330 messages
2024-10-28 14:30:08schlatterbeckcreate