comparison rhodecode/model/forms.py @ 659:758f64f3fbda beta

extended repo creation by repo type. fixed fork creation to maintain repo type.
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 05 Nov 2010 21:55:30 +0100
parents 05528ad948c4
children 673de12e6bf6
comparison
equal deleted inserted replaced
658:4ecb2ffcc110 659:758f64f3fbda
28 from rhodecode.model import meta 28 from rhodecode.model import meta
29 from rhodecode.model.user import UserModel 29 from rhodecode.model.user import UserModel
30 from rhodecode.model.repo import RepoModel 30 from rhodecode.model.repo import RepoModel
31 from rhodecode.model.db import User 31 from rhodecode.model.db import User
32 from webhelpers.pylonslib.secure_form import authentication_token 32 from webhelpers.pylonslib.secure_form import authentication_token
33 from vcs import BACKENDS
33 import formencode 34 import formencode
34 import logging 35 import logging
35 import os 36 import os
36 import rhodecode.lib.helpers as h 37 import rhodecode.lib.helpers as h
37 38
144 value, state) 145 value, state)
145 return slug 146 return slug
146 147
147 148
148 return _ValidRepoName 149 return _ValidRepoName
150
151 def ValidForkType(old_data):
152 class _ValidForkType(formencode.validators.FancyValidator):
153
154 def to_python(self, value, state):
155 if old_data['repo_type'] != value:
156 raise formencode.Invalid(_('Fork have to be the same type as original'), value, state)
157 return value
158 return _ValidForkType
149 159
150 class ValidPerms(formencode.validators.FancyValidator): 160 class ValidPerms(formencode.validators.FancyValidator):
151 messages = {'perm_new_user_name':_('This username is not valid')} 161 messages = {'perm_new_user_name':_('This username is not valid')}
152 162
153 def to_python(self, value, state): 163 def to_python(self, value, state):
290 allow_extra_fields = True 300 allow_extra_fields = True
291 filter_extra_fields = False 301 filter_extra_fields = False
292 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data)) 302 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
293 description = UnicodeString(strip=True, min=1, not_empty=True) 303 description = UnicodeString(strip=True, min=1, not_empty=True)
294 private = StringBoolean(if_missing=False) 304 private = StringBoolean(if_missing=False)
295 305 repo_type = OneOf(BACKENDS.keys())
296 if edit: 306 if edit:
297 user = All(Int(not_empty=True), ValidRepoUser) 307 user = All(Int(not_empty=True), ValidRepoUser)
298 308
299 chained_validators = [ValidPerms] 309 chained_validators = [ValidPerms]
300 return _RepoForm 310 return _RepoForm
304 allow_extra_fields = True 314 allow_extra_fields = True
305 filter_extra_fields = False 315 filter_extra_fields = False
306 fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data)) 316 fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
307 description = UnicodeString(strip=True, min=1, not_empty=True) 317 description = UnicodeString(strip=True, min=1, not_empty=True)
308 private = StringBoolean(if_missing=False) 318 private = StringBoolean(if_missing=False)
309 319 repo_type = All(ValidForkType(old_data), OneOf(BACKENDS.keys()))
310 return _RepoForkForm 320 return _RepoForkForm
311 321
312 def RepoSettingsForm(edit=False, old_data={}): 322 def RepoSettingsForm(edit=False, old_data={}):
313 class _RepoForm(formencode.Schema): 323 class _RepoForm(formencode.Schema):
314 allow_extra_fields = True 324 allow_extra_fields = True