changeset 2472:e70ebd6db3fa beta

validating choices for landing_rev
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 15 Jun 2012 00:05:20 +0200
parents 60bda63b64f0
children 1fd11b9d2dba
files rhodecode/controllers/admin/repos.py rhodecode/controllers/settings.py rhodecode/model/forms.py rhodecode/model/scm.py
diffstat 4 files changed, 30 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/admin/repos.py	Thu Jun 14 23:19:26 2012 +0200
+++ b/rhodecode/controllers/admin/repos.py	Fri Jun 15 00:05:20 2012 +0200
@@ -70,7 +70,8 @@
         repo_model = RepoModel()
         c.users_array = repo_model.get_users_js()
         c.users_groups_array = repo_model.get_users_groups_js()
-        c.landing_revs = ScmModel().get_repo_landing_revs()
+        choices, c.landing_revs = ScmModel().get_repo_landing_revs()
+        c.landing_revs_choices = choices
 
     def __load_data(self, repo_name=None):
         """
@@ -92,7 +93,9 @@
 
             return redirect(url('repos'))
 
-        c.landing_revs = ScmModel().get_repo_landing_revs(c.repo_info)
+        choices, c.landing_revs = ScmModel().get_repo_landing_revs(c.repo_info)
+        c.landing_revs_choices = choices
+
         c.default_user_id = User.get_by_username('default').user_id
         c.in_public_journal = UserFollowing.query()\
             .filter(UserFollowing.user_id == c.default_user_id)\
@@ -140,7 +143,8 @@
         self.__load_defaults()
         form_result = {}
         try:
-            form_result = RepoForm(repo_groups=c.repo_groups_choices)()\
+            form_result = RepoForm(repo_groups=c.repo_groups_choices,
+                                   landing_revs=c.landing_revs_choices)()\
                             .to_python(dict(request.POST))
             RepoModel().create(form_result, self.rhodecode_user)
             if form_result['clone_uri']:
@@ -208,7 +212,8 @@
         repo_model = RepoModel()
         changed_name = repo_name
         _form = RepoForm(edit=True, old_data={'repo_name': repo_name},
-                         repo_groups=c.repo_groups_choices)()
+                         repo_groups=c.repo_groups_choices,
+                         landing_revs=c.landing_revs_choices)()
         try:
             form_result = _form.to_python(dict(request.POST))
             repo = repo_model.update(repo_name, form_result)
--- a/rhodecode/controllers/settings.py	Thu Jun 14 23:19:26 2012 +0200
+++ b/rhodecode/controllers/settings.py	Fri Jun 15 00:05:20 2012 +0200
@@ -43,6 +43,7 @@
 from rhodecode.model.repo import RepoModel
 from rhodecode.model.db import RepoGroup
 from rhodecode.model.meta import Session
+from rhodecode.model.scm import ScmModel
 
 log = logging.getLogger(__name__)
 
@@ -60,6 +61,8 @@
         repo_model = RepoModel()
         c.users_array = repo_model.get_users_js()
         c.users_groups_array = repo_model.get_users_groups_js()
+        choices, c.landing_revs = ScmModel().get_repo_landing_revs()
+        c.landing_revs_choices = choices
 
     @HasRepoPermissionAllDecorator('repository.admin')
     def index(self, repo_name):
@@ -94,7 +97,8 @@
 
         _form = RepoSettingsForm(edit=True,
                                  old_data={'repo_name': repo_name},
-                                 repo_groups=c.repo_groups_choices)()
+                                 repo_groups=c.repo_groups_choices,
+                                 landing_revs=c.landing_revs_choices)()
         try:
             form_result = _form.to_python(dict(request.POST))
 
--- a/rhodecode/model/forms.py	Thu Jun 14 23:19:26 2012 +0200
+++ b/rhodecode/model/forms.py	Fri Jun 15 00:05:20 2012 +0200
@@ -653,7 +653,7 @@
 
 
 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
-             repo_groups=[]):
+             repo_groups=[], landing_revs=[]):
     class _RepoForm(formencode.Schema):
         allow_extra_fields = True
         filter_extra_fields = False
@@ -666,7 +666,7 @@
         private = StringBoolean(if_missing=False)
         enable_statistics = StringBoolean(if_missing=False)
         enable_downloads = StringBoolean(if_missing=False)
-        landing_rev = UnicodeString(strip=True, min=1, not_empty=True)
+        landing_rev = OneOf(landing_revs, hideList=True)
 
         if edit:
             #this is repo owner
@@ -678,8 +678,8 @@
     return _RepoForm
 
 
-def RepoForkForm(edit=False, old_data={},
-                 supported_backends=BACKENDS.keys(), repo_groups=[]):
+def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
+                 repo_groups=[]):
     class _RepoForkForm(formencode.Schema):
         allow_extra_fields = True
         filter_extra_fields = False
@@ -697,8 +697,8 @@
     return _RepoForkForm
 
 
-def RepoSettingsForm(edit=False, old_data={},
-                     supported_backends=BACKENDS.keys(), repo_groups=[]):
+def RepoSettingsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
+                     repo_groups=[], landing_revs=[]):
     class _RepoForm(formencode.Schema):
         allow_extra_fields = True
         filter_extra_fields = False
@@ -707,7 +707,7 @@
         description = UnicodeString(strip=True, min=1, not_empty=True)
         repo_group = OneOf(repo_groups, hideList=True)
         private = StringBoolean(if_missing=False)
-        landing_rev = UnicodeString(strip=True, min=1, not_empty=True)
+        landing_rev = OneOf(landing_revs, hideList=True)
         chained_validators = [ValidRepoName(edit, old_data), ValidPerms(),
                               ValidSettings]
     return _RepoForm
--- a/rhodecode/model/scm.py	Thu Jun 14 23:19:26 2012 +0200
+++ b/rhodecode/model/scm.py	Fri Jun 15 00:05:20 2012 +0200
@@ -482,24 +482,31 @@
         :param repo:
         :type repo:
         """
+
         hist_l = []
+        choices = []
         repo = self.__get_repo(repo)
         hist_l.append(['tip', _('latest tip')])
+        choices.append('tip')
         if not repo:
-            return hist_l
+            return choices, hist_l
 
         repo = repo.scm_instance
+
         branches_group = ([(k, k) for k, v in
                            repo.branches.iteritems()], _("Branches"))
         hist_l.append(branches_group)
+        choices.extend([x[0] for x in branches_group[0]])
 
         if repo.alias == 'hg':
             bookmarks_group = ([(k, k) for k, v in
                                 repo.bookmarks.iteritems()], _("Bookmarks"))
             hist_l.append(bookmarks_group)
+            choices.extend([x[0] for x in bookmarks_group[0]])
 
         tags_group = ([(k, k) for k, v in
                        repo.tags.iteritems()], _("Tags"))
         hist_l.append(tags_group)
+        choices.extend([x[0] for x in tags_group[0]])
 
-        return hist_l
+        return choices, hist_l