diff --git a/pagure/api/project.py b/pagure/api/project.py index 5588587..b915b28 100644 --- a/pagure/api/project.py +++ b/pagure/api/project.py @@ -236,7 +236,9 @@ def api_new_project(): if form.validate_on_submit(): name = form.name.data description = form.description.data - namespace = form.namespace.data or None + namespace = form.namespace.data.strip() or None + if namespace == 'None': + namespace = None url = form.url.data avatar_email = form.avatar_email.data create_readme = form.create_readme.data @@ -326,7 +328,9 @@ def api_fork_project(): if form.validate_on_submit(): repo = form.repo.data username = form.username.data or None - namespace = form.namespace.data or None + namespace = form.namespace.data.strip() or None + if namespace == 'None': + namespace = None repo = pagure.lib.get_project( SESSION, repo, user=username, namespace=namespace) diff --git a/pagure/forms.py b/pagure/forms.py index 0facbc3..c515a37 100644 --- a/pagure/forms.py +++ b/pagure/forms.py @@ -91,6 +91,23 @@ class ProjectForm(ProjectFormSimplified): 'Create README', [wtforms.validators.optional()], ) + namespace = wtforms.SelectField( + 'The project namespace', + [wtforms.validators.optional()], + choices=[], + ) + + def __init__(self, *args, **kwargs): + """ Calls the default constructor with the normal argument but + uses the list of collection provided to fill the choices of the + drop-down list. + """ + super(ProjectForm, self).__init__(*args, **kwargs) + if 'namespaces' in kwargs: + self.namespace.choices = [ + (namespace, namespace) for namespace in kwargs['namespaces'] + ] + self.namespace.choices.insert(0, ('', '')) class IssueFormSimplied(wtf.Form):