diff rhodecode/model/forms.py @ 1550:6f468ba37650 beta

fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 12 Oct 2011 14:43:46 +0200
parents bd604cf75c5a
children 752b0a7b7679 9dae92a65e40
line wrap: on
line diff
--- a/rhodecode/model/forms.py	Tue Oct 11 20:59:41 2011 -0500
+++ b/rhodecode/model/forms.py	Wed Oct 12 14:43:46 2011 +0200
@@ -250,7 +250,7 @@
                 gr = Group.get(value.get('repo_group'))
                 group_path = gr.full_path
                 # value needs to be aware of group name in order to check
-                # db key This is an actuall just the name to store in the
+                # db key This is an actual just the name to store in the
                 # database
                 repo_name_full = group_path + Group.url_sep() + repo_name
             else:
@@ -259,25 +259,32 @@
 
 
             value['repo_name_full'] = repo_name_full
-            if old_data.get('repo_name') != repo_name_full or not edit:
+            rename = old_data.get('repo_name') != repo_name_full
+            create = not edit
+            if  rename or create:
 
                 if group_path != '':
                     if RepoModel().get_by_repo_name(repo_name_full,):
                         e_dict = {'repo_name':_('This repository already '
-                                                'exists in group "%s"') %
+                                                'exists in a group "%s"') %
                                   gr.group_name}
                         raise formencode.Invalid('', value, state,
                                                  error_dict=e_dict)
+                elif Group.get_by_group_name(repo_name_full):
+                        e_dict = {'repo_name':_('There is a group with this'
+                                                ' name already "%s"') %
+                                  repo_name_full}
+                        raise formencode.Invalid('', value, state,
+                                                 error_dict=e_dict)
 
-                else:
-                    if RepoModel().get_by_repo_name(repo_name_full):
+                elif RepoModel().get_by_repo_name(repo_name_full):
                         e_dict = {'repo_name':_('This repository '
                                                 'already exists')}
                         raise formencode.Invalid('', value, state,
                                                  error_dict=e_dict)
+
             return value
 
-
     return _ValidRepoName
 
 def ValidForkName():