Show More
@@ -19,8 +19,10 b'' | |||||
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import colander |
|
21 | import colander | |
|
22 | import deform.widget | |||
22 |
|
23 | |||
23 | from rhodecode.translation import _ |
|
24 | from rhodecode.translation import _ | |
|
25 | from rhodecode.model.validation_schema.utils import convert_to_optgroup | |||
24 | from rhodecode.model.validation_schema import validators, preparers, types |
|
26 | from rhodecode.model.validation_schema import validators, preparers, types | |
25 |
|
27 | |||
26 | DEFAULT_LANDING_REF = 'rev:tip' |
|
28 | DEFAULT_LANDING_REF = 'rev:tip' | |
@@ -32,6 +34,11 b' def get_group_and_repo(repo_name):' | |||||
32 | repo_name, get_object=True) |
|
34 | repo_name, get_object=True) | |
33 |
|
35 | |||
34 |
|
36 | |||
|
37 | def get_repo_group(repo_group_id): | |||
|
38 | from rhodecode.model.repo_group import RepoGroup | |||
|
39 | return RepoGroup.get(repo_group_id), RepoGroup.CHOICES_SEPARATOR | |||
|
40 | ||||
|
41 | ||||
35 | @colander.deferred |
|
42 | @colander.deferred | |
36 | def deferred_repo_type_validator(node, kw): |
|
43 | def deferred_repo_type_validator(node, kw): | |
37 | options = kw.get('repo_type_options', []) |
|
44 | options = kw.get('repo_type_options', []) | |
@@ -53,11 +60,20 b' def deferred_repo_owner_validator(node, ' | |||||
53 |
|
60 | |||
54 | @colander.deferred |
|
61 | @colander.deferred | |
55 | def deferred_landing_ref_validator(node, kw): |
|
62 | def deferred_landing_ref_validator(node, kw): | |
56 | options = kw.get('repo_ref_options', [DEFAULT_LANDING_REF]) |
|
63 | options = kw.get( | |
|
64 | 'repo_ref_options', [DEFAULT_LANDING_REF]) | |||
57 | return colander.OneOf([x for x in options]) |
|
65 | return colander.OneOf([x for x in options]) | |
58 |
|
66 | |||
59 |
|
67 | |||
60 | @colander.deferred |
|
68 | @colander.deferred | |
|
69 | def deferred_landing_ref_widget(node, kw): | |||
|
70 | items = kw.get( | |||
|
71 | 'repo_ref_items', [(DEFAULT_LANDING_REF, DEFAULT_LANDING_REF)]) | |||
|
72 | items = convert_to_optgroup(items) | |||
|
73 | return deform.widget.Select2Widget(values=items) | |||
|
74 | ||||
|
75 | ||||
|
76 | @colander.deferred | |||
61 | def deferred_fork_of_validator(node, kw): |
|
77 | def deferred_fork_of_validator(node, kw): | |
62 | old_values = kw.get('old_values') or {} |
|
78 | old_values = kw.get('old_values') or {} | |
63 |
|
79 | |||
@@ -199,6 +215,19 b' def deferred_repo_name_validator(node, k' | |||||
199 | no_git_suffix_validator, validators.valid_name_validator) |
|
215 | no_git_suffix_validator, validators.valid_name_validator) | |
200 |
|
216 | |||
201 |
|
217 | |||
|
218 | @colander.deferred | |||
|
219 | def deferred_repo_group_validator(node, kw): | |||
|
220 | options = kw.get( | |||
|
221 | 'repo_repo_group_options') | |||
|
222 | return colander.OneOf([x for x in options]) | |||
|
223 | ||||
|
224 | ||||
|
225 | @colander.deferred | |||
|
226 | def deferred_repo_group_widget(node, kw): | |||
|
227 | items = kw.get('repo_repo_group_items') | |||
|
228 | return deform.widget.Select2Widget(values=items) | |||
|
229 | ||||
|
230 | ||||
202 | class GroupType(colander.Mapping): |
|
231 | class GroupType(colander.Mapping): | |
203 | def _validate(self, node, value): |
|
232 | def _validate(self, node, value): | |
204 | try: |
|
233 | try: | |
@@ -220,8 +249,10 b' class GroupType(colander.Mapping):' | |||||
220 | parent_group_name, |
|
249 | parent_group_name, | |
221 | parent_group) = get_group_and_repo(validated_name) |
|
250 | parent_group) = get_group_and_repo(validated_name) | |
222 |
|
251 | |||
|
252 | appstruct['repo_name_with_group'] = validated_name | |||
223 | appstruct['repo_name_without_group'] = repo_name_without_group |
|
253 | appstruct['repo_name_without_group'] = repo_name_without_group | |
224 | appstruct['repo_group_name'] = parent_group_name or types.RootLocation |
|
254 | appstruct['repo_group_name'] = parent_group_name or types.RootLocation | |
|
255 | ||||
225 | if parent_group: |
|
256 | if parent_group: | |
226 | appstruct['repo_group_id'] = parent_group.group_id |
|
257 | appstruct['repo_group_id'] = parent_group.group_id | |
227 |
|
258 | |||
@@ -265,16 +296,19 b' class RepoSchema(colander.MappingSchema)' | |||||
265 |
|
296 | |||
266 | repo_owner = colander.SchemaNode( |
|
297 | repo_owner = colander.SchemaNode( | |
267 | colander.String(), |
|
298 | colander.String(), | |
268 |
validator=deferred_repo_owner_validator |
|
299 | validator=deferred_repo_owner_validator, | |
|
300 | widget=deform.widget.TextInputWidget()) | |||
269 |
|
301 | |||
270 | repo_description = colander.SchemaNode( |
|
302 | repo_description = colander.SchemaNode( | |
271 |
colander.String(), missing='' |
|
303 | colander.String(), missing='', | |
|
304 | widget=deform.widget.TextAreaWidget()) | |||
272 |
|
305 | |||
273 | repo_landing_commit_ref = colander.SchemaNode( |
|
306 | repo_landing_commit_ref = colander.SchemaNode( | |
274 | colander.String(), |
|
307 | colander.String(), | |
275 | validator=deferred_landing_ref_validator, |
|
308 | validator=deferred_landing_ref_validator, | |
276 | preparers=[preparers.strip_preparer], |
|
309 | preparers=[preparers.strip_preparer], | |
277 |
missing=DEFAULT_LANDING_REF |
|
310 | missing=DEFAULT_LANDING_REF, | |
|
311 | widget=deferred_landing_ref_widget) | |||
278 |
|
312 | |||
279 | repo_clone_uri = colander.SchemaNode( |
|
313 | repo_clone_uri = colander.SchemaNode( | |
280 | colander.String(), |
|
314 | colander.String(), | |
@@ -289,19 +323,19 b' class RepoSchema(colander.MappingSchema)' | |||||
289 |
|
323 | |||
290 | repo_private = colander.SchemaNode( |
|
324 | repo_private = colander.SchemaNode( | |
291 | types.StringBooleanType(), |
|
325 | types.StringBooleanType(), | |
292 | missing=False) |
|
326 | missing=False, widget=deform.widget.CheckboxWidget()) | |
293 | repo_copy_permissions = colander.SchemaNode( |
|
327 | repo_copy_permissions = colander.SchemaNode( | |
294 | types.StringBooleanType(), |
|
328 | types.StringBooleanType(), | |
295 | missing=False) |
|
329 | missing=False, widget=deform.widget.CheckboxWidget()) | |
296 | repo_enable_statistics = colander.SchemaNode( |
|
330 | repo_enable_statistics = colander.SchemaNode( | |
297 | types.StringBooleanType(), |
|
331 | types.StringBooleanType(), | |
298 | missing=False) |
|
332 | missing=False, widget=deform.widget.CheckboxWidget()) | |
299 | repo_enable_downloads = colander.SchemaNode( |
|
333 | repo_enable_downloads = colander.SchemaNode( | |
300 | types.StringBooleanType(), |
|
334 | types.StringBooleanType(), | |
301 | missing=False) |
|
335 | missing=False, widget=deform.widget.CheckboxWidget()) | |
302 | repo_enable_locking = colander.SchemaNode( |
|
336 | repo_enable_locking = colander.SchemaNode( | |
303 | types.StringBooleanType(), |
|
337 | types.StringBooleanType(), | |
304 | missing=False) |
|
338 | missing=False, widget=deform.widget.CheckboxWidget()) | |
305 |
|
339 | |||
306 | def deserialize(self, cstruct): |
|
340 | def deserialize(self, cstruct): | |
307 | """ |
|
341 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now