changeset 5294:cd655fbd79ce

repogroups: compute repo group id lists on demand where they are needed
author Mads Kiilerich <madski@unity3d.com>
date Thu, 23 Jul 2015 00:52:29 +0200
parents 8e87c16ac58e
children fa8b8df51ad0
files kallithea/controllers/admin/repo_groups.py kallithea/controllers/admin/repos.py kallithea/controllers/forks.py kallithea/model/forms.py
diffstat 4 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/repo_groups.py	Thu Jul 23 00:52:29 2015 +0200
+++ b/kallithea/controllers/admin/repo_groups.py	Thu Jul 23 00:52:29 2015 +0200
@@ -72,7 +72,6 @@
         exclude_group_ids = set(rg.group_id for rg in exclude)
         c.repo_groups = [rg for rg in repo_groups
                          if rg[0] not in exclude_group_ids]
-        c.repo_groups_choices = [rg[0] for rg in c.repo_groups]
 
         repo_model = RepoModel()
         c.users_array = repo_model.get_users_js()
@@ -164,7 +163,7 @@
 
         # permissions for can create group based on parent_id are checked
         # here in the Form
-        repo_group_form = RepoGroupForm(available_groups=c.repo_groups_choices)
+        repo_group_form = RepoGroupForm(repo_groups=c.repo_groups)
         try:
             form_result = repo_group_form.to_python(dict(request.POST))
             gr = RepoGroupModel().create(
@@ -240,7 +239,7 @@
         repo_group_form = RepoGroupForm(
             edit=True,
             old_data=c.repo_group.get_dict(),
-            available_groups=c.repo_groups_choices,
+            repo_groups=c.repo_groups,
             can_create_in_root=allow_empty_group,
         )()
         try:
--- a/kallithea/controllers/admin/repos.py	Thu Jul 23 00:52:29 2015 +0200
+++ b/kallithea/controllers/admin/repos.py	Thu Jul 23 00:52:29 2015 +0200
@@ -83,7 +83,6 @@
         extras = [] if repo is None else [repo.group]
 
         c.repo_groups = AvailableRepoGroupChoices(top_perms, repo_group_perms, extras)
-        c.repo_groups_choices = [rg[0] for rg in c.repo_groups]
 
         c.landing_revs_choices, c.landing_revs = ScmModel().get_repo_landing_revs(repo)
 
@@ -128,7 +127,7 @@
         task_id = None
         try:
             # CanWriteGroup validators checks permissions of this POST
-            form_result = RepoForm(repo_groups=c.repo_groups_choices,
+            form_result = RepoForm(repo_groups=c.repo_groups,
                                    landing_revs=c.landing_revs_choices)()\
                             .to_python(dict(request.POST))
 
@@ -253,7 +252,7 @@
             'repo_type': repo.repo_type,
         }
         _form = RepoForm(edit=True, old_data=old_data,
-                         repo_groups=c.repo_groups_choices,
+                         repo_groups=c.repo_groups,
                          landing_revs=c.landing_revs_choices)()
 
         try:
--- a/kallithea/controllers/forks.py	Thu Jul 23 00:52:29 2015 +0200
+++ b/kallithea/controllers/forks.py	Thu Jul 23 00:52:29 2015 +0200
@@ -60,7 +60,6 @@
         if HasPermissionAny('hg.create.write_on_repogroup.true')():
             repo_group_perms.append('group.write')
         c.repo_groups = AvailableRepoGroupChoices(['hg.create.repository'], repo_group_perms)
-        c.repo_groups_choices = [rg[0] for rg in c.repo_groups]
 
         c.landing_revs_choices, c.landing_revs = ScmModel().get_repo_landing_revs()
 
@@ -158,7 +157,7 @@
         self.__load_defaults()
         c.repo_info = Repository.get_by_repo_name(repo_name)
         _form = RepoForkForm(old_data={'repo_type': c.repo_info.repo_type},
-                             repo_groups=c.repo_groups_choices,
+                             repo_groups=c.repo_groups,
                              landing_revs=c.landing_revs_choices)()
         form_result = {}
         task_id = None
--- a/kallithea/model/forms.py	Thu Jul 23 00:52:29 2015 +0200
+++ b/kallithea/model/forms.py	Thu Jul 23 00:52:29 2015 +0200
@@ -145,8 +145,9 @@
     return _UserGroupForm
 
 
-def RepoGroupForm(edit=False, old_data={}, available_groups=[],
+def RepoGroupForm(edit=False, old_data={}, repo_groups=[],
                    can_create_in_root=False):
+    repo_group_ids = [rg[0] for rg in repo_groups]
     class _RepoGroupForm(formencode.Schema):
         allow_extra_fields = True
         filter_extra_fields = False
@@ -162,8 +163,9 @@
             #FIXME: do a special check that we cannot move a group to one of
             #its children
             pass
+
         group_parent_id = All(v.CanCreateGroup(can_create_in_root),
-                              v.OneOf(available_groups, hideList=False,
+                              v.OneOf(repo_group_ids, hideList=False,
                                       testValueList=True,
                                       if_missing=None, not_empty=True),
                               v.Int(min=-1, not_empty=True))
@@ -209,13 +211,14 @@
 
 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
              repo_groups=[], landing_revs=[]):
+    repo_group_ids = [rg[0] for rg in repo_groups]
     class _RepoForm(formencode.Schema):
         allow_extra_fields = True
         filter_extra_fields = False
         repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
                         v.SlugifyName())
         repo_group = All(v.CanWriteGroup(old_data),
-                         v.OneOf(repo_groups, hideList=True),
+                         v.OneOf(repo_group_ids, hideList=True),
                          v.Int(min=-1, not_empty=True))
         repo_type = v.OneOf(supported_backends, required=False,
                             if_missing=old_data.get('repo_type'))
@@ -283,13 +286,14 @@
 
 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
                  repo_groups=[], landing_revs=[]):
+    repo_group_ids = [rg[0] for rg in repo_groups]
     class _RepoForkForm(formencode.Schema):
         allow_extra_fields = True
         filter_extra_fields = False
         repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
                         v.SlugifyName())
         repo_group = All(v.CanWriteGroup(),
-                         v.OneOf(repo_groups, hideList=True),
+                         v.OneOf(repo_group_ids, hideList=True),
                          v.Int(min=-1, not_empty=True))
         repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
         description = v.UnicodeString(strip=True, min=1, not_empty=True)