Coverage for users/ui/panels.py: 93%

41 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 18:35 +0000

1from django.utils.translation import gettext_lazy as _ 

2 

3from netbox.ui import actions, attrs, panels 

4 

5 

6class TokenPanel(panels.ObjectAttributesPanel): 

7 version = attrs.NumericAttr('version') 

8 key = attrs.TextAttr('key') 

9 token = attrs.TextAttr('partial') 

10 pepper_id = attrs.NumericAttr('pepper_id') 

11 user = attrs.RelatedObjectAttr('user', linkify=True) 

12 description = attrs.TextAttr('description') 

13 enabled = attrs.BooleanAttr('enabled') 

14 write_enabled = attrs.BooleanAttr('write_enabled') 

15 expires = attrs.TextAttr('expires') 

16 last_used = attrs.TextAttr('last_used') 

17 allowed_ips = attrs.ArrayAttr('allowed_ips', label=_('Allowed IPs')) 

18 

19 

20class TokenExamplePanel(panels.Panel): 

21 template_name = 'users/panels/token_example.html' 

22 title = _('Example Usage') 

23 actions = [ 

24 actions.CopyContent('token-example') 

25 ] 

26 

27 

28class UserPanel(panels.ObjectAttributesPanel): 

29 username = attrs.TextAttr('username') 

30 full_name = attrs.TemplatedAttr( 

31 'get_full_name', 

32 label=_('Full name'), 

33 template_name='users/attrs/full_name.html', 

34 ) 

35 email = attrs.TextAttr('email') 

36 date_joined = attrs.DateTimeAttr('date_joined', label=_('Account created'), spec='date') 

37 last_login = attrs.DateTimeAttr('last_login', label=_('Last login'), spec='minutes') 

38 is_active = attrs.BooleanAttr('is_active', label=_('Active')) 

39 is_superuser = attrs.BooleanAttr('is_superuser', label=_('Superuser')) 

40 

41 

42class ObjectPermissionPanel(panels.ObjectAttributesPanel): 

43 name = attrs.TextAttr('name') 

44 description = attrs.TextAttr('description') 

45 enabled = attrs.BooleanAttr('enabled') 

46 

47 

48class ObjectPermissionActionsPanel(panels.ObjectPanel): 

49 template_name = 'users/panels/actions.html' 

50 title = _('Actions') 

51 

52 def get_context(self, context): 

53 obj = context['object'] 

54 

55 crud_actions = [ 

56 (_('View'), 'view' in obj.actions), 

57 (_('Add'), 'add' in obj.actions), 

58 (_('Change'), 'change' in obj.actions), 

59 (_('Delete'), 'delete' in obj.actions), 

60 ] 

61 

62 return { 

63 **super().get_context(context), 

64 'crud_actions': crud_actions, 

65 'registered_actions': obj.get_registered_actions(), 

66 'additional_actions': obj.get_additional_actions(), 

67 } 

68 

69 

70class OwnerPanel(panels.ObjectAttributesPanel): 

71 name = attrs.TextAttr('name') 

72 group = attrs.RelatedObjectAttr('group', linkify=True) 

73 description = attrs.TextAttr('description')