Changeset - 12fa0c19c42f
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 13 years ago 2012-06-15 00:05:20
marcin@python-works.com
validating choices for landing_rev
4 files changed with 30 insertions and 14 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/repos.py
Show inline comments
 
@@ -70,7 +70,8 @@ class ReposController(BaseController):
 
        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 @@ class ReposController(BaseController):
 

	
 
            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 @@ class ReposController(BaseController):
 
        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 @@ class ReposController(BaseController):
 
        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)
rhodecode/controllers/settings.py
Show inline comments
 
@@ -43,6 +43,7 @@ from rhodecode.model.forms import RepoSe
 
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 @@ class SettingsController(BaseRepoControl
 
        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 @@ class SettingsController(BaseRepoControl
 

	
 
        _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))
 

	
rhodecode/model/forms.py
Show inline comments
 
@@ -653,7 +653,7 @@ def PasswordResetForm():
 

	
 

	
 
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 @@ def RepoForm(edit=False, old_data={}, su
 
        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 @@ def RepoForm(edit=False, old_data={}, su
 
    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 @@ def RepoForkForm(edit=False, old_data={}
 
    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 @@ def RepoSettingsForm(edit=False, old_dat
 
        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
rhodecode/model/scm.py
Show inline comments
 
@@ -482,24 +482,31 @@ class ScmModel(BaseModel):
 
        :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
0 comments (0 inline, 0 general)