uf.organization#
Function grouping and organization for uf.
Provides tools for organizing functions into categories, groups, and hierarchies for better navigation in the UI.
Functions
|
Automatically group functions by their module. |
|
Automatically group functions by name prefix. |
|
Automatically group functions by a tag attribute. |
|
Create a uf app with grouped function navigation. |
Classes
|
Group of functions with metadata. |
Organize functions into groups and hierarchies. |
- class uf.organization.FunctionGroup(name, funcs=<factory>, description='', icon=None, order=0, collapsed=False)[source]#
Bases:
objectGroup of functions with metadata.
- name#
Name of the group
- funcs#
Functions in this group: callables (partials and callable instances are fine; they are named as
uf.specs.name_of_funcdoes), or a{name: callable}mapping to name them explicitly
- description#
Description of the group
- icon#
Optional icon identifier for the group
- order#
Display order (lower numbers first)
- collapsed#
Whether the group starts collapsed in UI
Example
>>> math_funcs = FunctionGroup( ... 'Math', ... [add, subtract, multiply, divide], ... description='Mathematical operations', ... icon='calculator' ... )
- add_function(func, *, name=None)[source]#
Add a function to this group.
- Parameters:
- Return type:
- Returns:
Self for method chaining
- Raises:
ValueError – If a different callable already has that name in the group
- class uf.organization.FunctionOrganizer[source]#
Bases:
objectOrganize functions into groups and hierarchies.
This class provides a fluent interface for building function organization structures that can be used to generate grouped navigation in the UI.
Example
>>> organizer = FunctionOrganizer() >>> organizer.group('Admin', [user_create, user_delete], icon='shield') >>> organizer.group('Reports', [generate_report, export_csv], icon='file') >>> groups = organizer.get_groups()
- add_to_group(group_name, func)[source]#
Add a function to an existing group.
- Parameters:
- Return type:
- Returns:
Self for method chaining
- Raises:
ValueError – If group doesn’t exist
- add_ungrouped(func)[source]#
Add a function without a group.
- Parameters:
func (
Callable) – Function to add- Return type:
- Returns:
Self for method chaining
- get_groups()[source]#
Get all groups, sorted by order.
- Return type:
- Returns:
List of FunctionGroup objects sorted by order
- group(name, funcs=None, *, description='', icon=None, order=0, collapsed=False)[source]#
Create and add a function group.
- Parameters:
- Return type:
- Returns:
The created FunctionGroup
Example
>>> organizer.group( ... 'Database', ... [save_record, load_record], ... description='Database operations', ... icon='database' ... )
- uf.organization.auto_group_by_module(funcs)[source]#
Automatically group functions by their module.
- Parameters:
- Return type:
- Returns:
FunctionOrganizer with module-based groups (a
functools.partialgoes with the module of the function it wraps)
Example
>>> from myapp import user_ops, report_ops >>> funcs = [user_ops.create, user_ops.delete, report_ops.generate] >>> organizer = auto_group_by_module(funcs)
- uf.organization.auto_group_by_prefix(funcs, separator='_')[source]#
Automatically group functions by name prefix.
Groups functions based on the part of their name before the separator. For example, with separator=”_”:
user_create, user_delete → “user” group
report_generate, report_export → “report” group
- Parameters:
- Return type:
- Returns:
FunctionOrganizer with auto-generated groups
Example
>>> funcs = [user_create, user_delete, report_generate, admin_reset] >>> organizer = auto_group_by_prefix(funcs) >>> # Creates groups: 'user', 'report', 'admin'
- uf.organization.auto_group_by_tag(funcs, tag_attr='__uf_group__')[source]#
Automatically group functions by a tag attribute.
Functions can be tagged with a group name using an attribute.
- Parameters:
- Return type:
- Returns:
FunctionOrganizer with tag-based groups
Example
>>> def create_user(name: str): ... pass >>> create_user.__uf_group__ = 'Admin' >>> >>> organizer = auto_group_by_tag([create_user, other_func])
- uf.organization.mk_grouped_app(groups, **mk_rjsf_app_kwargs)[source]#
Create a uf app with grouped function navigation.
- Parameters:
groups (
Iterable[FunctionGroup]) – Iterable of FunctionGroup objects**mk_rjsf_app_kwargs – Arguments passed to mk_rjsf_app
- Returns:
Configured web application with grouped navigation
Example
>>> admin_group = FunctionGroup('Admin', [user_create, user_delete]) >>> reports_group = FunctionGroup('Reports', [generate_report]) >>> app = mk_grouped_app([admin_group, reports_group])