Coverage for gws-app/gws/plugin/model_value/current_user/__init__.py: 0%

15 statements  

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

1"""Current user value. 

2 

3Computes a string from the properties of the current user. 

4 

5If ``format`` is configured, it is a Python format string that refers to the 

6``user`` object, e.g. ``"{user.displayName}_{user.isGuest}"``. Otherwise the 

7user's ``loginName`` is returned. 

8 

9Example:: 

10 

11 fields+ { 

12 name "updated_by" 

13 type "text" 

14 values+ { 

15 type "currentUser" 

16 format "{user.displayName}" 

17 forRead false 

18 forUpdate true 

19 } 

20 } 

21""" 

22 

23import gws 

24import gws.base.model.value 

25 

26 

27@gws.ext.config.modelValue('currentUser') 

28class Config(gws.base.model.value.Config): 

29 """Value derived from the current user.""" 

30 

31 format: str = '' 

32 """Format string for the user value.""" 

33 

34 

35@gws.ext.object.modelValue('currentUser') 

36class Object(gws.base.model.value.Object): 

37 """Current user value object.""" 

38 

39 format: str 

40 """Format string, empty to use the login name.""" 

41 

42 def configure(self): 

43 self.format = self.cfg('format', default='') 

44 

45 def compute(self, field, feature, mc): 

46 if self.format: 

47 return self.format.format(user=mc.user) 

48 return mc.user.loginName