diff --git a/rhodecode/model/validation_schema/schemas/repo_schema.py b/rhodecode/model/validation_schema/schemas/repo_schema.py --- a/rhodecode/model/validation_schema/schemas/repo_schema.py +++ b/rhodecode/model/validation_schema/schemas/repo_schema.py @@ -19,8 +19,10 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ import colander +import deform.widget from rhodecode.translation import _ +from rhodecode.model.validation_schema.utils import convert_to_optgroup from rhodecode.model.validation_schema import validators, preparers, types DEFAULT_LANDING_REF = 'rev:tip' @@ -32,6 +34,11 @@ def get_group_and_repo(repo_name): repo_name, get_object=True) +def get_repo_group(repo_group_id): + from rhodecode.model.repo_group import RepoGroup + return RepoGroup.get(repo_group_id), RepoGroup.CHOICES_SEPARATOR + + @colander.deferred def deferred_repo_type_validator(node, kw): options = kw.get('repo_type_options', []) @@ -53,11 +60,20 @@ def deferred_repo_owner_validator(node, @colander.deferred def deferred_landing_ref_validator(node, kw): - options = kw.get('repo_ref_options', [DEFAULT_LANDING_REF]) + options = kw.get( + 'repo_ref_options', [DEFAULT_LANDING_REF]) return colander.OneOf([x for x in options]) @colander.deferred +def deferred_landing_ref_widget(node, kw): + items = kw.get( + 'repo_ref_items', [(DEFAULT_LANDING_REF, DEFAULT_LANDING_REF)]) + items = convert_to_optgroup(items) + return deform.widget.Select2Widget(values=items) + + +@colander.deferred def deferred_fork_of_validator(node, kw): old_values = kw.get('old_values') or {} @@ -199,6 +215,19 @@ def deferred_repo_name_validator(node, k no_git_suffix_validator, validators.valid_name_validator) +@colander.deferred +def deferred_repo_group_validator(node, kw): + options = kw.get( + 'repo_repo_group_options') + return colander.OneOf([x for x in options]) + + +@colander.deferred +def deferred_repo_group_widget(node, kw): + items = kw.get('repo_repo_group_items') + return deform.widget.Select2Widget(values=items) + + class GroupType(colander.Mapping): def _validate(self, node, value): try: @@ -220,8 +249,10 @@ class GroupType(colander.Mapping): parent_group_name, parent_group) = get_group_and_repo(validated_name) + appstruct['repo_name_with_group'] = validated_name appstruct['repo_name_without_group'] = repo_name_without_group appstruct['repo_group_name'] = parent_group_name or types.RootLocation + if parent_group: appstruct['repo_group_id'] = parent_group.group_id @@ -265,16 +296,19 @@ class RepoSchema(colander.MappingSchema) repo_owner = colander.SchemaNode( colander.String(), - validator=deferred_repo_owner_validator) + validator=deferred_repo_owner_validator, + widget=deform.widget.TextInputWidget()) repo_description = colander.SchemaNode( - colander.String(), missing='') + colander.String(), missing='', + widget=deform.widget.TextAreaWidget()) repo_landing_commit_ref = colander.SchemaNode( colander.String(), validator=deferred_landing_ref_validator, preparers=[preparers.strip_preparer], - missing=DEFAULT_LANDING_REF) + missing=DEFAULT_LANDING_REF, + widget=deferred_landing_ref_widget) repo_clone_uri = colander.SchemaNode( colander.String(), @@ -289,19 +323,19 @@ class RepoSchema(colander.MappingSchema) repo_private = colander.SchemaNode( types.StringBooleanType(), - missing=False) + missing=False, widget=deform.widget.CheckboxWidget()) repo_copy_permissions = colander.SchemaNode( types.StringBooleanType(), - missing=False) + missing=False, widget=deform.widget.CheckboxWidget()) repo_enable_statistics = colander.SchemaNode( types.StringBooleanType(), - missing=False) + missing=False, widget=deform.widget.CheckboxWidget()) repo_enable_downloads = colander.SchemaNode( types.StringBooleanType(), - missing=False) + missing=False, widget=deform.widget.CheckboxWidget()) repo_enable_locking = colander.SchemaNode( types.StringBooleanType(), - missing=False) + missing=False, widget=deform.widget.CheckboxWidget()) def deserialize(self, cstruct): """