:param label: :param actions: action list action available format: * dict: ``{label:button label, value:button value, [type: button type], [disabled:is disabled?]}`` * tuple or list: ``(label, value, [type], [disabled])`` * single value: label and value of b
(buttons)
| 445 | |
| 446 | |
| 447 | def _parse_action_buttons(buttons): |
| 448 | """ |
| 449 | :param label: |
| 450 | :param actions: action list |
| 451 | action available format: |
| 452 | |
| 453 | * dict: ``{label:button label, value:button value, [type: button type], [disabled:is disabled?]}`` |
| 454 | * tuple or list: ``(label, value, [type], [disabled])`` |
| 455 | * single value: label and value of button share the same value |
| 456 | |
| 457 | :return: dict format |
| 458 | """ |
| 459 | act_res = [] |
| 460 | for act in buttons: |
| 461 | act = copy.deepcopy(act) |
| 462 | if isinstance(act, Mapping): |
| 463 | assert 'label' in act, 'actions item must have label key' |
| 464 | assert 'value' in act or act.get('type', 'submit') != 'submit' or act.get('disabled'), \ |
| 465 | 'actions item must have value key for submit type' |
| 466 | elif isinstance(act, (list, tuple)): |
| 467 | assert len(act) in (2, 3, 4), 'actions item format error' |
| 468 | act = dict(zip(('label', 'value', 'type', 'disabled'), act)) |
| 469 | else: |
| 470 | act = dict(value=act, label=act) |
| 471 | |
| 472 | act.setdefault('type', 'submit') |
| 473 | assert act['type'] in ('submit', 'reset', 'cancel'), \ |
| 474 | "submit type must be 'submit'/'reset'/'cancel', not %r" % act['type'] |
| 475 | act_res.append(act) |
| 476 | |
| 477 | return act_res |
| 478 | |
| 479 | |
| 480 | def actions(label: str = '', buttons: List[Union[Dict[str, Any], Tuple, List, str]] = None, name: str = None, |