Coverage for gws-app/gws/base/edit/__init__.py: 100%

0 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""Feature editing. 

2 

3Server side of the client edit tools (``Sidebar.Edit``, ``Toolbar.Edit``). 

4The client lists the editable models of a project, loads features, opens 

5forms, and creates, updates and deletes features through the ``edit`` action. 

6 

7Submodules 

8---------- 

9 

10- ``action`` - the ``edit`` action. Each API command calls two methods of the 

11 helper: one that does the work and returns features, and one that turns the 

12 result into a response. 

13- ``api`` - request and response types of the edit API commands. 

14- ``helper`` - the ``edit`` helper (``root.app.helper('edit')``) with the actual 

15 logic: model and field lookup with permission checks, searching, reading, 

16 validating and writing features, and converting features to props with 

17 their list views (``feature.title``, ``feature.label`` templates). 

18 

19Splitting the work and the response into two helper methods lets other actions 

20reuse the edit logic with their own models or responses, either by calling the 

21helper or by extending it (for example ``gws.plugin.account.helper``). 

22 

23API commands 

24------------ 

25 

26- ``editGetModels`` - editable models of the project for the current user. 

27- ``editGetFeatures`` - features of the given models, filtered by extent, 

28 shapes, keyword or uids. 

29- ``editGetRelatableFeatures`` - features that can be linked in a related field. 

30- ``editGetFeature`` - a single feature for the edit form. 

31- ``editInitFeature`` - a new feature with initial values, not saved yet. 

32- ``editWriteFeature`` - validates and saves a new or existing feature. On 

33 validation errors, the errors are returned instead of the feature. 

34- ``editDeleteFeature`` - deletes a feature. 

35 

36A model is listed for editing if it is configured with ``isEditable`` and the 

37user has the ``edit`` permission on it. Models of layers in the project map, 

38of the project and of the application are considered. Related models of 

39listed models are added if the user can read them. 

40 

41Example:: 

42 

43 actions+ { type "edit" } 

44 client.addElements+ { tag "Sidebar.Edit" } 

45 client.addElements+ { tag "Toolbar.Edit" } 

46 

47 map.layers+ { 

48 title "Points of interest" 

49 type "postgres" 

50 tableName "edit.poi" 

51 models+ { 

52 type "postgres" 

53 isEditable true 

54 permissions.edit "allow all" 

55 } 

56 } 

57"""