You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2018/10/05 21:26:04 UTC

[1/5] allura git commit: [#6299] make all markdown textareas look better before the editor loads in

Repository: allura
Updated Branches:
  refs/heads/db/6299 [created] 34fee5a3d


[#6299] make all markdown textareas look better before the editor loads in


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

Branch: refs/heads/db/6299
Commit: 34fee5a3df9e60fc36da4d05cb51a0c6df05910e
Parents: abd1232
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Oct 5 16:14:12 2018 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Fri Oct 5 17:25:54 2018 -0400

----------------------------------------------------------------------
 Allura/allura/lib/widgets/resources/css/markitup_sf.css | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/34fee5a3/Allura/allura/lib/widgets/resources/css/markitup_sf.css
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/css/markitup_sf.css b/Allura/allura/lib/widgets/resources/css/markitup_sf.css
index 072361c..292c061 100644
--- a/Allura/allura/lib/widgets/resources/css/markitup_sf.css
+++ b/Allura/allura/lib/widgets/resources/css/markitup_sf.css
@@ -22,6 +22,12 @@
   margin-top: 5px;
   margin-bottom: 5px;
 }
+.markdown_edit textarea {  /* so initial display before editor appears looks consistent with editor size */
+  box-sizing: border-box;
+  width: 100%;
+  margin: 0;
+  height: 168px;
+}
 .markdown_edit .CodeMirror {
   color: rgb(85, 85, 85);
   min-height: 60px;


[5/5] allura git commit: [#6299] make attachments with thumbnails look better

Posted by br...@apache.org.
[#6299] make attachments with thumbnails look better


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

Branch: refs/heads/db/6299
Commit: 5ab6a82dddea9261a94a48673689839d102b2e8d
Parents: b57b458
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Oct 5 13:47:00 2018 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Fri Oct 5 17:25:54 2018 -0400

----------------------------------------------------------------------
 Allura/allura/nf/allura/css/site_style.css           | 7 +++----
 Allura/allura/templates/widgets/attachment_list.html | 3 ++-
 Allura/allura/templates/widgets/post_widget.html     | 2 +-
 ForgeBlog/forgeblog/model/blog.py                    | 1 +
 ForgeWiki/forgewiki/model/wiki.py                    | 1 +
 ForgeWiki/forgewiki/tests/functional/test_root.py    | 2 +-
 6 files changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/5ab6a82d/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 0fb43fe..1bf5e37 100644
--- a/Allura/allura/nf/allura/css/site_style.css
+++ b/Allura/allura/nf/allura/css/site_style.css
@@ -2292,8 +2292,10 @@ div.attachment_thumb .file {
     top: 0;
     right: -40px;
 }
-div.attachment_thumb .file_type {
+div.attachment_thumb img {
   border: 1px solid #ccc;
+}
+div.attachment_thumb .file_type {
   display: block;
   height: 100px;
   width: 100px;
@@ -2303,9 +2305,6 @@ div.attachment_thumb .file_type {
   font-weight: bold;
   font-size: 1.2em;
   margin-bottom: .5em;
-  background: #ccc;
-  background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, to(#cccccc), from(white));
-  background-image: -moz-linear-gradient(100% 100% 90deg, #cccccc, white 100%);
 }
 div.attachment_thumb .file_type span {
   display: block;

http://git-wip-us.apache.org/repos/asf/allura/blob/5ab6a82d/Allura/allura/templates/widgets/attachment_list.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/attachment_list.html b/Allura/allura/templates/widgets/attachment_list.html
index c553dd7..f924b42 100644
--- a/Allura/allura/templates/widgets/attachment_list.html
+++ b/Allura/allura/templates/widgets/attachment_list.html
@@ -26,8 +26,9 @@
           <div class="attachment_thumb">
             <a href="{{att.url()}}">
               <img src="{{att.url()}}/thumb" alt="Thumbnail"/>
-            </a><br/>
+            <br/>
             {{att.filename}}
+            </a>
             {% if edit_mode %}
             <form method="post" action="{{att.url()}}" onsubmit="{{onsubmit}}">
               <input type="hidden" name="delete" value="True"/>

http://git-wip-us.apache.org/repos/asf/allura/blob/5ab6a82d/Allura/allura/templates/widgets/post_widget.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/post_widget.html b/Allura/allura/templates/widgets/post_widget.html
index 657d01c..f98aafa 100644
--- a/Allura/allura/templates/widgets/post_widget.html
+++ b/Allura/allura/templates/widgets/post_widget.html
@@ -116,7 +116,7 @@
                  <div class="attachment_toolbar">
                     <form method="POST" action="{{att.url()}}">
                         {% if h.has_access(value, 'moderate')()%}
-                            <a href="javascript: void(0)"  onclick="$(this).closest('form').submit();" title="Remove Attachment"" class="btn ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only">
+                            <a href="javascript: void(0)"  onclick="$(this).closest('form').submit();" title="Remove Attachment" class="btn ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only">
                                 <span><i class="fa fa-trash-o" aria-hidden="true"></i></span>
                             </a>
                         {% endif %}

http://git-wip-us.apache.org/repos/asf/allura/blob/5ab6a82d/ForgeBlog/forgeblog/model/blog.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/model/blog.py b/ForgeBlog/forgeblog/model/blog.py
index baa4520..f20b228 100644
--- a/ForgeBlog/forgeblog/model/blog.py
+++ b/ForgeBlog/forgeblog/model/blog.py
@@ -328,6 +328,7 @@ class BlogPost(M.VersionedArtifact, ActivityObject):
 
 class BlogAttachment(M.BaseAttachment):
     ArtifactType = BlogPost
+    thumbnail_size = (100, 100)
 
     class __mongometa__:
         polymorphic_identity = 'BlogAttachment'

http://git-wip-us.apache.org/repos/asf/allura/blob/5ab6a82d/ForgeWiki/forgewiki/model/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/model/wiki.py b/ForgeWiki/forgewiki/model/wiki.py
index 1cf165b..bb9f452 100644
--- a/ForgeWiki/forgewiki/model/wiki.py
+++ b/ForgeWiki/forgewiki/model/wiki.py
@@ -281,6 +281,7 @@ class Page(VersionedArtifact, ActivityObject):
 
 class WikiAttachment(BaseAttachment):
     ArtifactType = Page
+    thumbnail_size = (100, 100)
 
     class __mongometa__:
         polymorphic_identity = 'WikiAttachment'

http://git-wip-us.apache.org/repos/asf/allura/blob/5ab6a82d/ForgeWiki/forgewiki/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index b157e30..98533eb 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -508,7 +508,7 @@ class TestRootController(TestController):
         r = self.app.get('/wiki/TEST/attachment/' + filename + '/thumb')
 
         thumbnail = PIL.Image.open(StringIO.StringIO(r.body))
-        assert thumbnail.size == (255, 255)
+        assert thumbnail.size == (100, 100)
 
         # Make sure thumbnail is absent
         r = self.app.get('/wiki/TEST/')


[3/5] allura git commit: [#6299] support attachments on blog posts

Posted by br...@apache.org.
[#6299] support attachments on blog posts


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

Branch: refs/heads/db/6299
Commit: b57b458f990b0991bf913ac987ed5f6a00020b90
Parents: 4c5c9f9
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Oct 5 13:26:21 2018 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Fri Oct 5 17:25:54 2018 -0400

----------------------------------------------------------------------
 ForgeBlog/forgeblog/main.py                     | 27 ++++++++++----
 ForgeBlog/forgeblog/model/__init__.py           |  2 +-
 ForgeBlog/forgeblog/model/blog.py               |  8 +++-
 .../forgeblog/templates/blog/edit_posts.html    | 31 ----------------
 ForgeBlog/forgeblog/templates/blog/post.html    |  4 +-
 .../templates/blog_widgets/post_form.html       |  8 +++-
 .../forgeblog/tests/functional/test_root.py     | 39 ++++++++++++++------
 ForgeBlog/forgeblog/widgets.py                  |  3 ++
 8 files changed, 67 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/b57b458f/ForgeBlog/forgeblog/main.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/main.py b/ForgeBlog/forgeblog/main.py
index 653400f..bf4c3ec 100644
--- a/ForgeBlog/forgeblog/main.py
+++ b/ForgeBlog/forgeblog/main.py
@@ -49,6 +49,7 @@ from allura.lib.widgets import form_fields as ffw
 from allura.lib.widgets.search import SearchResults, SearchHelp
 from allura import model as M
 from allura.controllers import BaseController, AppDiscussionController, AppDiscussionRestController
+from allura.controllers.attachments import AttachmentController, AttachmentsController
 from allura.controllers.rest import AppRestControllerMixin
 from allura.controllers.feed import FeedArgs, FeedController
 
@@ -68,8 +69,6 @@ class W:
     new_post_form = widgets.NewPostForm()
     edit_post_form = widgets.EditPostForm()
     view_post_form = widgets.ViewPostForm()
-    label_edit = ffw.LabelEdit()
-    attachment_add = ffw.AttachmentAdd()
     attachment_list = ffw.AttachmentList()
     preview_post_form = widgets.PreviewPostForm()
     subscribe_form = SubscribeForm(thing='post')
@@ -207,7 +206,7 @@ class ForgeBlogApp(Application):
 
     def uninstall(self, project):
         "Remove all the tool's artifacts from the database"
-        BM.Attachment.query.remove(dict(app_config_id=c.app.config._id))
+        BM.BlogAttachment.query.remove(dict(app_config_id=c.app.config._id))
         BM.BlogPost.query.remove(dict(app_config_id=c.app.config._id))
         BM.BlogPostSnapshot.query.remove(dict(app_config_id=c.app.config._id))
         super(ForgeBlogApp, self).uninstall(project)
@@ -304,9 +303,12 @@ class RootController(BaseController, FeedController):
     def save(self, **kw):
         require_access(c.app, 'write')
         self.rate_limit(BM.BlogPost, 'Create/edit', c.app.config.url())
+        attachment = kw.pop('attachment', None)
         post = BM.BlogPost.new(**kw)
         g.spam_checker.check(kw['title'] + u'\n' + kw['text'], artifact=post,
                              user=c.user, content_type='blog-post')
+        if attachment is not None:
+            post.add_multiple_attachments(attachment)
         redirect(h.really_unicode(post.url()).encode('utf-8'))
 
     @with_trailing_slash
@@ -338,22 +340,32 @@ class RootController(BaseController, FeedController):
             app.url)
 
 
+class BlogAttachmentController(AttachmentController):
+    AttachmentClass = BM.BlogAttachment
+
+
+class BlogAttachmentsController(AttachmentsController):
+    AttachmentControllerClass = BlogAttachmentController
+
+
 class PostController(BaseController, FeedController):
 
     def __init__(self, post):
         self.post = post
+        self.attachment = BlogAttachmentsController(self.post)
 
     def _check_security(self):
         require_access(self.post, 'read')
+        if self.post.state == 'draft':
+            require_access(self.post, 'write')
 
     @expose('jinja:forgeblog:templates/blog/post.html')
     @with_trailing_slash
     @validate(dict(page=validators.Int(if_empty=0, if_invalid=0),
                    limit=validators.Int(if_empty=None, if_invalid=None)))
     def index(self, page=0, limit=None, **kw):
-        if self.post.state == 'draft':
-            require_access(self.post, 'write')
         c.form = W.view_post_form
+        c.attachment_list = W.attachment_list
         c.subscribe_form = W.subscribe_form
         c.thread = W.thread
         post_count = self.post.discussion_thread.post_count
@@ -373,9 +385,7 @@ class PostController(BaseController, FeedController):
         require_access(self.post, 'write')
         self.rate_limit(BM.BlogPost, 'Create/edit', c.app.config.url())
         c.form = W.edit_post_form
-        c.attachment_add = W.attachment_add
         c.attachment_list = W.attachment_list
-        c.label_edit = W.label_edit
         return dict(post=self.post)
 
     @without_trailing_slash
@@ -407,6 +417,9 @@ class PostController(BaseController, FeedController):
         else:
             g.spam_checker.check(kw['title'] + u'\n' + kw['text'], artifact=self.post,
                                  user=c.user, content_type='blog-post')
+        attachment = kw.pop('attachment', None)
+        if attachment is not None:
+            self.post.add_multiple_attachments(attachment)
         for k, v in kw.iteritems():
             setattr(self.post, k, v)
         self.post.commit()

http://git-wip-us.apache.org/repos/asf/allura/blob/b57b458f/ForgeBlog/forgeblog/model/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/model/__init__.py b/ForgeBlog/forgeblog/model/__init__.py
index 7c17d5c..e1b5fcc 100644
--- a/ForgeBlog/forgeblog/model/__init__.py
+++ b/ForgeBlog/forgeblog/model/__init__.py
@@ -15,4 +15,4 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-from blog import Globals, BlogPost, Attachment, BlogPostSnapshot
+from blog import Globals, BlogPost, BlogAttachment, BlogPostSnapshot

http://git-wip-us.apache.org/repos/asf/allura/blob/b57b458f/ForgeBlog/forgeblog/model/blog.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/model/blog.py b/ForgeBlog/forgeblog/model/blog.py
index 67b45b6..baa4520 100644
--- a/ForgeBlog/forgeblog/model/blog.py
+++ b/ForgeBlog/forgeblog/model/blog.py
@@ -321,9 +321,13 @@ class BlogPost(M.VersionedArtifact, ActivityObject):
             feed_item.delete()
         super(BlogPost, self).delete()
 
+    @classmethod
+    def attachment_class(cls):
+        return BlogAttachment
+
 
-class Attachment(M.BaseAttachment):
-    ArtifactClass = BlogPost
+class BlogAttachment(M.BaseAttachment):
+    ArtifactType = BlogPost
 
     class __mongometa__:
         polymorphic_identity = 'BlogAttachment'

http://git-wip-us.apache.org/repos/asf/allura/blob/b57b458f/ForgeBlog/forgeblog/templates/blog/edit_posts.html
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/templates/blog/edit_posts.html b/ForgeBlog/forgeblog/templates/blog/edit_posts.html
deleted file mode 100644
index 5c87a3c..0000000
--- a/ForgeBlog/forgeblog/templates/blog/edit_posts.html
+++ /dev/null
@@ -1,31 +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.
--#}
-{% extends g.theme.master %}
-
-{% block title %}{{c.project.name}} / {{c.app.config.options.mount_label}}{% endblock %}
-
-{% block header %}{{c.project.name}} / {{c.app.config.options.mount_label}}: Recent posts{% endblock %}
-
-{% block content %}
-    <div class="content">
-      {% for post in posts %}
-        {{c.form.display(value=post)}}
-      {% endfor %}
-    </div>
-{% endblock %}

http://git-wip-us.apache.org/repos/asf/allura/blob/b57b458f/ForgeBlog/forgeblog/templates/blog/post.html
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/templates/blog/post.html b/ForgeBlog/forgeblog/templates/blog/post.html
index 979b1f6..1b91176 100644
--- a/ForgeBlog/forgeblog/templates/blog/post.html
+++ b/ForgeBlog/forgeblog/templates/blog/post.html
@@ -35,7 +35,9 @@
 
 {% block content %}
     {{c.form.display(value=post, base_post=base_post)}}
-    <div style="clear:both;"></div>
+    <div class="grid-19">
+        {{c.attachment_list.display(attachments=post.attachments, edit_mode=h.has_access(post, 'edit')())}}
+    </div>
     {% if post.discussion_thread and c.app.show_discussion %}
     <div style="margin-top: 10px">
       {{c.thread.display(value=post.discussion_thread,page=page,limit=limit,count=count)}}

http://git-wip-us.apache.org/repos/asf/allura/blob/b57b458f/ForgeBlog/forgeblog/templates/blog_widgets/post_form.html
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/templates/blog_widgets/post_form.html b/ForgeBlog/forgeblog/templates/blog_widgets/post_form.html
index 5ec530f..b8216b0 100644
--- a/ForgeBlog/forgeblog/templates/blog_widgets/post_form.html
+++ b/ForgeBlog/forgeblog/templates/blog_widgets/post_form.html
@@ -28,14 +28,18 @@
   <div class="grid-19">
     {{widget.display_field(widget.fields.text)}}
   </div>
-  <div class="grid-6">
+  <div class="grid-5">
     <label class="cr">State:</label>
     {{widget.display_field(widget.fields.state)}}
   </div>
-  <div class="grid-13">
+  <div class="grid-6">
     <label class="cr">Labels:</label>
     {{widget.display_field(widget.fields.labels)}}
   </div>
+  <div class="grid-8">
+    <label class="cr">Add attachments:</label>
+    {{widget.display_field(widget.fields.attachment)}}
+  </div>
   {% for field in widget.fields %}
     {% if field.field_type == 'hidden' %}
       {% set ctx=widget.context_for(field) %}

http://git-wip-us.apache.org/repos/asf/allura/blob/b57b458f/ForgeBlog/forgeblog/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/tests/functional/test_root.py b/ForgeBlog/forgeblog/tests/functional/test_root.py
index 22a8fa3..4085744 100644
--- a/ForgeBlog/forgeblog/tests/functional/test_root.py
+++ b/ForgeBlog/forgeblog/tests/functional/test_root.py
@@ -19,31 +19,23 @@ import datetime
 import json
 
 import tg
-from nose.tools import assert_equal, assert_in
+from nose.tools import assert_equal
 from mock import patch
 
 from allura.lib import helpers as h
 from alluratest.controller import TestController
 
-#---------x---------x---------x---------x---------x---------x---------x
-# RootController methods exposed:
-#     index, new_page, search
-# PageController methods exposed:
-#     index, edit, history, diff, raw, revert, update
-# CommentController methods exposed:
-#     reply, delete
-
 
 class Test(TestController):
 
-    def _post(self, slug='', **kw):
+    def _post(self, slug='', extra_app_post_params={}, **kw):
         d = {
             'title': 'My Post',
             'text': 'Nothing to see here',
             'labels': '',
             'state': 'published'}
         d.update(kw)
-        r = self.app.post('/blog%s/save' % slug, params=d)
+        r = self.app.post('/blog%s/save' % slug, params=d, **extra_app_post_params)
         return r
 
     def _blog_date(self):
@@ -169,6 +161,31 @@ class Test(TestController):
                                 extra_environ=dict(username='*anonymous'))
         assert 'Nothing' not in response
 
+    def test_post_attachments(self):
+        # create
+        upload = ('attachment', 'nums.txt', '123412341234')
+        self._post(extra_app_post_params=dict(upload_files=[upload]))
+
+        # check it is listed
+        d = self._blog_date()
+        r = self.app.get('/blog/%s/my-post/' % d)
+        assert 'nums.txt' in r
+
+        # edit
+        slug = '/%s/my-post' % d
+        upload = ('attachment', 'letters.txt', 'abcdefghij')
+        self._post(slug=slug,
+                   extra_app_post_params=dict(upload_files=[upload]))
+
+        # check both are there
+        r = self.app.get('/blog/%s/my-post/' % d)
+        assert 'nums.txt' in r
+        assert 'letters.txt' in r
+
+        # check attachment is accessible
+        r = self.app.get('/blog/%s/my-post/attachment/letters.txt' % d)
+        assert 'abcdefghij' in r
+
     def test_post_history(self):
         self._post()
         d = self._blog_date()

http://git-wip-us.apache.org/repos/asf/allura/blob/b57b458f/ForgeBlog/forgeblog/widgets.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/widgets.py b/ForgeBlog/forgeblog/widgets.py
index 9d54903..6b055fc 100644
--- a/ForgeBlog/forgeblog/widgets.py
+++ b/ForgeBlog/forgeblog/widgets.py
@@ -31,6 +31,7 @@ class BlogPager(ffw.PageList):
 
 class NewPostForm(forms.ForgeForm):
     template = 'jinja:forgeblog:templates/blog_widgets/post_form.html'
+    enctype = 'multipart/form-data'
 
     class fields(ew_core.NameList):
         title = ew.TextField(validator=fev.UnicodeString(not_empty=True,
@@ -48,6 +49,8 @@ class NewPostForm(forms.ForgeForm):
                 ew.Option(py_value='published', label='Published')])
         labels = ffw.LabelEdit(placeholder='Add labels here',
                                title='Add labels here')
+        attachment = ew.InputField(label='Attachment', field_type='file', attrs={'multiple': 'True'},
+                                   validator=fev.FieldStorageUploadConverter(if_missing=None))
 
     def resources(self):
         for r in super(NewPostForm, self).resources():


[2/5] allura git commit: [#6299] lightbox on attachments, and make it easier to use

Posted by br...@apache.org.
[#6299] lightbox on attachments, and make it easier to use


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

Branch: refs/heads/db/6299
Commit: ca2dc134d4cfe368722e402af00d855092bd47a0
Parents: 5ab6a82
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Oct 5 14:57:18 2018 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Fri Oct 5 17:25:54 2018 -0400

----------------------------------------------------------------------
 Allura/allura/lib/utils.py                           |  2 +-
 Allura/allura/lib/widgets/discuss.py                 | 13 -------------
 Allura/allura/public/nf/js/allura-base.js            | 15 +++++++++++++++
 Allura/allura/templates/widgets/attachment_list.html |  2 +-
 Allura/allura/templates/widgets/post_widget.html     |  7 +------
 .../templates/widgets/project_screenshots.html       |  6 +-----
 6 files changed, 19 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/ca2dc134/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index dcf4b79..ccc19d2 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -591,7 +591,7 @@ class ForgeHTMLSanitizerFilter(html5lib.filters.sanitizer.Filter):
         self.allowed_elements = set(html5lib.filters.sanitizer.allowed_elements) - _form_elements
 
         # srcset is used in our own project_list/project_summary widgets which are used as macros so go through markdown
-        self.allowed_attributes = html5lib.filters.sanitizer.allowed_attributes | {(None, 'srcset'), (None, 'data-src')}
+        self.allowed_attributes = html5lib.filters.sanitizer.allowed_attributes | {(None, 'srcset')}
 
         self.valid_iframe_srcs = ('https://www.youtube.com/embed/', 'https://www.gittip.com/')
         self._prev_token_was_ok_iframe = False

http://git-wip-us.apache.org/repos/asf/allura/blob/ca2dc134/Allura/allura/lib/widgets/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py
index ac76da9..b571977 100644
--- a/Allura/allura/lib/widgets/discuss.py
+++ b/Allura/allura/lib/widgets/discuss.py
@@ -417,19 +417,6 @@ class Post(HierWidget):
                     });
                 }
             });
-
-            //lightbox_me script to create lightbox of attached images
-            $('.lightbox').click(function(e) {
-                var image_source = $(this).data("src");
-                var image = $('#lightbox').find('img:first');
-                image.attr("src", image_source);
-
-                $('#lightbox').lightbox_me({
-                    centered: true
-                });
-
-                e.preventDefault();
-            });
         }());
         ''')
 

http://git-wip-us.apache.org/repos/asf/allura/blob/ca2dc134/Allura/allura/public/nf/js/allura-base.js
----------------------------------------------------------------------
diff --git a/Allura/allura/public/nf/js/allura-base.js b/Allura/allura/public/nf/js/allura-base.js
index e03f065..f7b8a3c 100644
--- a/Allura/allura/public/nf/js/allura-base.js
+++ b/Allura/allura/public/nf/js/allura-base.js
@@ -216,4 +216,19 @@ $(function(){
 
     twemoji.size = '36x36';
     twemoji.parse($('#content_base')[0]);
+
+    $('.lightbox').click(function(e) {
+        var image_source = $(this).data("src") || $(this).attr('href');
+        if ($('#lightbox').length === 0) {
+            $('body').append('<div id="lightbox" style="display:none; height: 90%"><img style="display: block; max-height: 100%; max-width: 100%; margin-left: auto; margin-right: auto;"></div>');
+        }
+        var image = $('#lightbox').find('img:first');
+        image.attr("src", image_source);
+
+        $('#lightbox').lightbox_me({
+            centered: true
+        });
+
+        e.preventDefault();
+    });
 });

http://git-wip-us.apache.org/repos/asf/allura/blob/ca2dc134/Allura/allura/templates/widgets/attachment_list.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/attachment_list.html b/Allura/allura/templates/widgets/attachment_list.html
index f924b42..1bedec0 100644
--- a/Allura/allura/templates/widgets/attachment_list.html
+++ b/Allura/allura/templates/widgets/attachment_list.html
@@ -24,7 +24,7 @@
     <div class="attachment_images">
       {% for att in attachments if att.is_image() %}
           <div class="attachment_thumb">
-            <a href="{{att.url()}}">
+            <a href="{{att.url()}}" class="lightbox">
               <img src="{{att.url()}}/thumb" alt="Thumbnail"/>
             <br/>
             {{att.filename}}

http://git-wip-us.apache.org/repos/asf/allura/blob/ca2dc134/Allura/allura/templates/widgets/post_widget.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/post_widget.html b/Allura/allura/templates/widgets/post_widget.html
index f98aafa..4439821 100644
--- a/Allura/allura/templates/widgets/post_widget.html
+++ b/Allura/allura/templates/widgets/post_widget.html
@@ -101,7 +101,7 @@
             <div class="attachment_item">
                 {% if att.is_image() %}
                     <div class="attachment_thumbnail">
-                        <a class="lightbox" data-src="{{att.url()}}" href="{{att.url()}}">
+                        <a class="lightbox" href="{{att.url()}}">
                             <img src="{{att.url()}}/thumb" alt="Thumbnail"/>
                         </a>
                     </div>
@@ -168,9 +168,4 @@
       </li>
     </ul>
   </div>
-    <!-- lightbox_me div that will dynamically load attachment image -->
-  <div id="lightbox" style="display:none; height: 90%">
-      <img style="width: inherit; height: inherit; display: block; margin-left: auto; margin-right: auto;">
-  </div>
-
 </div>

http://git-wip-us.apache.org/repos/asf/allura/blob/ca2dc134/Allura/allura/templates/widgets/project_screenshots.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/project_screenshots.html b/Allura/allura/templates/widgets/project_screenshots.html
index 83bbbc1..5aa5059 100644
--- a/Allura/allura/templates/widgets/project_screenshots.html
+++ b/Allura/allura/templates/widgets/project_screenshots.html
@@ -25,7 +25,7 @@
   {% for ss in screenshots %}
   <div data-ss-id="{{ ss._id }}" class="screenshot">
     <div class="image">
-      <a class="lightbox" data-src="{{project.url()}}screenshot/{{h.urlquote(ss.filename)}}" href="{{project.url()}}screenshot/{{h.urlquote(ss.filename)}}" ><img src="{{project.url()}}screenshot/{{h.urlquote(ss.filename)}}/thumb" alt="Screenshot thumbnail"/></a>
+      <a class="lightbox" href="{{project.url()}}screenshot/{{h.urlquote(ss.filename)}}" ><img src="{{project.url()}}screenshot/{{h.urlquote(ss.filename)}}/thumb" alt="Screenshot thumbnail"/></a>
       {% if not edit %}
       <br>
       {{ss.caption}}
@@ -50,7 +50,3 @@
   {% endfor %}
 </div>
 {% if screenshots.__len__() %}<hr>{% endif %}
-<!-- lightbox_me div that will dynamically load attachment image -->
-<div id="lightbox" style="display:none; height: 90%">
-  <img style="width: inherit; height: inherit; display: block; margin-left: auto; margin-right: auto;">
-</div>
\ No newline at end of file


[4/5] allura git commit: [#6299] allow attachments on initial forum thread creation

Posted by br...@apache.org.
[#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 <da...@brondsema.net>
Authored: Fri Oct 5 16:01:21 2018 -0400
Committer: Dave Brondsema <da...@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/')