small fixes
- set child default object to field key - strip whitespace if split - ignore case for sort order - setup.py package instead of module
This commit is contained in:
@@ -42,8 +42,8 @@ class GroupByPlugin(Plugin):
|
||||
def _fn(args: GroupByCallbackArgs) -> Iterator[str]:
|
||||
val = args.field
|
||||
if isinstance(val, str):
|
||||
val = val.split(split) if split else [val] # make list
|
||||
if isinstance(val, list):
|
||||
val = map(str.strip, val.split(split)) if split else [val]
|
||||
if isinstance(val, (list, map)):
|
||||
yield from val
|
||||
|
||||
def on_before_build_all(self, builder: Builder, **extra: object) -> None:
|
||||
|
||||
@@ -121,7 +121,7 @@ class GroupBySource(VirtualSourceObject):
|
||||
|
||||
def __lt__(self, other: 'GroupBySource') -> bool:
|
||||
# Used for |sort filter ("group" is the provided original string)
|
||||
return self.group < other.group
|
||||
return self.group.lower() < other.group.lower()
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
# Used for |unique filter
|
||||
|
||||
@@ -150,7 +150,7 @@ class Watcher:
|
||||
while True:
|
||||
if not isinstance(obj, (str, tuple)):
|
||||
raise TypeError(f'Unsupported groupby yield: {obj}')
|
||||
slug = self._persist(record, obj)
|
||||
slug = self._persist(record, key, obj)
|
||||
# return slugified group key and continue iteration
|
||||
if isinstance(_gen, Generator) and not _gen.gi_yieldfrom:
|
||||
obj = _gen.send(slug)
|
||||
@@ -159,7 +159,12 @@ class Watcher:
|
||||
except StopIteration:
|
||||
del _gen
|
||||
|
||||
def _persist(self, record: Record, obj: Union[str, tuple]) -> str:
|
||||
def _persist(
|
||||
self,
|
||||
record: Record,
|
||||
key: FieldKeyPath,
|
||||
obj: Union[str, tuple]
|
||||
) -> str:
|
||||
group = obj if isinstance(obj, str) else obj[0]
|
||||
slug = self.config.slugify(group)
|
||||
# init group-key
|
||||
@@ -174,6 +179,8 @@ class Watcher:
|
||||
# (optional) append extra
|
||||
if isinstance(obj, tuple):
|
||||
self._state[slug][record].append(obj[1])
|
||||
else:
|
||||
self._state[slug][record].append(key.flowKey or key.fieldKey)
|
||||
return slug
|
||||
|
||||
def iter_sources(self, root: Record) -> Iterator[GroupBySource]:
|
||||
|
||||
Reference in New Issue
Block a user