Mercurial > p > roundup > code
comparison roundup/hyperdb.py @ 6401:8bc5faeb7677
Make rev multilink expressions work for anydbm
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Sat, 08 May 2021 12:52:35 +0200 |
| parents | 95183d73ac64 |
| children | 619807d9a2df |
comparison
equal
deleted
inserted
replaced
| 6400:5ce995c33eee | 6401:8bc5faeb7677 |
|---|---|
| 26 import logging | 26 import logging |
| 27 | 27 |
| 28 # roundup modules | 28 # roundup modules |
| 29 from . import date, password | 29 from . import date, password |
| 30 from .support import ensureParentsExist, PrioList | 30 from .support import ensureParentsExist, PrioList |
| 31 from roundup.mlink_expr import Expression | |
| 31 from roundup.i18n import _ | 32 from roundup.i18n import _ |
| 32 from roundup.cgi.exceptions import DetectorError | 33 from roundup.cgi.exceptions import DetectorError |
| 33 from roundup.anypy.cmp_ import NoneAndDictComparable | 34 from roundup.anypy.cmp_ import NoneAndDictComparable |
| 34 from roundup.anypy.strings import eval_import | 35 from roundup.anypy.strings import eval_import |
| 35 | 36 |
| 588 if getattr(p.propclass,'rev_property',None): | 589 if getattr(p.propclass,'rev_property',None): |
| 589 pn = p.propclass.rev_property.name | 590 pn = p.propclass.rev_property.name |
| 590 cl = p.propclass.rev_property.cls | 591 cl = p.propclass.rev_property.cls |
| 591 if not isinstance(p.val, type([])): | 592 if not isinstance(p.val, type([])): |
| 592 p.val = [p.val] | 593 p.val = [p.val] |
| 593 if p.val == ['-1'] : | 594 nval = [int(i) for i in p.val] |
| 594 s1 = set(self.cls.getnodeids(retired=False)) | 595 pval = [str(i) for i in nval if i >= 0] |
| 595 s2 = set() | 596 items = set() |
| 597 if not nval or min(nval) >= -1: | |
| 598 if -1 in nval: | |
| 599 s1 = set(self.cls.getnodeids(retired=False)) | |
| 600 s2 = set() | |
| 601 for id in cl.getnodeids(retired=False): | |
| 602 node = cl.getnode(id) | |
| 603 if node[pn]: | |
| 604 if isinstance(node[pn], type([])): | |
| 605 s2.update(node[pn]) | |
| 606 else: | |
| 607 s2.add(node[pn]) | |
| 608 items |= s1.difference(s2) | |
| 609 if isinstance(p.propclass.rev_property, Link): | |
| 610 items |= set(cl.get(x, pn) for x in pval | |
| 611 if not cl.is_retired(x)) | |
| 612 else: | |
| 613 items |= set().union(*(cl.get(x, pn) for x in pval | |
| 614 if not cl.is_retired(x))) | |
| 615 else: | |
| 616 # Expression: materialize rev multilinks and run | |
| 617 # expression on them | |
| 618 expr = Expression(nval) | |
| 619 by_id = {} | |
| 596 for id in cl.getnodeids(retired=False): | 620 for id in cl.getnodeids(retired=False): |
| 621 by_id[id] = set() | |
| 622 items = set() | |
| 623 for id in self.cls.getnodeids(retired=False): | |
| 597 node = cl.getnode(id) | 624 node = cl.getnode(id) |
| 598 if node[pn]: | 625 if node[pn]: |
| 599 if isinstance(node [pn], type([])): | 626 v = node[pn] |
| 600 s2.update(node [pn]) | 627 if not isinstance(v, type([])): |
| 601 else: | 628 v = [v] |
| 602 s2.add(node [pn]) | 629 for x in v: |
| 603 items = s1.difference(s2) | 630 if x not in by_id: |
| 604 elif isinstance(p.propclass.rev_property, Link): | 631 by_id[x] = set() |
| 605 items = set(cl.get(x, pn) for x in p.val | 632 by_id[x].add(id) |
| 606 if not cl.is_retired(x)) | 633 for k in by_id: |
| 607 else: | 634 if expr.evaluate(by_id[k]): |
| 608 items = set().union(*(cl.get(x, pn) for x in p.val | 635 items.add(k) |
| 609 if not cl.is_retired(x))) | 636 |
| 610 filterspec[p.name] = list(sorted(items)) | 637 filterspec[p.name] = list(sorted(items, key=int)) |
| 611 elif isinstance(p.val, type([])): | 638 elif isinstance(p.val, type([])): |
| 612 exact = [] | 639 exact = [] |
| 613 subst = [] | 640 subst = [] |
| 614 for v in p.val: | 641 for v in p.val: |
| 615 if isinstance(v, Exact_Match): | 642 if isinstance(v, Exact_Match): |
