summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-05-29 03:15:43 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-05-29 03:15:43 -0400
commitd6e30bef98ac85a8606284aba4adaf17de811b63 (patch)
tree5bb860eb9c21328a9c791e0c32f868ad49ae89db
parent8a1e7f47c1aa74d56e0d40ba46d9c771b6ac33eb (diff)
downloadaskbot-d6e30bef98ac85a8606284aba4adaf17de811b63.tar.gz
askbot-d6e30bef98ac85a8606284aba4adaf17de811b63.tar.bz2
askbot-d6e30bef98ac85a8606284aba4adaf17de811b63.zip
hopefully it is possible to edit by email
-rw-r--r--askbot/mail/lamson_handlers.py25
-rw-r--r--askbot/models/__init__.py24
-rw-r--r--askbot/models/reply_by_email.py39
-rw-r--r--askbot/tests/reply_by_email_tests.py8
4 files changed, 61 insertions, 35 deletions
diff --git a/askbot/mail/lamson_handlers.py b/askbot/mail/lamson_handlers.py
index e98e3e99..d803dcf2 100644
--- a/askbot/mail/lamson_handlers.py
+++ b/askbot/mail/lamson_handlers.py
@@ -259,16 +259,18 @@ def VALIDATE_EMAIL(
def PROCESS(
parts = None,
reply_address_object = None,
+ subject_line = None,
**kwargs
):
"""handler to process the emailed message
and make a post to askbot based on the contents of
the email, including the text body and the file attachments"""
- #split email into bits
+ #1) get actual email content
+ # todo: factor this out into the process_reply decorator
reply_code = reply_address_object.address
body_text, stored_files, signature = mail.process_parts(parts, reply_code)
- #if have signature update signature
+ #2) process body text and email signature
user = reply_address_object.user
if signature:#if there, then it was stripped
if signature != user.email_signature:
@@ -281,14 +283,17 @@ def PROCESS(
raise ValueError('email signature changed or unknown')
body_text = stripped_body_text
- #validate email address
+ #3) validate email address and save user
user.email_isvalid = True
user.save()#todo: actually, saving is not necessary, if nothing changed
- #todo: elaborate - here in some cases we want to add an edit
- #and in other cases - replace the text entirely
- if reply_address_object.was_used:
- action = reply_address_object.edit_post
- else:
- action = reply_address_object.create_reply
- action(body_text, stored_files)
+ #4) actually make an edit in the forum
+ robj = reply_address_object
+ add_post_actions = ('post_comment', 'post_answer', 'auto_answer_or_comment')
+ if robj.reply_action in ('replace_content', 'append_content'):
+ robj.edit_post(body_text, title = subject_line)
+ elif robj.reply_action in add_post_actions:
+ if robj.was_used:
+ robj.edit_post(body_text, reply_action = 'append_content')
+ else:
+ robj.create_reply(body_text)
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 701238e1..2526c4b7 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -1503,18 +1503,18 @@ def user_edit_post(self,
@auto_now_timestamp
def user_edit_question(
- self,
- question = None,
- title = None,
- body_text = None,
- revision_comment = None,
- tags = None,
- wiki = False,
- edit_anonymously = False,
- timestamp = None,
- force = False,#if True - bypass the assert
- by_email = False
- ):
+ self,
+ question = None,
+ title = None,
+ body_text = None,
+ revision_comment = None,
+ tags = None,
+ wiki = False,
+ edit_anonymously = False,
+ timestamp = None,
+ force = False,#if True - bypass the assert
+ by_email = False
+ ):
if force == False:
self.assert_can_edit_question(question)
diff --git a/askbot/models/reply_by_email.py b/askbot/models/reply_by_email.py
index 4981765f..bcd82645 100644
--- a/askbot/models/reply_by_email.py
+++ b/askbot/models/reply_by_email.py
@@ -36,6 +36,8 @@ class ReplyAddressManager(BaseQuerySetManager):
REPLY_ACTION_CHOICES = (
('post_answer', _('Post an answer')),
('post_comment', _('Post a comment')),
+ ('replace_content', _('Edit post')),
+ ('append_content', _('Append to post')),
('auto_answer_or_comment', _('Answer or comment, depending on the size of post')),
('validate_email', _('Validate email and record signature')),
)
@@ -83,22 +85,41 @@ class ReplyAddress(models.Model):
askbot_settings.REPLY_BY_EMAIL_HOSTNAME
)
- def edit_post(self, body_text, stored_files):
+ def edit_post(
+ self, body_text, title = None, reply_action = None
+ ):
"""edits the created post upon repeated response
to the same address"""
- assert self.was_used == True
- self.user.edit_post(
- post = self.response_post,
- body_text = stored_files,
- revision_comment = _('edited by email'),
- by_email = True
- )
+ reply_action = reply_action or self.reply_action
+
+ if reply_action == 'append_content':
+ body_text = self.post.text + '\n\n' + body_text
+ revision_comment = _('added content by email')
+ else:
+ revision_comment = _('edited by email')
+
+ if self.post.post_type == 'question':
+ self.user.edit_question(
+ question = self.post,
+ body_text = body_text,
+ title = title,
+ revision_comment = revision_comment,
+ by_email = True
+ )
+ else:
+ self.user.edit_post(
+ post = self.response_post,
+ body_text = body_text,
+ revision_comment = revision_comment,
+ by_email = True
+ )
self.response_post.thread.invalidate_cached_data()
- def create_reply(self, body_text, stored_files):
+ def create_reply(self, body_text):
"""creates a reply to the post which was emailed
to the user
"""
+ assert(self.was_used == False)
result = None
if self.post.post_type == 'answer':
result = self.user.post_comment(
diff --git a/askbot/tests/reply_by_email_tests.py b/askbot/tests/reply_by_email_tests.py
index 177deebd..698662fc 100644
--- a/askbot/tests/reply_by_email_tests.py
+++ b/askbot/tests/reply_by_email_tests.py
@@ -101,7 +101,7 @@ class ReplyAddressModelTests(AskbotTestCase):
post = self.answer,
user = self.u1
)
- post = result.create_reply(TEST_CONTENT, [])
+ post = result.create_reply(TEST_CONTENT)
self.assertEquals(post.post_type, "comment")
self.assertEquals(post.text, TEST_CONTENT)
self.assertEquals(self.answer.comments.count(), 2)
@@ -111,7 +111,7 @@ class ReplyAddressModelTests(AskbotTestCase):
post = self.comment,
user = self.u1
)
- post = result.create_reply(TEST_CONTENT, [])
+ post = result.create_reply(TEST_CONTENT)
self.assertEquals(post.post_type, "comment")
self.assertEquals(post.text, TEST_CONTENT)
self.assertEquals(self.answer.comments.count(), 2)
@@ -122,7 +122,7 @@ class ReplyAddressModelTests(AskbotTestCase):
post = self.question,
user = self.u3
)
- post = result.create_reply(TEST_CONTENT, [])
+ post = result.create_reply(TEST_CONTENT)
self.assertEquals(post.post_type, "comment")
self.assertEquals(post.text, TEST_CONTENT)
@@ -131,7 +131,7 @@ class ReplyAddressModelTests(AskbotTestCase):
post = self.question,
user = self.u3
)
- post = result.create_reply(TEST_LONG_CONTENT, [])
+ post = result.create_reply(TEST_LONG_CONTENT)
self.assertEquals(post.post_type, "answer")
self.assertEquals(post.text, TEST_LONG_CONTENT)