allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [4/5] allura git commit: [#6299] allow attachments on initial forum thread creation
Date Fri, 05 Oct 2018 21:26:07 GMT
[#6299] allow attachments on initial forum thread creation


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

Branch: refs/heads/db/6299
Commit: abd12329943f3f194a6a78514d12bd596e8ae078
Parents: ca2dc13
Author: Dave Brondsema <dave@brondsema.net>
Authored: Fri Oct 5 16:01:21 2018 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Fri Oct 5 17:25:54 2018 -0400

----------------------------------------------------------------------
 Allura/allura/lib/widgets/discuss.py                  |  8 ++++++++
 Allura/allura/nf/allura/css/site_style.css            |  7 +++++++
 Allura/allura/templates/widgets/new_topic_post.html   |  7 ++++++-
 ForgeDiscussion/forgediscussion/controllers/root.py   |  2 ++
 .../forgediscussion/tests/functional/test_forum.py    | 14 +++++++++++++-
 5 files changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/abd12329/Allura/allura/lib/widgets/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py
index b571977..9575c24 100644
--- a/Allura/allura/lib/widgets/discuss.py
+++ b/Allura/allura/lib/widgets/discuss.py
@@ -191,6 +191,14 @@ class NewTopicPost(EditPost):
         show_subject=True,
         forums=None)
 
+    @property
+    def fields(self):
+        fields = super(NewTopicPost, self).fields
+        fields.append(ew.InputField(name='attachment', label='Attachment', field_type='file',
+                                    attrs={'multiple': 'True'},
+                                    validator=fev.FieldStorageUploadConverter(if_missing=None)))
+        return fields
+
 
 class _ThreadsTable(ew.TableField):
     template = 'jinja:allura:templates/widgets/threads_table.html'

http://git-wip-us.apache.org/repos/asf/allura/blob/abd12329/Allura/allura/nf/allura/css/site_style.css
----------------------------------------------------------------------
diff --git a/Allura/allura/nf/allura/css/site_style.css b/Allura/allura/nf/allura/css/site_style.css
index 1bf5e37..b124fbe 100644
--- a/Allura/allura/nf/allura/css/site_style.css
+++ b/Allura/allura/nf/allura/css/site_style.css
@@ -2616,6 +2616,13 @@ div.attachment_item{
   display: none;
 }
 
+#create_new_topic select {
+  width: auto;
+}
+#create_new_topic input[type=file] {
+  margin-left: 1em;
+}
+
 .forum-list th .ico {
   margin-left: 4px;
 }

http://git-wip-us.apache.org/repos/asf/allura/blob/abd12329/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 c7f572a..12f74da 100644
--- a/Allura/allura/templates/widgets/new_topic_post.html
+++ b/Allura/allura/templates/widgets/new_topic_post.html
@@ -17,7 +17,7 @@
        under the License.
 -#}
 {% import 'allura:templates/jinja_master/lib.html' as lib with context %}
-<form id="create_new_topic" method="post" action="{{action}}">
+<form id="create_new_topic" method="post" action="{{action}}" enctype='multipart/form-data'>
     {% if show_subject %}
     <div class="grid-19">&nbsp;</div>
     <div class="grid-19">
@@ -43,6 +43,11 @@
     </div>
     <div class="grid-19">&nbsp;</div>
     <div class="grid-19">
+        <label for="{{ widget.context_for(widget.fields.attachment)['id'] }}">Attachments:</label>
+        {{widget.display_field(widget.fields.attachment)}}
+    </div>
+    <div class="grid-19">&nbsp;</div>
+    <div class="grid-19">
       <input type="submit" value="{{submit_text}}"> <a href=".." class="btn link">Cancel</a>
     </div>
   {% if widget.antispam %}{% for fld in g.antispam.extra_fields() %}

http://git-wip-us.apache.org/repos/asf/allura/blob/abd12329/ForgeDiscussion/forgediscussion/controllers/root.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/controllers/root.py b/ForgeDiscussion/forgediscussion/controllers/root.py
index 47c724c..0b5add6 100644
--- a/ForgeDiscussion/forgediscussion/controllers/root.py
+++ b/ForgeDiscussion/forgediscussion/controllers/root.py
@@ -139,6 +139,8 @@ class RootController(BaseController, DispatchIndex, FeedController):
         thd = discussion.get_discussion_thread(dict(
             headers=dict(Subject=subject)))[0]
         p = thd.post(subject, text)
+        if 'attachment' in kw:
+            p.add_multiple_attachments(kw['attachment'])
         thd.post_to_feed(p)
         flash('Message posted')
         redirect(thd.url())

http://git-wip-us.apache.org/repos/asf/allura/blob/abd12329/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 838aa00..2684085 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -26,6 +26,7 @@ from email.mime.multipart import MIMEMultipart
 
 import pkg_resources
 import pymongo
+import webtest
 
 from ming.odm import ThreadLocalORMSession
 from pylons import tmpl_context as c
@@ -888,7 +889,6 @@ class TestForum(TestController):
         assert 'first subject' not in resp.html
         assert 'changed subject' in resp
 
-
     def test_sidebar_menu(self):
         r = self.app.get('/discussion/')
         sidebar = r.html.find('div', {'id': 'sidebar'})
@@ -963,6 +963,18 @@ class TestForum(TestController):
         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
 
+    def test_create_topic_attachment(self):
+        r = self.app.get('/discussion/create_topic/')
+        form = self.fill_new_topic_form(r)
+        for field in form.fields.values():
+            field = field[0]
+            if field.id is None:
+                continue
+            if 'attachment' in field.id:
+                form[field.name] = ('myfile.txt', b'foo bar baz')  # webtest.Upload dooesn't
work here
+        r = form.submit().follow()
+        assert 'myfile.txt' in r, r
+
     def test_viewing_a_thread_does_not_update_project_last_updated(self):
         # Create new topic/thread
         r = self.app.get('/discussion/create_topic/')


Mime
View raw message