From fbd092d96ce775bfa444162f78e05ad44672a601 Mon Sep 17 00:00:00 2001 From: Patrick Samson Date: Thu, 16 Jan 2014 21:59:30 +0100 Subject: [PATCH] Added a setting: POSTMAN_QUICKREPLY_QUOTE_BODY --- docs/api.rst | 3 +++ docs/conf.py | 4 ++-- docs/quickstart.rst | 9 +++++++++ docs/views.rst | 4 ++++ postman/__init__.py | 4 ++-- postman/models.py | 10 +++++----- postman/tests.py | 32 +++++++++++++++++++++++++++----- postman/views.py | 2 +- 8 files changed, 53 insertions(+), 15 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 7027ff8..cc2864b 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,6 +4,9 @@ API For an easier usage of the application from other applications in the project, an API is provided. +Note: The "sites" framework is optional but you need it if you want the ``site`` context variable +to provide a *Site* instance (not *None*) in the notification templates. + pm_broadcast() -------------- Broadcast a message to multiple Users. diff --git a/docs/conf.py b/docs/conf.py index 0a3aff1..4e6295f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -45,9 +45,9 @@ copyright = u'2010, Patrick Samson' # built documents. # # The short X.Y version. -version = '3.0' +version = '3.2' # The full version, including alpha/beta/rc tags. -release = '3.1.0' +release = '3.2.0a1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/quickstart.rst b/docs/quickstart.rst index a5a0c5e..eea5a0e 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -110,6 +110,14 @@ You may specify some additional configuration options in your :file:`settings.py (misspelled attribute name, empty result, ...), or the value is a function and an exception is raised (but any result, even empty, is valid). +``POSTMAN_QUICKREPLY_QUOTE_BODY`` + *New in version 3.2.0.* + + Set it to True if you want the original message to be quoted when replying directly from the display view. + This setting does not apply to the reply view in which quote is the basic behaviour. + + *Defaults to*: False. + ``POSTMAN_NOTIFIER_APP`` A notifier application name, used in preference to the basic emailing, to notify users of their rejected or received messages. @@ -230,6 +238,7 @@ Examples # POSTMAN_DISABLE_USER_EMAILING = True # default is False # POSTMAN_AUTO_MODERATE_AS = True # default is None # POSTMAN_SHOW_USER_AS = 'get_full_name' # default is None + # POSTMAN_QUICKREPLY_QUOTE_BODY = True # default is False # POSTMAN_NOTIFIER_APP = None # default is 'notification' # POSTMAN_MAILER_APP = None # default is 'mailer' # POSTMAN_AUTOCOMPLETER_APP = { diff --git a/docs/views.rst b/docs/views.rst index 5364199..05772f5 100644 --- a/docs/views.rst +++ b/docs/views.rst @@ -109,3 +109,7 @@ Examples:: name='postman_view'), # ... ) + +See also: + +* the ``POSTMAN_QUICKREPLY_QUOTE_BODY`` setting in :ref:`optional_settings` diff --git a/postman/__init__.py b/postman/__init__.py index 087d630..094a254 100644 --- a/postman/__init__.py +++ b/postman/__init__.py @@ -4,8 +4,8 @@ A messaging application for Django from __future__ import unicode_literals # following PEP 386: N.N[.N]+[{a|b|c|rc}N[.N]+][.postN][.devN] -VERSION = (3, 1, 0) -PREREL = () +VERSION = (3, 2, 0) +PREREL = ('a', 1) POST = 0 DEV = 0 diff --git a/postman/models.py b/postman/models.py index 6b3fc48..eb58dcb 100644 --- a/postman/models.py +++ b/postman/models.py @@ -359,12 +359,12 @@ class Message(models.Model): """Return the number of accepted responses.""" return self.next_messages.filter(moderation_status=STATUS_ACCEPTED).count() - def quote(self, format_subject, format_body): + def quote(self, format_subject, format_body=None): """Return a dictionary of quote values to initiate a reply.""" - return { - 'subject': format_subject(self.subject)[:self.SUBJECT_MAX_LENGTH], - 'body': format_body(self.obfuscated_sender, self.body), - } + values = {'subject': format_subject(self.subject)[:self.SUBJECT_MAX_LENGTH]} + if format_body: + values['body'] = format_body(self.obfuscated_sender, self.body) + return values def clean(self): """Check some validity constraints.""" diff --git a/postman/tests.py b/postman/tests.py index 5cfc744..75f3666 100644 --- a/postman/tests.py +++ b/postman/tests.py @@ -79,7 +79,7 @@ class GenericTest(TestCase): Usual generic tests. """ def test_version(self): - self.assertEqual(sys.modules['postman'].__version__, "3.1.0") + self.assertEqual(sys.modules['postman'].__version__, "3.2.0a1") class BaseTest(TestCase): @@ -97,7 +97,9 @@ class BaseTest(TestCase): 'POSTMAN_DISALLOW_COPIES_ON_REPLY', 'POSTMAN_DISABLE_USER_EMAILING', 'POSTMAN_AUTO_MODERATE_AS', + 'POSTMAN_NOTIFIER_APP', 'POSTMAN_SHOW_USER_AS', + 'POSTMAN_QUICKREPLY_QUOTE_BODY', ): if hasattr(settings, a): delattr(settings, a) @@ -477,6 +479,12 @@ class ViewTest(BaseTest): self.assertContains(response, '\n\nbar wrote:\n> this is my body\n') self.assertEqual(response.context['recipient'], 'bar') + settings.POSTMAN_QUICKREPLY_QUOTE_BODY = True # no influence here, acts only for Quick Reply + self.reload_modules() + response = self.client.get(url) + self.assertContains(response, 'value="Re: s"') + self.assertContains(response, '\n\nbar wrote:\n> this is my body\n') + def test_reply_formatters(self): "Test the 'formatters' parameter." template = "postman/reply.html" @@ -486,7 +494,7 @@ class ViewTest(BaseTest): response = self.client.get(url) self.assertTemplateUsed(response, template) self.assertContains(response, 'value="Re_ s"') - self.assertContains(response, 'bar _ this is my body') + self.assertContains(response, 'bar _ this is my body') # POSTMAN_QUICKREPLY_QUOTE_BODY setting is not involved def test_reply_auto_complete(self): "Test the 'autocomplete_channel' parameter." @@ -629,7 +637,7 @@ class ViewTest(BaseTest): "Test permission, what template and form are used, set-as-read." template = "postman/view.html" pk1 = self.c12().pk - pk2 = self.c21().pk + pk2 = self.c21(body="this is my body").pk url = reverse('postman_view', args=[pk1]) # anonymous response = self.client.get(url) @@ -649,8 +657,15 @@ class ViewTest(BaseTest): self.assertEqual(response.context['reply_to_pk'], pk2) from postman.forms import QuickReplyForm self.assertTrue(isinstance(response.context['form'], QuickReplyForm)) + self.assertNotContains(response, 'value="Re: s"') + self.assertContains(response, '>\r\n') # as in django\forms\widgets.py\Textarea self.check_status(Message.objects.get(pk=pk2), status=STATUS_ACCEPTED, is_new=False) + settings.POSTMAN_QUICKREPLY_QUOTE_BODY = True + self.reload_modules() + response = self.client.get(url) + self.assertContains(response, '\n\nbar wrote:\n> this is my body\n') + def test_view_formatters(self): "Test the 'formatters' parameter." template = "postman/view.html" @@ -660,7 +675,7 @@ class ViewTest(BaseTest): response = self.client.get(url) self.assertTemplateUsed(response, template) self.assertNotContains(response, 'value="Re_ s"') - self.assertContains(response, 'bar _ this is my body') + self.assertContains(response, 'bar _ this is my body') # POSTMAN_QUICKREPLY_QUOTE_BODY setting is not involved def check_view_404(self, pk): self.check_404('postman_view', pk) @@ -680,7 +695,7 @@ class ViewTest(BaseTest): template = "postman/view.html" m1 = self.c12() m1.read_at, m1.thread = now(), m1 - m2 = self.c21(parent=m1, thread=m1.thread) + m2 = self.c21(parent=m1, thread=m1.thread, body="this is my body") m1.replied_at = m2.sent_at; m1.save() url = reverse('postman_view_conversation', args=[m1.pk]) self.check_status(Message.objects.get(pk=m1.pk), status=STATUS_ACCEPTED, is_new=False, is_replied=True, thread=m1) @@ -695,9 +710,16 @@ class ViewTest(BaseTest): self.assertEqual(response.context['reply_to_pk'], m2.pk) from postman.forms import QuickReplyForm self.assertTrue(isinstance(response.context['form'], QuickReplyForm)) + self.assertNotContains(response, 'value="Re: s"') + self.assertContains(response, '>\r\n') # as in django\forms\widgets.py\Textarea self.assertEqual(len(response.context['pm_messages']), 2) self.check_status(Message.objects.get(pk=m2.pk), status=STATUS_ACCEPTED, is_new=False, parent=m1, thread=m1) + settings.POSTMAN_QUICKREPLY_QUOTE_BODY = True + self.reload_modules() + response = self.client.get(url) + self.assertContains(response, '\n\nbar wrote:\n> this is my body\n') + def check_view_conversation_404(self, thread_id): self.check_404('postman_view_conversation', thread_id) diff --git a/postman/views.py b/postman/views.py index 8d3a1b9..2d49381 100644 --- a/postman/views.py +++ b/postman/views.py @@ -306,7 +306,7 @@ class DisplayMixin(object): """ http_method_names = ['get'] form_class = QuickReplyForm - formatters = (format_subject, format_body) + formatters = (format_subject, format_body if getattr(settings, 'POSTMAN_QUICKREPLY_QUOTE_BODY', False) else None) template_name = 'postman/view.html' @login_required_m -- 2.39.5