allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/3] allura git commit: [#8094] reduce delays for suggesting and validating project names
Date Fri, 01 Jul 2016 20:41:55 GMT
Repository: allura
Updated Branches:
  refs/heads/db/8094 [created] 81cfcf9aa


[#8094] reduce delays for suggesting and validating project names


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/08b48cac
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/08b48cac
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/08b48cac

Branch: refs/heads/db/8094
Commit: 08b48cac507d422d54c67cf600a8e5e1eb180cc2
Parents: bdf758d
Author: Dave Brondsema <dave@brondsema.net>
Authored: Fri Jul 1 11:35:09 2016 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Fri Jul 1 16:41:38 2016 -0400

----------------------------------------------------------------------
 Allura/allura/controllers/project.py            |  6 ----
 Allura/allura/lib/plugin.py                     |  9 ------
 Allura/allura/lib/widgets/forms.py              | 29 ++++++++------------
 .../tests/functional/test_neighborhood.py       |  6 ----
 Allura/allura/tests/test_plugin.py              |  8 ------
 5 files changed, 12 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/08b48cac/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 9fe1177..d2039a7 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -183,12 +183,6 @@ class NeighborhoodController(object):
         return res
 
     @expose('json:')
-    def suggest_name(self, project_name='', **kw):
-        provider = plugin.ProjectRegistrationProvider.get()
-        return dict(suggested_name=provider.suggest_name(project_name,
-                                                         self.neighborhood))
-
-    @expose('json:')
     @validate(W.add_project)
     def check_names(self, **raw_data):
         return c.form_errors

http://git-wip-us.apache.org/repos/asf/allura/blob/08b48cac/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 64b44b3..06242c4 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -681,15 +681,6 @@ class ProjectRegistrationProvider(object):
         method = config.get('registration.method', 'local')
         return app_globals.Globals().entry_points['registration'][method]()
 
-    def suggest_name(self, project_name, neighborhood):
-        """Return a suggested project shortname for the full ``project_name``.
-
-        Example: "My Great Project" -> "mygreatproject"
-
-        """
-        name = re.sub("[^A-Za-z0-9]", " ", project_name).lower()
-        return '-'.join(name.split())
-
     def rate_limit(self, user, neighborhood):
         """Check the various config-defined project registration rate
         limits, and if any are exceeded, raise ProjectRatelimitError.

http://git-wip-us.apache.org/repos/asf/allura/blob/08b48cac/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index fbff6d4..0820117 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -1025,6 +1025,9 @@ class NeighborhoodAddProjectForm(ForgeForm):
                         });
                     }
                 });
+                var suggest_name = function(project_name) {
+                    return project_name.replace(/[^A-Za-z0-9]+/g, '-').toLowerCase();
+                };
                 var check_names = function() {
                     var data = {
                         'neighborhood': $nbhd_input.val(),
@@ -1037,28 +1040,20 @@ class NeighborhoodAddProjectForm(ForgeForm):
                     });
                 };
                 var manual = false;
-                $name_input.keyup(function(){
-                    delay(function() {
-                        if (!manual) {
-                            var data = {
-                                'project_name':$name_input.val()
-                            };
-                            $.getJSON('suggest_name', data, function(result){
-                                $unixname_input.val(result.suggested_name);
-                                $url_fragment.text(result.suggested_name);
-                                check_names();
-                            });
-                        } else {
-                            check_names();
-                        }
-                    }, 500);
+                $name_input.on('input', function(){
+                    if (!manual) {
+                        var suggested_name = suggest_name($name_input.val());
+                        $unixname_input.val(suggested_name);
+                        $url_fragment.text(suggested_name);
+                    }
+                    delay(check_names, 20);
                 });
                 $unixname_input.change(function() {
                     manual = true;
                 });
-                $unixname_input.keyup(function(){
+                $unixname_input.on('input', function(){
                     $url_fragment.text($unixname_input.val());
-                    delay(check_names, 500);
+                    delay(check_names, 20);
                 });
             });
         ''' % dict(neighborhood=neighborhood, project_name=project_name, project_unixname=project_unixname))

http://git-wip-us.apache.org/repos/asf/allura/blob/08b48cac/Allura/allura/tests/functional/test_neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index 1119749..ce8c8d8 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -821,12 +821,6 @@ class TestNeighborhood(TestController):
         assert r.html.find('div', id='top_nav').find(
             'a', href='/adobe/testtemp/admin/'), r.html
 
-    def test_name_suggest(self):
-        r = self.app.get('/p/suggest_name?project_name=My+Moz')
-        assert_equal(r.json, dict(suggested_name='my-moz'))
-        r = self.app.get('/p/suggest_name?project_name=Te%st!')
-        assert_equal(r.json, dict(suggested_name='te-st'))
-
     def test_name_check(self):
         for name in ('My+Moz', 'Te%st!', 'ab', 'a' * 16):
             r = self.app.get(

http://git-wip-us.apache.org/repos/asf/allura/blob/08b48cac/Allura/allura/tests/test_plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_plugin.py b/Allura/allura/tests/test_plugin.py
index 1cbd686..a30c66e 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -65,14 +65,6 @@ class TestProjectRegistrationProvider(object):
             private_project=False,
         )
 
-    def test_suggest_name(self):
-        f = self.provider.suggest_name
-        assert_equals(f('Foo Bar', Mock()), 'foo-bar')
-        assert_equals(f('A More Than Fifteen Character Name', Mock()),
-                      'a-more-than-fifteen-character-name')
-        assert_equals(f('foo! bar?.. the great!!', Mock()),
-                      'foo-bar-the-great')
-
     @patch('allura.model.Project')
     def test_shortname_validator(self, Project):
         Project.query.get.return_value = None


Mime
View raw message