You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/07/15 23:04:31 UTC
[35/50] [abbrv] git commit: [#4659] ticket:381 refactored multiple
attachments
[#4659] ticket:381 refactored multiple attachments
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/870f5aad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/870f5aad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/870f5aad
Branch: refs/heads/tv/6355
Commit: 870f5aad4b4c2c5680429d6f649df47a6bb7adc1
Parents: 087b9ec
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Fri Jul 5 21:03:24 2013 +0400
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Thu Jul 11 14:35:13 2013 +0000
----------------------------------------------------------------------
Allura/allura/controllers/discuss.py | 20 ++++----------------
Allura/allura/lib/widgets/discuss.py | 2 +-
Allura/allura/model/artifact.py | 7 +++++++
Allura/allura/model/discuss.py | 6 ++++++
Allura/allura/model/notification.py | 18 +++++++-----------
Allura/allura/templates/widgets/edit_post.html | 4 +---
ForgeTracker/forgetracker/tracker_main.py | 8 +-------
.../forgetracker/widgets/ticket_form.py | 2 +-
.../forgewiki/tests/functional/test_root.py | 2 +-
ForgeWiki/forgewiki/wiki_main.py | 8 +-------
10 files changed, 30 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index 97a08e5..45b0124 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -202,10 +202,7 @@ class ThreadController(BaseController, FeedController):
file_info = kw.get('file_info', None)
p = self.thread.add_post(**kw)
- if isinstance(file_info, list):
- map(p.add_attachment, file_info)
- else:
- p.add_attachment(file_info)
+ p.add_multiple_attach(file_info)
if self.thread.artifact:
self.thread.artifact.mod_date = datetime.utcnow()
flash('Message posted')
@@ -278,10 +275,7 @@ class PostController(BaseController):
require_access(self.post, 'moderate')
post_fields = self.W.edit_post.to_python(kw, None)
file_info = post_fields.pop('file_info', None)
- if isinstance(file_info, list):
- map(self.post.add_attachment, file_info)
- else:
- self.post.add_attachment(file_info)
+ self.post.add_multiple_attach(file_info)
for k,v in post_fields.iteritems():
try:
setattr(self.post, k, v)
@@ -326,10 +320,7 @@ class PostController(BaseController):
require_access(self.thread, 'post')
kw = self.W.edit_post.to_python(kw, None)
p = self.thread.add_post(parent_id=self.post._id, **kw)
- if isinstance(file_info, list):
- map(p.add_attachment, file_info)
- else:
- p.add_attachment(file_info)
+ p.add_multiple_attach(file_info)
redirect(request.referer)
@h.vardec
@@ -364,10 +355,7 @@ class PostController(BaseController):
@require_post()
def attach(self, file_info=None):
require_access(self.post, 'moderate')
- if isinstance(file_info, list):
- map(self.post.add_attachment, file_info)
- else:
- self.post.add_attachment(file_info)
+ self.post.add_multiple_attach(file_info)
redirect(request.referer)
@expose()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/Allura/allura/lib/widgets/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py
index 96a48b3..e62a993 100644
--- a/Allura/allura/lib/widgets/discuss.py
+++ b/Allura/allura/lib/widgets/discuss.py
@@ -160,9 +160,9 @@ class EditPost(ff.ForgeForm):
for r in ffw.MarkdownEdit(name='text').resources(): yield r
yield ew.JSScript('''$(document).ready(function () {
$("a.attachment_form_add_button").click(function(evt){
- evt.preventDefault();
$(this).hide();
$(".attachment_form_fields", this.parentNode).show();
+ evt.preventDefault();
});
$("a.cancel_edit_post").click(function(evt){
$("textarea", this.parentNode).val($("input.original_value", this.parentNode).val());
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 05d7c14..6fbe0f5 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -386,6 +386,13 @@ class Artifact(MappedClass):
"""
return self.get_discussion_thread()[0]
+ def add_multiple_attach(self, file_info):
+ if not isinstance(file_info, list):
+ file_info = [file_info]
+ for attach in file_info:
+ if hasattr(attach, 'file'):
+ self.attach(attach.filename, attach.file, content_type=attach.type)
+
def attach(self, filename, fp, **kw):
"""Attach a file to this Artifact.
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 7699d33..b15d03d 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -527,6 +527,12 @@ class Post(Message, VersionedArtifact, ActivityObject):
return self.attachment_class().query.find(dict(
post_id=self._id, type='attachment'))
+ def add_multiple_attach(self, file_info):
+ if isinstance(file_info, list):
+ map(self.add_attachment, file_info)
+ else:
+ self.add_attachment(file_info)
+
def add_attachment(self, file_info):
if hasattr(file_info, 'file'):
mime_type = file_info.type
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index 1d03eef..d4b0755 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -148,17 +148,13 @@ class Notification(MappedClass):
file_info = kwargs.pop('file_info', None)
if file_info is not None:
text = "%s\n\n\nAttachment:" % text
- if isinstance(file_info, list):
- for attach in file_info:
- attach.file.seek(0, 2)
- bytecount = attach.file.tell()
- attach.file.seek(0)
- text = "%s %s (%s; %s) " % (text, attach.filename, h.do_filesizeformat(bytecount), attach.type)
- else:
- file_info.file.seek(0, 2)
- bytecount = file_info.file.tell()
- file_info.file.seek(0)
- text = "%s %s (%s; %s) " % (text, file_info.filename, h.do_filesizeformat(bytecount), file_info.type)
+ if not isinstance(file_info, list):
+ file_info = [file_info]
+ for attach in file_info:
+ attach.file.seek(0, 2)
+ bytecount = attach.file.tell()
+ attach.file.seek(0)
+ text = "%s %s (%s; %s) " % (text, attach.filename, h.do_filesizeformat(bytecount), attach.type)
subject = post.subject or ''
if post.parent_id and not subject.lower().startswith('re:'):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/Allura/allura/templates/widgets/edit_post.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/edit_post.html b/Allura/allura/templates/widgets/edit_post.html
index 0fe22a7..38ad0b3 100644
--- a/Allura/allura/templates/widgets/edit_post.html
+++ b/Allura/allura/templates/widgets/edit_post.html
@@ -26,13 +26,11 @@
{{widget.display_field(widget.fields.text)}}
<input type="hidden" class="original_value" value="{{value.text}}">
<span class="arw"><span></span></span><br/>
- <div class="attachment_form_fields" style="display:none; padding: 5px 0;">
- <input type="file" class="text" multiple="True" name="{{att_name}}" {% if att_id %}id="{{att_id}}"{% endif %}/>
- </div>
<div style="clear:both"></div>
<input type="submit" value="{{submit_text}}"/>
<a href="#" class="btn link cancel_edit_post">Cancel</a>
<a href="#" class="btn link attachment_form_add_button">Add attachments</a>
+ <input type="file" class="text attachment_form_fields" style="display:none" multiple="True" name="{{att_name}}" {% if att_id %}id="{{att_id}}"{% endif %}/>
{% if widget.antispam %}{% for fld in g.antispam.extra_fields() %}
{{fld}}{% endfor %}{% endif %}
</form>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 3d2d02d..9037c4d 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -1293,13 +1293,7 @@ class TicketController(BaseController, FeedController):
if 'attachment' in post_data:
attachment = post_data['attachment']
- if isinstance(attachment, list):
- for attach in attachment:
- self.ticket.attach(attach.filename, attach.file, content_type=attach.type)
- else:
- if hasattr(attachment, 'file'):
- self.ticket.attach(
- attachment.filename, attachment.file, content_type=attachment.type)
+ self.ticket.add_multiple_attach(attachment)
for cf in c.app.globals.custom_fields or []:
if 'custom_fields.' + cf.name in post_data:
value = post_data['custom_fields.' + cf.name]
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/ForgeTracker/forgetracker/widgets/ticket_form.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/widgets/ticket_form.py b/ForgeTracker/forgetracker/widgets/ticket_form.py
index edee7e5..f022177 100644
--- a/ForgeTracker/forgetracker/widgets/ticket_form.py
+++ b/ForgeTracker/forgetracker/widgets/ticket_form.py
@@ -136,9 +136,9 @@ class TicketForm(GenericTicketForm):
yield ew.JSScript('''
$(function(){
$('#show_attach').click(function(evt) {
- evt.preventDefault();
$('#view_attach').show();
$('#show_attach').hide();
+ evt.preventDefault();
});
$('form').submit(function() {
var value = $('div.tagsinput div input').val();
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/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 05c0dd1..3312ed7 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -348,7 +348,7 @@ class TestRootController(TestController):
response = self.app.get('/wiki/tést/')
assert 'test_root.py' in response
- def test_attach_two_fiels(self):
+ def test_attach_two_files(self):
self.app.post(
'/wiki/tést/update',
params={
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/870f5aad/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 88f1102..76f66f6 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -649,13 +649,7 @@ class PageController(BaseController, FeedController):
if not self.page:
raise exc.HTTPNotFound
require_access(self.page, 'edit')
- if isinstance(file_info, list):
- for attach in file_info:
- if hasattr(attach, 'file'):
- self.page.attach(attach.filename, attach.file, content_type=attach.type)
- else:
- if hasattr(file_info, 'file'):
- self.page.attach(file_info.filename, file_info.file, content_type=file_info.type)
+ self.page.add_multiple_attach(file_info)
redirect(request.referer)
@expose()