incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [11/12] git commit: [#6314] Add config option for short_url.url_pattern and refactor short url form widget
Date Fri, 07 Jun 2013 17:20:10 GMT
[#6314] Add config option for short_url.url_pattern and refactor short url form widget

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/cj/6314
Commit: 9ea46614682f1ac7e650b1a8386cc860192c733f
Parents: 2b74a7d
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Wed Jun 5 20:58:12 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Thu Jun 6 18:00:15 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/widgets/form_fields.py           |    3 +-
 Allura/allura/templates/widgets/lightbox.html      |    8 ++-
 Allura/development.ini                             |    2 +
 Allura/test.ini                                    |    2 +
 ForgeShortUrl/forgeshorturl/main.py                |   36 +++++++---
 ForgeShortUrl/forgeshorturl/model/shorturl.py      |    8 ++
 ForgeShortUrl/forgeshorturl/templates/add.html     |   33 ---------
 ForgeShortUrl/forgeshorturl/templates/form.html    |   53 +++++++++++++++
 ForgeShortUrl/forgeshorturl/templates/index.html   |   48 +++----------
 ForgeShortUrl/forgeshorturl/templates/master.html  |   36 ++++------
 .../forgeshorturl/tests/functional/test.py         |    7 ++-
 ForgeShortUrl/forgeshorturl/widgets/short_url.py   |   14 +---
 12 files changed, 130 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/Allura/allura/lib/widgets/form_fields.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/form_fields.py b/Allura/allura/lib/widgets/form_fields.py
index 3571b04..1accf93 100644
--- a/Allura/allura/lib/widgets/form_fields.py
+++ b/Allura/allura/lib/widgets/form_fields.py
@@ -435,7 +435,8 @@ class Lightbox(ew_core.Widget):
     defaults=dict(
         name=None,
         trigger=None,
-        content='')
+        content='',
+        content_template=None)
 
     def resources(self):
         yield ew.JSLink('js/jquery.lightbox_me.js')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/Allura/allura/templates/widgets/lightbox.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/lightbox.html b/Allura/allura/templates/widgets/lightbox.html
index e251a16..4c5210d 100644
--- a/Allura/allura/templates/widgets/lightbox.html
+++ b/Allura/allura/templates/widgets/lightbox.html
@@ -18,5 +18,9 @@
 -#}
 <div id="lightbox_{{name}}" class="modal" style="display:none">
   <b data-icon="{{g.icons['close'].char}}" class="ico {{g.icons['close'].css}} close"></b>
-  {{content|safe}}
-</div>
\ No newline at end of file
+  {% if content_template %}
+    {% include content_template with context %}
+  {% else %}
+    {{content|safe}}
+  {% endif %}
+</div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index b3c084f..0ddf539 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -250,6 +250,8 @@ auto_reload_templates = true
 # pip install -e git://github.com/brondsem/html2text.git#egg=html2text
 forgeblog.exfeed = false
 
+short_url.url_pattern = {base_url}p/{project}/{mount_point}/{short_name}
+
 [app:tool_test]
 use = egg:Allura
 override_root=basetest_project_root

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index b3d9760..cebbe80 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -107,6 +107,8 @@ support_tool_choices = wiki tickets discussion
 
 disable_csrf_protection=1
 
+short_url.url_pattern = {base_url}p/{project}/{mount_point}/{short_name}
+
 [app:main_without_authn]
 use = main
 skip_authentication = True

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/ForgeShortUrl/forgeshorturl/main.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/main.py b/ForgeShortUrl/forgeshorturl/main.py
index 1ce62d8..8ecce61 100644
--- a/ForgeShortUrl/forgeshorturl/main.py
+++ b/ForgeShortUrl/forgeshorturl/main.py
@@ -15,7 +15,7 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-from tg import expose, validate, redirect, flash, request
+from tg import expose, validate, redirect, flash, request, config
 from tg.decorators import without_trailing_slash
 
 from allura.app import Application, SitemapEntry, DefaultAdminController
@@ -47,10 +47,7 @@ class W:
     search_help = SearchHelp(comments=False, history=False)
     page_list = ffw.PageList()
     page_size = ffw.PageSize()
-    create_short_url_lightbox = suw.CreateShortUrlWidget(
-            name='create_short_url',
-            trigger='#sidebar a.add_short_url')
-    update_short_url_lightbox = suw.UpdateShortUrlWidget()
+    short_url_lightbox = suw.ShortUrlFormWidget()
 
 
 class ForgeShortUrlApp(Application):
@@ -81,7 +78,7 @@ class ForgeShortUrlApp(Application):
     @h.exceptionless([], log)
     def sitemap(self):
         menu_id = self.config.options.mount_label
-        return [SitemapEntry(menu_id, '.')[self.sidebar_menu()]]
+        return [SitemapEntry(menu_id, '.')]
 
     def sidebar_menu(self):
         links = []
@@ -91,7 +88,7 @@ class ForgeShortUrlApp(Application):
             links = [SitemapEntry('Add Short URL',
                                   url,
                                   ui_icon=g.icons['plus'],
-                                  className="add_short_url"), ]
+                                  className="add-short-url"), ]
         return links
 
     def admin_menu(self):
@@ -132,8 +129,7 @@ class ForgeShortUrlApp(Application):
 
 class RootController(BaseController):
     def __init__(self):
-        c.create_short_url_lightbox = W.create_short_url_lightbox
-        c.update_short_url_lightbox = W.update_short_url_lightbox
+        c.short_url_lightbox = W.short_url_lightbox
 
     def _check_security(self):
         require_access(c.app, 'read')
@@ -157,7 +153,12 @@ class RootController(BaseController):
             'short_urls': short_urls,
             'limit': limit,
             'pagenum': pagenum,
-            'count': count
+            'count': count,
+            'url_len': len(config['short_url.url_pattern'].format(
+                    base_url=config['base_url'],
+                    project=c.project.shortname,
+                    mount_point=c.app.config.options.mount_point,
+                    short_name='')),
         }
 
     @expose('jinja:forgeshorturl:templates/search.html')
@@ -179,6 +180,11 @@ class RootController(BaseController):
         d = search_app(**search_params)
         d['search_comments_disable'] = True
         d['search_history_disable'] = True
+        d['url_len'] = len(config['short_url.url_pattern'].format(
+                base_url=config['base_url'],
+                project=c.project.shortname,
+                mount_point=c.app.config.options.mount_point,
+                short_name=''))
         return d
 
     @expose()
@@ -214,7 +220,7 @@ class ShortURLAdminController(DefaultAdminController):
             'short_name': shorturl})
         return dict(status='ok')
 
-    @expose('jinja:forgeshorturl:templates/add.html')
+    @expose('jinja:forgeshorturl:templates/form.html')
     @validate(dict(full_url=All(validators.URL(add_http=True),
                                 validators.NotEmpty()),
                    short_url=validators.NotEmpty()))
@@ -262,4 +268,10 @@ class ShortURLAdminController(DefaultAdminController):
 
             M.AuditLog.log(msg)
             redirect(request.referer)
-        return dict(app=self.app)
+        return dict(
+                app=self.app,
+                url_len=len(config['short_url.url_pattern'].format(
+                    base_url=config['base_url'],
+                    project=c.project.shortname,
+                    mount_point=self.app.config.options.mount_point,
+                    short_name='')))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/ForgeShortUrl/forgeshorturl/model/shorturl.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/model/shorturl.py b/ForgeShortUrl/forgeshorturl/model/shorturl.py
index a16ef69..8a7fce7 100644
--- a/ForgeShortUrl/forgeshorturl/model/shorturl.py
+++ b/ForgeShortUrl/forgeshorturl/model/shorturl.py
@@ -16,6 +16,7 @@
 #       under the License.
 
 import pymongo
+from tg import config
 from pylons import tmpl_context as c
 from ming.orm import FieldProperty, ForeignIdProperty, session
 from datetime import datetime
@@ -69,3 +70,10 @@ class ShortUrl(M.Artifact):
 
     def url(self):
         return self.app.url + self.short_name
+
+    def short_url(self):
+        return config['short_url.url_pattern'].format(
+                base_url=config['base_url'],
+                project=self.app.project.shortname,
+                mount_point=self.app.config.options.mount_point,
+                short_name=self.short_name)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/ForgeShortUrl/forgeshorturl/templates/add.html
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/templates/add.html b/ForgeShortUrl/forgeshorturl/templates/add.html
deleted file mode 100644
index 4deece9..0000000
--- a/ForgeShortUrl/forgeshorturl/templates/add.html
+++ /dev/null
@@ -1,33 +0,0 @@
-{#-
-       Licensed to the Apache Software Foundation (ASF) under one
-       or more contributor license agreements.  See the NOTICE file
-       distributed with this work for additional information
-       regarding copyright ownership.  The ASF licenses this file
-       to you under the Apache License, Version 2.0 (the
-       "License"); you may not use this file except in compliance
-       with the License.  You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-       Unless required by applicable law or agreed to in writing,
-       software distributed under the License is distributed on an
-       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-       KIND, either express or implied.  See the License for the
-       specific language governing permissions and limitations
-       under the License.
--#}
-{# fixes identation #}    <form method="post" action="{{c.project.url()}}admin/{{app.config.options.mount_point}}/add">
-        <label class="grid-13">Short name</label>
-        <div class="grid-13"><input type = "text" name = "short_url" style="width:
250px"></div>
-        <label class="grid-13">Full URL</label>
-        <div class="grid-13"><input type = "text" name = "full_url" style="width:
250px"></div>
-        <label class="grid-13">Description</label>
-        <div class="grid-13"><textarea name = "description" style="width: 250px;
height: 100px"></textarea></div>
-        <div class="grid-1"><input type = "checkbox" name="private" id="private"></div>
-        <label for="private" class="grid-12">Private</label>
-        <div class="grid-13">&nbsp;</div>
-        <hr>
-        <div class="grid-13"><div class="grid-13">&nbsp;</div>
-        <input type="submit" value="Save">
-        <a href="#" class="close">Cancel</a></div>
-    </form>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/ForgeShortUrl/forgeshorturl/templates/form.html
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/templates/form.html b/ForgeShortUrl/forgeshorturl/templates/form.html
new file mode 100644
index 0000000..fa39b92
--- /dev/null
+++ b/ForgeShortUrl/forgeshorturl/templates/form.html
@@ -0,0 +1,53 @@
+{#-
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+-#}
+{% set app = app or c.app %}
+<div>
+    <h1 id="short-url-form-title" style="display:none"><span id="short-url-form-action-label">Add</span>
Short URL</h1>
+    <form method="post" action="{{c.project.url()}}admin/{{app.config.options.mount_point}}/add"
id="short-url-form">
+        <input type="hidden" name="update"/>
+        <label class="grid-13">Short Name</label>
+        <div class="grid-13"><input type="text" name="short_url" style="width: 250px"/>
&nbsp;<span class="name_len">0</span> / <span class="url_len">{{url_len}}</span>
+        </div>
+        <label class="grid-13">Full URL</label>
+        <div class="grid-13"><input type="text" name="full_url" style="width: 250px"/></div>
+        <label class="grid-13">Description</label>
+        <div class="grid-13"><textarea name="description" style="width: 250px; height:
100px"></textarea></div>
+        <div class="grid-1"><input type="checkbox" name="private" id="private"></div>
+        <label for="private" class="grid-12">Private</label>
+        <div class="grid-13">&nbsp;</div>
+        <hr>
+        <div class="grid-13"><div class="grid-13">&nbsp;</div>
+        <input type="submit" value="Save">
+        <a href="#" class="close">Cancel</a></div>
+    </form>
+</div>
+
+{% block extra_js %}
+<script type="text/javascript">
+    $(function() {
+        $('#short-url-form input[name="short_url"]').keyup(function(e) {
+            var form = $('#short-url-form');
+            var name_len = $(this).val().length;
+            var url_len = name_len + {{url_len}};
+            form.find('.name_len').text(name_len);
+            form.find('.url_len').text(url_len);
+        });
+    });
+</script>
+{% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/ForgeShortUrl/forgeshorturl/templates/index.html
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/templates/index.html b/ForgeShortUrl/forgeshorturl/templates/index.html
index 85b94af..5478214 100644
--- a/ForgeShortUrl/forgeshorturl/templates/index.html
+++ b/ForgeShortUrl/forgeshorturl/templates/index.html
@@ -20,33 +20,6 @@
 
 {% set can_update = c.user and h.has_access(c.app, 'update') %}
 
-{% block extra_js %}
-  {{ super() }}
-
-  {{ c.update_short_url_lightbox.display(content='''
-<div>
-<h1>Update Short URL</h1>
-<form method="post" action="" id="update-short-url-form">
-  <input type="hidden" name="update" value="update">
-  <input type="hidden" name="short_url">
-  <label class="grid-13">Short name</label>
-  <div class="grid-13"><input type="text" name="short_url_display" style="width:
250px" disabled="disabled"></div>
-  <label class="grid-13">Full URL</label>
-  <div class="grid-13"><input type="text" name="full_url" style="width: 250px"></div>
-  <label class="grid-13">Description</label>
-  <div class="grid-13"><textarea name="description" style="width: 250px; height:
100px"></textarea></div>
-  <div class="grid-13"><input type="checkbox" name="private" id="update-checkbox-private"><label
for="update-checkbox-private">Private</label></div>
-  <div class="grid-13">&nbsp;</div>
-  <hr>
-  <div class="grid-13"><div class="grid-13">&nbsp;</div>
-  <input type="submit" value="Save">
-    <a href="#" class="close">Cancel</a>
-  </div>
-</form>
-</div>
-''') }}
-{% endblock %}
-
 {% block content %}
 <table>
     <thead>
@@ -70,7 +43,7 @@
         {% endif %}
 
         <td><small>{{ su.user.username }}</small></td>
-        <td><small><a href="{{ c.app.url+su.short_name }}">{{ request.scheme+'://'+request.host+su.url()}}</a></small></td>
+        <td><small><a href="{{ su.short_url() }}">{{ su.short_url() }}</a></small></td>
         <td><small>{{ su.full_url|urlize(20) }}</small></td>
         <td><small>{{ su.description }}</small></td>
         <td><small>{{ lib.abbr_date(su.created) }}</small></td>
@@ -78,22 +51,23 @@
         {% if can_update %}
         <td>
           <small>
-            <a class="update-url" id="update-url-{{su.short_name}}" href="{{c.project.url()}}admin/{{c.app.config.options.mount_point}}/add/">
+            <a class="update-short-url" id="update-url-{{su.short_name}}" href="{{c.project.url()}}admin/{{c.app.config.options.mount_point}}/add/">
               Update
             </a>
             <script>
               $(function() {
-                var upform = $('#update-short-url-form');
+                var modal = $('#lightbox_short-url-modal');
                 $('#update-url-{{su.short_name}}').click(function() {
-                  upform.attr('action', this.href);
-                  upform.find('input[name="short_url"]').val('{{ su.short_name }}');
-                  upform.find('input[name="short_url_display"]').val('{{ su.short_name }}');
-                  upform.find('input[name="full_url"]').val('{{ su.full_url }}');
-                  upform.find('textarea[name="description"]').val('{{su.description|replace("\n",
"\\n")|replace("\r", "\\r")}}');
+                  modal.find('#short-url-form-title').show();
+                  modal.find('#short-url-form-action-label').text('Update');
+                  modal.find('input[name="update"]').val('True');
+                  modal.find('input[name="short_url"]').val('{{ su.short_name }}').attr('readonly',
true).trigger('keyup');
+                  modal.find('input[name="full_url"]').val('{{ su.full_url }}');
+                  modal.find('textarea[name="description"]').val('{{su.description|replace("\n",
"\\n")|replace("\r", "\\r")}}');
                   if ('{{ su.private }}' == 'True') {
-                    $('#update-checkbox-private').attr('checked', 'checked');
+                    modal.find('input[name="private"]').attr('checked', 'checked');
                   } else {
-                    $('#update-checkbox-private').removeAttr('checked');
+                    modal.find('input[name="private"]').removeAttr('checked');
                   }
                   return false;
                 });

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/ForgeShortUrl/forgeshorturl/templates/master.html
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/templates/master.html b/ForgeShortUrl/forgeshorturl/templates/master.html
index fcad187..98186ec 100644
--- a/ForgeShortUrl/forgeshorturl/templates/master.html
+++ b/ForgeShortUrl/forgeshorturl/templates/master.html
@@ -23,29 +23,19 @@
 {% block short_url_content %}{% endblock %}
 
 {% block extra_js %}
-{{c.create_short_url_lightbox.display(content='''
-<div>
-    <h1>Add Short URL</h1>
-    <form method="post" action="" id="add_url_form">
-        <label class="grid-13">Short name</label>
-        <div class="grid-13"><input type = "text" name = "short_url" style="width:
250px"></div>
-        <label class="grid-13">Full URL</label>
-        <div class="grid-13"><input type = "text" name = "full_url" style="width:
250px"></div>
-        <label class="grid-13">Description</label>
-        <div class="grid-13"><textarea name = "description" style="width: 250px;
height: 100px"></textarea></div>
-        <div class="grid-1"><input type = "checkbox" name="private" id="private"></div>
-        <label for="private" class="grid-12">Private</label>
-        <div class="grid-13">&nbsp;</div>
-        <hr>
-        <div class="grid-13"><div class="grid-13">&nbsp;</div>
-            <input type="submit" value="Save">
-            <a href="#" class="close">Cancel</a></div>
-    </form>
-</div>
-''')}}
+{{c.short_url_lightbox.display(url_len=url_len)}}
 <script type="text/javascript">
-    /*<![CDATA[*/
-    $('#add_url_form').attr("action",$('#sidebar a.add_short_url').attr('href'));
-    /*]]>*/
+    $(function() {
+        $('a.add-short-url').click(function() {
+            var modal = $('#lightbox_short-url-modal');
+            modal.find('#short-url-form-title').show();
+            modal.find('#short-url-form-action-label').text('Add');
+            modal.find('input[name="update"]').val('False');
+            modal.find('input[name="short_url"]').val('').removeAttr('readonly').trigger('keyup');
+            modal.find('input[name="full_url"]').val('');
+            modal.find('textarea[name="description"]').val('');
+            modal.find('input[name="private"]').removeAttr('checked');
+        });
+    });
 </script>
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/ForgeShortUrl/forgeshorturl/tests/functional/test.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/tests/functional/test.py b/ForgeShortUrl/forgeshorturl/tests/functional/test.py
index f9fa225..5d7f9d7 100644
--- a/ForgeShortUrl/forgeshorturl/tests/functional/test.py
+++ b/ForgeShortUrl/forgeshorturl/tests/functional/test.py
@@ -16,6 +16,8 @@
 #       under the License.
 
 from pylons import tmpl_context as c
+from nose.tools import assert_equal
+
 from allura.tests import decorators as td
 from alluratest.controller import TestController
 
@@ -48,13 +50,14 @@ class TestRootController(TestController):
         assert redirected.request.url == 'http://www.google.com/'
 
         response = self.app.get('/url/')
-        form = response.forms['update-short-url-form']
+        form = response.forms['short-url-form']
+        form['update'] = 'True'
         form['short_url'] = 'g'
         form['full_url'] = 'http://www.yahoo.com/'
         form.action = '/admin/url/add/'
         form.submit()
         redirected = self.app.get('/url/g').follow()
-        assert redirected.request.url == 'http://www.yahoo.com/'
+        assert_equal(redirected.request.url, 'http://www.yahoo.com/')
 
     def test_shorturl_not_found(self):
         self.app.post('/admin/url/add',

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9ea46614/ForgeShortUrl/forgeshorturl/widgets/short_url.py
----------------------------------------------------------------------
diff --git a/ForgeShortUrl/forgeshorturl/widgets/short_url.py b/ForgeShortUrl/forgeshorturl/widgets/short_url.py
index d1e3529..51f14f4 100644
--- a/ForgeShortUrl/forgeshorturl/widgets/short_url.py
+++ b/ForgeShortUrl/forgeshorturl/widgets/short_url.py
@@ -18,15 +18,9 @@
 from allura.lib.widgets import form_fields as ffw
 
 
-class CreateShortUrlWidget(ffw.Lightbox):
-
-    def resources(self):
-        for r in super(CreateShortUrlWidget, self).resources():
-            yield r
-
-
-class UpdateShortUrlWidget(ffw.Lightbox):
+class ShortUrlFormWidget(ffw.Lightbox):
     defaults = dict(
             ffw.Lightbox.defaults,
-            name='update-short-url-modal',
-            trigger='a.update-url')
+            name='short-url-modal',
+            trigger='a.add-short-url, a.update-short-url',
+            content_template='forgeshorturl:templates/form.html')


Mime
View raw message