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 2013/04/30 17:00:34 UTC
[1/3] git commit: [#5891] ticket:327 refactoring for comments
attachments
Updated Branches:
refs/heads/master 5fb297e6d -> 5c8db5459
[#5891] ticket:327 refactoring for comments 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/c40773b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/c40773b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/c40773b7
Branch: refs/heads/master
Commit: c40773b77f71335adfe7a300955e5fc99d0266c1
Parents: 57d4e6f
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Tue Apr 30 11:15:35 2013 +0400
Committer: Yuriy Arhipov <yu...@yandex.ru>
Committed: Tue Apr 30 11:16:44 2013 +0400
----------------------------------------------------------------------
Allura/allura/controllers/discuss.py | 35 ++------------------
Allura/allura/lib/helpers.py | 13 ++++++++
Allura/allura/tests/model/test_discussion.py | 14 ++++++++
3 files changed, 31 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c40773b7/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index b0bb426..eb34981 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -211,12 +211,7 @@ class ThreadController(BaseController):
file_info = kw.get('file_info', None)
p = self.thread.add_post(**kw)
is_spam = g.spam_checker.check(kw['text'], artifact=p, user=c.user)
- if hasattr(file_info, 'file'):
- p.attach(
- file_info.filename, file_info.file, content_type=file_info.type,
- post_id=p._id,
- thread_id=p.thread_id,
- discussion_id=p.discussion_id)
+ h.attach_to_post(p, file_info)
if self.thread.artifact:
self.thread.artifact.mod_date = datetime.utcnow()
flash('Message posted')
@@ -299,12 +294,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 hasattr(file_info, 'file'):
- self.post.attach(
- file_info.filename, file_info.file, content_type=file_info.type,
- post_id=self.post._id,
- thread_id=self.post.thread_id,
- discussion_id=self.post.discussion_id)
+ h.attach_to_post(self.post, file_info)
for k,v in post_fields.iteritems():
try:
setattr(self.post, k, v)
@@ -349,15 +339,7 @@ class PostController(BaseController):
kw = self.W.edit_post.to_python(kw, None)
p = self.thread.add_post(parent_id=self.post._id, **kw)
is_spam = g.spam_checker.check(kw['text'], artifact=p, user=c.user)
- if hasattr(file_info, 'file'):
- mime_type = file_info.type
- if not mime_type or '/' not in mime_type:
- mime_type = utils.guess_mime_type(file_info.filename)
- p.attach(
- file_info.filename, file_info.file, content_type=mime_type,
- post_id=p._id,
- thread_id=p.thread_id,
- discussion_id=p.discussion_id)
+ h.attach_to_post(p, file_info)
redirect(request.referer)
@h.vardec
@@ -391,16 +373,7 @@ class PostController(BaseController):
@require_post()
def attach(self, file_info=None):
require_access(self.post, 'moderate')
- if hasattr(file_info, 'file'):
- mime_type = file_info.type
- # If mime type was not passed or bogus, guess it
- if not mime_type or '/' not in mime_type:
- mime_type = utils.guess_mime_type(file_info.filename)
- self.post.attach(
- file_info.filename, file_info.file, content_type=mime_type,
- post_id=self.post._id,
- thread_id=self.post.thread_id,
- discussion_id=self.post.discussion_id)
+ h.attach_to_post(self.post, file_info)
redirect(request.referer)
@expose()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c40773b7/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 9ddad18..deed268 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -51,6 +51,7 @@ from allura.lib import exceptions as exc
from allura.lib.decorators import exceptionless
from allura.lib import AsciiDammit
from .security import has_access
+from allura.lib import utils
# validates project, subproject, and user names
@@ -702,3 +703,15 @@ def get_first(d, key):
if isinstance(v, list):
return v[0] if len(v) > 0 else None
return v
+
+
+def attach_to_post(post, file_info):
+ if hasattr(file_info, 'file'):
+ mime_type = file_info.type
+ if not mime_type or '/' not in mime_type:
+ mime_type = utils.guess_mime_type(file_info.filename)
+ post.attach(
+ file_info.filename, file_info.file, content_type=mime_type,
+ post_id=post._id,
+ thread_id=post.thread_id,
+ discussion_id=post.discussion_id)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c40773b7/Allura/allura/tests/model/test_discussion.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_discussion.py b/Allura/allura/tests/model/test_discussion.py
index 7e9df32..2ab4b2a 100644
--- a/Allura/allura/tests/model/test_discussion.py
+++ b/Allura/allura/tests/model/test_discussion.py
@@ -206,6 +206,20 @@ def test_attachment_methods():
assert '\nAttachment: fake.txt (37 Bytes; text/plain)' in n.text
@with_setup(setUp, tearDown)
+def test_attach_to_post():
+ test_file = FieldStorage()
+ test_file.name = 'file_info'
+ test_file.filename = 'test.txt'
+ test_file.type = 'text/plain'
+ test_file.file=StringIO('test file\n')
+ d = M.Discussion(shortname='test', name='test')
+ t = M.Thread.new(discussion_id=d._id, subject='Test Thread')
+ test_post = t.post('test post')
+ h.attach_to_post(test_post, test_file)
+ ThreadLocalORMSession.flush_all()
+ assert test_post.attachments.count() == 1, test_post.attachments.count()
+
+@with_setup(setUp, tearDown)
def test_discussion_delete():
d = M.Discussion(shortname='test', name='test')
t = M.Thread.new(discussion_id=d._id, subject='Test Thread')
[2/3] git commit: [#5891] ticket:316 add attachments to replies
Posted by br...@apache.org.
[#5891] ticket:316 add attachments to replies
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/57d4e6fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/57d4e6fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/57d4e6fb
Branch: refs/heads/master
Commit: 57d4e6fb9af1eabbf5cb16acbafbe0c00550db39
Parents: 5fb297e
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Mon Apr 22 14:25:23 2013 +0400
Committer: Yuriy Arhipov <yu...@yandex.ru>
Committed: Tue Apr 30 11:16:44 2013 +0400
----------------------------------------------------------------------
Allura/allura/controllers/discuss.py | 11 ++++++++++-
Allura/allura/tests/functional/test_discuss.py | 18 ++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/57d4e6fb/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index 2ef1df4..b0bb426 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -344,11 +344,20 @@ class PostController(BaseController):
@validate(pass_validator, error_handler=index)
@utils.AntiSpam.validate('Spambot protection engaged')
@require_post(redir='.')
- def reply(self, **kw):
+ def reply(self, file_info=None, **kw):
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)
is_spam = g.spam_checker.check(kw['text'], artifact=p, user=c.user)
+ if hasattr(file_info, 'file'):
+ mime_type = file_info.type
+ if not mime_type or '/' not in mime_type:
+ mime_type = utils.guess_mime_type(file_info.filename)
+ p.attach(
+ file_info.filename, file_info.file, content_type=mime_type,
+ post_id=p._id,
+ thread_id=p.thread_id,
+ discussion_id=p.discussion_id)
redirect(request.referer)
@h.vardec
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/57d4e6fb/Allura/allura/tests/functional/test_discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_discuss.py b/Allura/allura/tests/functional/test_discuss.py
index 83910e9..633f078 100644
--- a/Allura/allura/tests/functional/test_discuss.py
+++ b/Allura/allura/tests/functional/test_discuss.py
@@ -220,3 +220,21 @@ class TestAttachment(TestController):
r = self.app.post(self.post_link + 'attach',
upload_files=[('file_info', 'test.o12', 'HiThere!')])
r = self.app.post(alink, params=dict(delete='on'))
+
+ @patch('allura.model.discuss.Post.notify')
+ def test_reply_attach(self, notify):
+ notify.return_value = True
+ r = self.app.get(self.thread_link)
+ post_form = r.html.find('form', {'action':self.post_link + 'reply'})
+ params = dict()
+ inputs = post_form.findAll('input')
+
+ for field in inputs:
+ if field.has_key('name') and (field['name']!='file_info'):
+ params[field['name']] = field.has_key('value') and field['value'] or ''
+ params[post_form.find('textarea')['name']] = 'Reply'
+ r = self.app.post(self.post_link + 'reply',
+ params=params,
+ upload_files=[('file_info', 'test.txt', 'HiThere!')])
+ r = self.app.get(self.thread_link)
+ assert "test.txt" in r
[3/3] git commit: [#5891] ticket:327 removed add_attach from helpers,
and put it to Post
Posted by br...@apache.org.
[#5891] ticket:327 removed add_attach from helpers, and put it to Post
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/5c8db545
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/5c8db545
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/5c8db545
Branch: refs/heads/master
Commit: 5c8db5459133394fbfe82828fcab82d42bd785ad
Parents: c40773b
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Tue Apr 30 15:10:11 2013 +0400
Committer: Yuriy Arhipov <yu...@yandex.ru>
Committed: Tue Apr 30 15:10:11 2013 +0400
----------------------------------------------------------------------
Allura/allura/controllers/discuss.py | 8 ++++----
Allura/allura/lib/helpers.py | 15 +--------------
Allura/allura/model/discuss.py | 12 ++++++++++++
Allura/allura/tests/model/test_discussion.py | 7 +++++--
4 files changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5c8db545/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index eb34981..218f9b4 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -211,7 +211,7 @@ class ThreadController(BaseController):
file_info = kw.get('file_info', None)
p = self.thread.add_post(**kw)
is_spam = g.spam_checker.check(kw['text'], artifact=p, user=c.user)
- h.attach_to_post(p, file_info)
+ p.add_attachment(file_info)
if self.thread.artifact:
self.thread.artifact.mod_date = datetime.utcnow()
flash('Message posted')
@@ -294,7 +294,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)
- h.attach_to_post(self.post, file_info)
+ self.post.add_attachment(file_info)
for k,v in post_fields.iteritems():
try:
setattr(self.post, k, v)
@@ -339,7 +339,7 @@ class PostController(BaseController):
kw = self.W.edit_post.to_python(kw, None)
p = self.thread.add_post(parent_id=self.post._id, **kw)
is_spam = g.spam_checker.check(kw['text'], artifact=p, user=c.user)
- h.attach_to_post(p, file_info)
+ p.add_attachment(file_info)
redirect(request.referer)
@h.vardec
@@ -373,7 +373,7 @@ class PostController(BaseController):
@require_post()
def attach(self, file_info=None):
require_access(self.post, 'moderate')
- h.attach_to_post(self.post, file_info)
+ self.post.add_attachment(file_info)
redirect(request.referer)
@expose()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5c8db545/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index deed268..29cf44e 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -51,7 +51,6 @@ from allura.lib import exceptions as exc
from allura.lib.decorators import exceptionless
from allura.lib import AsciiDammit
from .security import has_access
-from allura.lib import utils
# validates project, subproject, and user names
@@ -702,16 +701,4 @@ def get_first(d, key):
v = d.get(key)
if isinstance(v, list):
return v[0] if len(v) > 0 else None
- return v
-
-
-def attach_to_post(post, file_info):
- if hasattr(file_info, 'file'):
- mime_type = file_info.type
- if not mime_type or '/' not in mime_type:
- mime_type = utils.guess_mime_type(file_info.filename)
- post.attach(
- file_info.filename, file_info.file, content_type=mime_type,
- post_id=post._id,
- thread_id=post.thread_id,
- discussion_id=post.discussion_id)
+ return v
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5c8db545/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index d169e1b..4375077 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -31,6 +31,7 @@ from ming.utils import LazyProperty
from allura.lib import helpers as h
from allura.lib import security
from allura.lib.security import require_access, has_access
+from allura.lib import utils
from allura.model.notification import Notification, Mailbox
from .artifact import Artifact, ArtifactReference, VersionedArtifact, Snapshot, Message, Feed
from .attachments import BaseAttachment
@@ -513,6 +514,17 @@ class Post(Message, VersionedArtifact, ActivityObject):
return self.attachment_class().query.find(dict(
post_id=self._id, type='attachment'))
+ def add_attachment(self, file_info):
+ if hasattr(file_info, 'file'):
+ mime_type = file_info.type
+ if not mime_type or '/' not in mime_type:
+ mime_type = utils.guess_mime_type(file_info.filename)
+ self.attach(
+ file_info.filename, file_info.file, content_type=mime_type,
+ post_id=self._id,
+ thread_id=self.thread_id,
+ discussion_id=self.discussion_id)
+
def last_edit_by(self):
return User.query.get(_id=self.last_edit_by_id) or User.anonymous()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/5c8db545/Allura/allura/tests/model/test_discussion.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_discussion.py b/Allura/allura/tests/model/test_discussion.py
index 2ab4b2a..35c5594 100644
--- a/Allura/allura/tests/model/test_discussion.py
+++ b/Allura/allura/tests/model/test_discussion.py
@@ -206,7 +206,7 @@ def test_attachment_methods():
assert '\nAttachment: fake.txt (37 Bytes; text/plain)' in n.text
@with_setup(setUp, tearDown)
-def test_attach_to_post():
+def test_add_attachment():
test_file = FieldStorage()
test_file.name = 'file_info'
test_file.filename = 'test.txt'
@@ -215,9 +215,12 @@ def test_attach_to_post():
d = M.Discussion(shortname='test', name='test')
t = M.Thread.new(discussion_id=d._id, subject='Test Thread')
test_post = t.post('test post')
- h.attach_to_post(test_post, test_file)
+ test_post.add_attachment(test_file)
ThreadLocalORMSession.flush_all()
assert test_post.attachments.count() == 1, test_post.attachments.count()
+ attach = test_post.attachments.first()
+ assert attach.filename == 'test.txt', attach.filename
+ assert attach.content_type == 'text/plain', attach.content_type
@with_setup(setUp, tearDown)
def test_discussion_delete():