incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [08/50] git commit: [#4902] ticket:355 Improve 'Discussion > Create Forum'
Date Fri, 24 May 2013 17:04:44 GMT
[#4902] ticket:355 Improve 'Discussion > Create Forum'


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

Branch: refs/heads/db/6255
Commit: 3f044784ac0f44ce35bfefa50b737ff125303d4f
Parents: 57c0e3e
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu May 16 13:15:15 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Wed May 22 14:56:16 2013 +0000

----------------------------------------------------------------------
 .../allura/templates/widgets/new_topic_post.html   |    2 +-
 .../forgediscussion/controllers/root.py            |   20 +++++++++-----
 ForgeDiscussion/forgediscussion/forum_main.py      |    4 ++-
 .../forgediscussion/tests/functional/test_forum.py |   19 ++++++++++++-
 4 files changed, 34 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3f044784/Allura/allura/templates/widgets/new_topic_post.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/new_topic_post.html b/Allura/allura/templates/widgets/new_topic_post.html
index d6f63a0..60e31a0 100644
--- a/Allura/allura/templates/widgets/new_topic_post.html
+++ b/Allura/allura/templates/widgets/new_topic_post.html
@@ -30,7 +30,7 @@
       <label for="{{ widget.context_for(widget.fields.forum)['id'] }}" class="cr">Forum:</label>
       <select id="{{ widget.context_for(widget.fields.forum)['id'] }}" name="{{ widget.context_for(widget.fields.forum)['rendered_name']
}}">
         {% for forum in forums %}
-          <option value="{{forum.shortname}}"{% if forum.shortname==current_forum %}selected{%
endif %}>{{forum.name}}</option>
+          <option value="{{forum.shortname}}"{% if forum == current_forum %} selected{%
endif %}>{{forum.name}}</option>
         {% endfor %}
       </select>
     </div>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3f044784/ForgeDiscussion/forgediscussion/controllers/root.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py b/ForgeDiscussion/forgediscussion/controllers/root.py
index 45a81d6..e358e18 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -95,19 +95,19 @@ class RootController(BaseController, DispatchIndex, FeedController):
 
     @with_trailing_slash
     @expose('jinja:forgediscussion:templates/discussionforums/create_topic.html')
-    def create_topic(self, new_forum=False, **kw):
+    def create_topic(self, forum_name=None, new_forum=False, **kw):
         forums = model.Forum.query.find(dict(app_config_id=c.app.config._id,
                                              parent_id=None,
                                              deleted=False))
-        current_forum = None
         c.new_topic = self.W.new_topic
         my_forums = []
+        forum_name = h.really_unicode(unquote(forum_name)) if forum_name else None
+        current_forum = None
         for f in forums:
-                if request.referer and (f.url() in request.referer):
-                    current_forum = f.shortname
-                if has_access(f, 'post')():
-                    my_forums.append(f)
-
+            if forum_name == f.shortname:
+                current_forum = f
+            if has_access(f, 'post')():
+                my_forums.append(f)
         return dict(forums=my_forums, current_forum=current_forum)
 
     @h.vardec
@@ -168,6 +168,12 @@ class RootController(BaseController, DispatchIndex, FeedController):
     def _lookup(self, id=None, *remainder):
         if id:
             id = unquote(id)
+            forum = model.Forum.query.get(
+                app_config_id=c.app.config._id,
+                shortname=id)
+            if forum is None:
+                raise exc.HTTPNotFound()
+            c.forum = forum
             return ForumController(id), remainder
         else:
             raise exc.HTTPNotFound()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3f044784/ForgeDiscussion/forgediscussion/forum_main.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/forum_main.py b/ForgeDiscussion/forgediscussion/forum_main.py
index e94855d..75b0104 100644
--- a/ForgeDiscussion/forgediscussion/forum_main.py
+++ b/ForgeDiscussion/forgediscussion/forum_main.py
@@ -152,7 +152,9 @@ class ForgeDiscussionApp(Application):
                         moderate_link = SitemapEntry('Moderate', "%smoderate/" % f.url(),
ui_icon=g.icons['pencil'],
                         small = DM.ForumPost.query.find({'discussion_id':f._id, 'status':{'$ne':
'ok'}}).count())
                     forum_links.append(SitemapEntry(f.name, f.url(), small=f.num_topics))
-            l.append(SitemapEntry('Create Topic', c.app.url + 'create_topic', ui_icon=g.icons['plus']))
+            url = c.app.url + 'create_topic/'
+            url = h.urlquote(url + c.forum.shortname if getattr(c, 'forum', None) and c.forum
else url)
+            l.append(SitemapEntry('Create Topic', url, ui_icon=g.icons['plus']))
             if has_access(c.app, 'configure')():
                 l.append(SitemapEntry('Add Forum', c.app.url + 'new_forum', ui_icon=g.icons['conversation']))
                 l.append(SitemapEntry('Admin Forums', c.project.url()+'admin/'+self.config.options.mount_point+'/forums',
ui_icon=g.icons['pencil']))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3f044784/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
index f7cfd1c..863f1c7 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -735,5 +735,20 @@ class TestForum(TestController):
             self.app.get('/discussion/general/feed%s' % ext, status=200)
 
     def test_create_topic(self):
-        r = self.app.get('/p/test/discussion/create_topic/', headers={'Referer':'/p/test/discussion/testforum/'})
-        assert '<option value="testforum"selected>Test Forum</option>' in r
\ No newline at end of file
+        r = self.app.get('/p/test/discussion/create_topic/')
+        assert 'Test Forum' in r
+        assert 'General Discussion' in r
+        r = self.app.get('/p/test/discussion/create_topic/general/')
+        assert '<option value="general" selected>General Discussion</option>'
in r
+        r = self.app.get('/p/test/discussion/create_topic/testforum/')
+        assert '<option value="testforum" selected>Test Forum</option>' in r
+
+    def test_create_topic_unicode(self):
+        r = self.app.get('/admin/discussion/forums')
+        r.forms[1]['add_forum.shortname'] = u'téstforum'.encode('utf-8')
+        r.forms[1]['add_forum.name'] = u'Tést Forum'.encode('utf-8')
+        r.forms[1].submit()
+        r = self.app.get('/admin/discussion/forums')
+        assert u'téstforum'.encode('utf-8') in r
+        r = self.app.get(u'/p/test/discussion/create_topic/téstforum/'.encode('utf-8'))
+        assert u'<option value="téstforum" selected>Tést Forum</option>' in
r


Mime
View raw message