comparison rhodecode/model/forms.py @ 1347:43b8e161be3f beta

#47 implemented basic edition of groups
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 25 May 2011 10:27:29 +0200
parents cf78d302d441
children 526120c77a38
comparison
equal deleted inserted replaced
1346:cf78d302d441 1347:43b8e161be3f
115 115
116 return _ValidUsersGroup 116 return _ValidUsersGroup
117 117
118 118
119 def ValidReposGroup(edit, old_data): 119 def ValidReposGroup(edit, old_data):
120
121 class _ValidReposGroup(formencode.validators.FancyValidator): 120 class _ValidReposGroup(formencode.validators.FancyValidator):
122 121
123 def validate_python(self, value, state): 122 def validate_python(self, value, state):
124 #TODO WRITE VALIDATIONS 123 #TODO WRITE VALIDATIONS
125 group_name = value.get('repos_group_name') 124 group_name = value.get('group_name')
126 parent_id = value.get('repos_group_parent') 125 group_parent_id = value.get('group_parent_id')
127 126
128 # slugify repo group just in case :) 127 # slugify repo group just in case :)
129 slug = repo_name_slug(group_name) 128 slug = repo_name_slug(group_name)
130 129
131 # check filesystem 130 old_gname = None
132 gr = Group.query().filter(Group.group_name == slug)\ 131 if edit:
133 .filter(Group.group_parent_id == parent_id).scalar() 132 old_gname = Group.get(
134 133 old_data.get('group_id')).group_name
135 if gr: 134
136 e_dict = {'repos_group_name':_('This group already exists')} 135 if old_gname != group_name or not edit:
137 raise formencode.Invalid('', value, state, 136 # check filesystem
138 error_dict=e_dict) 137 gr = Group.query().filter(Group.group_name == slug)\
138 .filter(Group.group_parent_id == group_parent_id).scalar()
139
140 if gr:
141 e_dict = {'group_name':_('This group already exists')}
142 raise formencode.Invalid('', value, state,
143 error_dict=e_dict)
144
139 return _ValidReposGroup 145 return _ValidReposGroup
140 146
141 class ValidPassword(formencode.validators.FancyValidator): 147 class ValidPassword(formencode.validators.FancyValidator):
142 148
143 def to_python(self, value, state): 149 def to_python(self, value, state):
500 def ReposGroupForm(edit=False, old_data={}, available_groups=[]): 506 def ReposGroupForm(edit=False, old_data={}, available_groups=[]):
501 class _ReposGroupForm(formencode.Schema): 507 class _ReposGroupForm(formencode.Schema):
502 allow_extra_fields = True 508 allow_extra_fields = True
503 filter_extra_fields = True 509 filter_extra_fields = True
504 510
505 repos_group_name = All(UnicodeString(strip=True, min=1, not_empty=True), 511 group_name = All(UnicodeString(strip=True, min=1, not_empty=True),
506 SlugifyName()) 512 SlugifyName())
507 repos_group_description = UnicodeString(strip=True, min=1, 513 group_description = UnicodeString(strip=True, min=1,
508 not_empty=True) 514 not_empty=True)
509 repos_group_parent = OneOf(available_groups, hideList=False, 515 group_parent_id = OneOf(available_groups, hideList=False,
510 testValueList=True, 516 testValueList=True,
511 if_missing=None, not_empty=False) 517 if_missing=None, not_empty=False)
512 518
513 chained_validators = [ValidReposGroup(edit, old_data)] 519 chained_validators = [ValidReposGroup(edit, old_data)]
514 520