@@ -407,12 +407,19 @@ def __init__(self, gl, data=None, **kwargs):
407
407
if not hasattr (self , "id" ):
408
408
self .id = None
409
409
410
- self ._set_managers ()
410
+ def _set_manager (self , var , cls , attrs ):
411
+ manager = cls (self .gitlab , self , attrs )
412
+ setattr (self , var , manager )
411
413
412
- def _set_managers (self ):
414
+ def __getattr__ (self , name ):
415
+ # build a manager if it doesn't exist yet
413
416
for var , cls , attrs in self .managers :
414
- manager = cls (self .gitlab , self , attrs )
415
- setattr (self , var , manager )
417
+ if var != name :
418
+ continue
419
+ self ._set_manager (var , cls , attrs )
420
+ return getattr (self , var )
421
+
422
+ raise AttributeError
416
423
417
424
def __str__ (self ):
418
425
return '%s => %s' % (type (self ), str (self .__dict__ ))
@@ -582,10 +589,10 @@ class User(GitlabObject):
582
589
'projects_limit' , 'extern_uid' , 'provider' , 'bio' ,
583
590
'admin' , 'can_create_group' , 'website_url' ,
584
591
'confirm' , 'external' ]
585
- managers = [
592
+ managers = (
586
593
('emails' , UserEmailManager , [('user_id' , 'id' )]),
587
594
('keys' , UserKeyManager , [('user_id' , 'id' )])
588
- ]
595
+ )
589
596
590
597
def _data_for_gitlab (self , extra_parameters = {}, update = False ,
591
598
as_json = True ):
@@ -690,11 +697,10 @@ class CurrentUser(GitlabObject):
690
697
canUpdate = False
691
698
canDelete = False
692
699
shortPrintAttr = 'username'
693
- managers = [
700
+ managers = (
694
701
('emails' , CurrentUserEmailManager , [('user_id' , 'id' )]),
695
702
('keys' , CurrentUserKeyManager , [('user_id' , 'id' )])
696
- ]
697
-
703
+ )
698
704
699
705
class ApplicationSettings (GitlabObject ):
700
706
_url = '/application/settings'
@@ -867,14 +873,14 @@ class Group(GitlabObject):
867
873
optionalCreateAttrs = ['description' , 'visibility_level' ]
868
874
optionalUpdateAttrs = ['name' , 'path' , 'description' , 'visibility_level' ]
869
875
shortPrintAttr = 'name'
870
- managers = [
876
+ managers = (
871
877
('accessrequests' , GroupAccessRequestManager , [('group_id' , 'id' )]),
872
878
('members' , GroupMemberManager , [('group_id' , 'id' )]),
873
879
('notificationsettings' , GroupNotificationSettingsManager ,
874
880
[('group_id' , 'id' )]),
875
881
('projects' , GroupProjectManager , [('group_id' , 'id' )]),
876
882
('issues' , GroupIssueManager , [('group_id' , 'id' )])
877
- ]
883
+ )
878
884
879
885
GUEST_ACCESS = gitlab .GUEST_ACCESS
880
886
REPORTER_ACCESS = gitlab .REPORTER_ACCESS
@@ -994,8 +1000,8 @@ class ProjectBoard(GitlabObject):
994
1000
canUpdate = False
995
1001
canCreate = False
996
1002
canDelete = False
997
- managers = [ ('lists' , ProjectBoardListManager ,
998
- [('project_id' , 'project_id' ), ('board_id' , 'id' )])]
1003
+ managers = ( ('lists' , ProjectBoardListManager ,
1004
+ [('project_id' , 'project_id' ), ('board_id' , 'id' )]))
999
1005
1000
1006
1001
1007
class ProjectBoardManager (BaseManager ):
@@ -1168,10 +1174,12 @@ class ProjectCommit(GitlabObject):
1168
1174
canCreate = False
1169
1175
requiredUrlAttrs = ['project_id' ]
1170
1176
shortPrintAttr = 'title'
1171
- managers = [('comments' , ProjectCommitCommentManager ,
1172
- [('project_id' , 'project_id' ), ('commit_id' , 'id' )]),
1173
- ('statuses' , ProjectCommitStatusManager ,
1174
- [('project_id' , 'project_id' ), ('commit_id' , 'id' )])]
1177
+ managers = (
1178
+ ('comments' , ProjectCommitCommentManager ,
1179
+ [('project_id' , 'project_id' ), ('commit_id' , 'id' )]),
1180
+ ('statuses' , ProjectCommitStatusManager ,
1181
+ [('project_id' , 'project_id' ), ('commit_id' , 'id' )])
1182
+ )
1175
1183
1176
1184
def diff (self , ** kwargs ):
1177
1185
"""Generate the commit diff."""
@@ -1335,8 +1343,8 @@ class ProjectIssue(GitlabObject):
1335
1343
'milestone_id' , 'labels' , 'created_at' ,
1336
1344
'state_event' ]
1337
1345
shortPrintAttr = 'title'
1338
- managers = [ ('notes' , ProjectIssueNoteManager ,
1339
- [('project_id' , 'project_id' ), ('issue_id' , 'id' )])]
1346
+ managers = ( ('notes' , ProjectIssueNoteManager ,
1347
+ [('project_id' , 'project_id' ), ('issue_id' , 'id' )]))
1340
1348
1341
1349
def _data_for_gitlab (self , extra_parameters = {}, update = False ,
1342
1350
as_json = True ):
@@ -1518,8 +1526,8 @@ class ProjectMergeRequest(GitlabObject):
1518
1526
'milestone_id' ]
1519
1527
optionalListAttrs = ['iid' , 'state' , 'order_by' , 'sort' ]
1520
1528
1521
- managers = [ ('notes' , ProjectMergeRequestNoteManager ,
1522
- [('project_id' , 'project_id' ), ('merge_request_id' , 'id' )])]
1529
+ managers = ( ('notes' , ProjectMergeRequestNoteManager ,
1530
+ [('project_id' , 'project_id' ), ('merge_request_id' , 'id' )]))
1523
1531
1524
1532
def _data_for_gitlab (self , extra_parameters = {}, update = False ,
1525
1533
as_json = True ):
@@ -1827,8 +1835,8 @@ class ProjectSnippet(GitlabObject):
1827
1835
optionalCreateAttrs = ['lifetime' , 'visibility_level' ]
1828
1836
optionalUpdateAttrs = ['title' , 'file_name' , 'code' , 'visibility_level' ]
1829
1837
shortPrintAttr = 'title'
1830
- managers = [ ('notes' , ProjectSnippetNoteManager ,
1831
- [('project_id' , 'project_id' ), ('snippet_id' , 'id' )])]
1838
+ managers = ( ('notes' , ProjectSnippetNoteManager ,
1839
+ [('project_id' , 'project_id' ), ('snippet_id' , 'id' )]))
1832
1840
1833
1841
def Content (self , ** kwargs ):
1834
1842
warnings .warn ("`Content` is deprecated, use `content` instead" ,
@@ -2021,7 +2029,7 @@ class Project(GitlabObject):
2021
2029
'public_builds' ,
2022
2030
'only_allow_merge_if_build_succeeds' ]
2023
2031
shortPrintAttr = 'path'
2024
- managers = [
2032
+ managers = (
2025
2033
('accessrequests' , ProjectAccessRequestManager ,
2026
2034
[('project_id' , 'id' )]),
2027
2035
('boards' , ProjectBoardManager , [('project_id' , 'id' )]),
@@ -2054,7 +2062,7 @@ class Project(GitlabObject):
2054
2062
('tags' , ProjectTagManager , [('project_id' , 'id' )]),
2055
2063
('triggers' , ProjectTriggerManager , [('project_id' , 'id' )]),
2056
2064
('variables' , ProjectVariableManager , [('project_id' , 'id' )]),
2057
- ]
2065
+ )
2058
2066
2059
2067
VISIBILITY_PRIVATE = gitlab .VISIBILITY_PRIVATE
2060
2068
VISIBILITY_INTERNAL = gitlab .VISIBILITY_INTERNAL
@@ -2531,10 +2539,10 @@ class Team(GitlabObject):
2531
2539
shortPrintAttr = 'name'
2532
2540
requiredCreateAttrs = ['name' , 'path' ]
2533
2541
canUpdate = False
2534
- managers = [
2542
+ managers = (
2535
2543
('members' , TeamMemberManager , [('team_id' , 'id' )]),
2536
2544
('projects' , TeamProjectManager , [('team_id' , 'id' )])
2537
- ]
2545
+ )
2538
2546
2539
2547
2540
2548
class TeamManager (BaseManager ):
0 commit comments