Coverage for src / lexigram / admin / ui / actions / standard.py: 33%

61 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-11 02:25 +0800

1""" 

2Standard Action implementations for common operations. 

3 

4These classes provide pre-configured defaults for Edit, View, Delete, 

5and Create actions, while allowing full customization via the fluent API. 

6""" 

7 

8from __future__ import annotations 

9 

10from typing import Self 

11 

12from lexigram.admin.ui.actions.base import Action, BulkAction 

13from lexigram.ui import Zones 

14 

15 

16class EditAction(Action): 

17 """Standard Edit action implementation.""" 

18 

19 def __init__(self, name: str = "edit", label: str = "Edit"): 

20 super().__init__(name, label) 

21 self._icon = "pencil" 

22 self._color = "primary" 

23 self._hx_target = "body" 

24 self._hx_swap = "beforeend" 

25 self.slide_over() 

26 

27 def using_form_modal(self) -> Self: 

28 """Configure to open in a modal.""" 

29 self._open_modal = True 

30 return self 

31 

32 

33class ViewAction(Action): 

34 """Standard View action implementation.""" 

35 

36 def __init__(self, name: str = "view", label: str = "View"): 

37 super().__init__(name, label) 

38 self._icon = "eye" 

39 self._color = "gray" 

40 

41 

42class DeleteAction(Action): 

43 """Standard Delete action implementation.""" 

44 

45 def __init__(self, name: str = "delete", label: str = "Delete"): 

46 super().__init__(name, label) 

47 self._icon = "trash" 

48 self._color = "danger" 

49 self._requires_confirmation = True 

50 # Load delete confirmation into the slide-over instead of browser confirm 

51 self._hx_target = Zones.SLIDE_OVER.selector 

52 self._hx_swap = Zones.SLIDE_OVER.swap_mode.value 

53 self._hx_push_url = "false" 

54 

55 

56class CreateAction(Action): 

57 """Standard Create action implementation (Header Action).""" 

58 

59 def __init__(self, name: str = "create", label: str = "Create"): 

60 super().__init__(name, label) 

61 self._icon = "plus" 

62 self._color = "primary" 

63 self._hx_target = Zones.SLIDE_OVER.selector 

64 self._hx_swap = Zones.SLIDE_OVER.swap_mode.value 

65 

66 def using_form_modal(self) -> Self: 

67 """Configure to open in a modal.""" 

68 self._open_modal = True 

69 return self 

70 

71 

72class ExportAction(Action): 

73 """Standard Export action implementation.""" 

74 

75 def __init__(self, name: str = "export", label: str = "Export"): 

76 super().__init__(name, label) 

77 self._icon = "download" 

78 self._color = "gray" 

79 

80 

81class DeleteBulkAction(BulkAction): 

82 """Standard Bulk Delete action.""" 

83 

84 def __init__(self, name: str = "delete", label: str = "Delete Selected"): 

85 super().__init__(name, label) 

86 self._icon = "trash" 

87 self._color = "danger" 

88 self._requires_confirmation = True 

89 self._confirmation_title = "Delete Selected Records" 

90 self._confirmation_message = "Are you sure you would like to delete the selected records? This action cannot be undone." 

91 from lexigram.ui import Zones 

92 

93 self._hx_target = Zones.SLIDE_OVER.selector 

94 self._deselect_after = True 

95 

96 

97class ExportBulkAction(BulkAction): 

98 """Standard Bulk Export action.""" 

99 

100 def __init__(self, name: str = "export", label: str = "Export Selected"): 

101 super().__init__(name, label) 

102 self._icon = "download" 

103 self._color = "gray" 

104 self._deselect_after = True