From: Plom Heller Date: Sat, 30 May 2026 03:05:06 +0000 (+0200) Subject: To designs tables add n_studs column, lookup. X-Git-Url: https://plomlompom.com/repos/booking/process?a=commitdiff_plain;h=4726d45c49089ed2d9e0657fad67e76db8fc55b4;p=bricksplom To designs tables add n_studs column, lookup. --- diff --git a/bricksplom.py b/bricksplom.py index 5daadef..d826f77 100755 --- a/bricksplom.py +++ b/bricksplom.py @@ -166,10 +166,12 @@ class Design(Textfiled, Lookupable): def __init__( self, id_: str, - description='' + n_studs=-1, + description='', ) -> None: self.id_ = id_ self._description = description + self._n_studs = n_studs self.alternate_ids: set[str] = set() @property @@ -178,8 +180,15 @@ class Design(Textfiled, Lookupable): ) -> str: 'Description text wherever found between self and .alternate_to.' return (f'={self.alternate_to.id_}: {self.alternate_to.description}' - if self.alternate_to - else self._description) + if self.alternate_to else self._description) + + @property + def n_studs( + self + ) -> int: + 'Studs count wherever found between self and .alternate_to.' + return (self.alternate_to.n_studs + if self.alternate_to else self._n_studs) @property def all_ids( @@ -206,8 +215,10 @@ class Design(Textfiled, Lookupable): alts[body] = alts.get(body, set()) alts[body].add(design_id) collected[design_id] = cls(design_id) - else: # == CHAR_DESIGN_DESC - collected[design_id] = cls(design_id, body) + else: + n_studs_str, desc = cls.tokify(body, 2) + n_studs = int(n_studs_str) if n_studs_str.isdigit() else -1 + collected[design_id] = cls(design_id, n_studs, desc) for id_, alternate_ids in alts.items(): collected[id_].alternate_ids = alternate_ids for alt_id in alternate_ids: @@ -217,9 +228,11 @@ class Design(Textfiled, Lookupable): def raw( self ) -> str: - return f'{self.id_indented()} ' + (f'={self.alternate_to.id_}' - if self.alternate_to - else f'_{self._description}') + return (f'{self.id_indented()} ' + + (f'={self.alternate_to.id_}' if self.alternate_to + else ('_' + + ('?' if self._n_studs < 0 else str(self._n_studs)) + + f' {self._description}'))) class Piece(Textfiled, WithDb, Lookupable): @@ -561,6 +574,14 @@ class BricksDb: v in sorted(table.values(), key=lambda v: f'{v.id_indented()}') if inquiry[1:].upper() in str(v.searchable()).upper()]) + if table_name == 'designs' and inquiry.startswith('s'): + n_studs_str = inquiry[1:] + assert n_studs_str.isdigit() + return CHAR_NEWLINE.join( + [(v.raw() if show_raw else str(v)) for + v in sorted(table.values(), + key=lambda v: f'{v.id_indented()}') + if v.n_studs == int(n_studs_str)]) item = table[inquiry] return item.raw() if show_raw else item.show()