kopia lustrzana https://github.com/wagtail/wagtail
				
				
				
			send individual notification emails per user
							rodzic
							
								
									4433d4f3c0
								
							
						
					
					
						commit
						e18f877286
					
				| 
						 | 
				
			
			@ -14,6 +14,7 @@ Changelog
 | 
			
		|||
 * `wagtailadmin.utils.send_mail` now passes extra keyword arguments to Django's `send_mail` function (Matthew Downey)
 | 
			
		||||
 * `page_unpublish` signal is now fired for each page that was unpublished by a call to `PageQuerySet.unpublish()`
 | 
			
		||||
 * Add `get_upload_to` method to `AbstractImage`, to allow overriding the default image upload path (Ben Emery)
 | 
			
		||||
 * Notification emails are now sent per user (Matthew Downey)
 | 
			
		||||
 * New translations for Arabic and Latvian
 | 
			
		||||
 * Fix: HTTP cache purge now works again on Python 2 (Mitchel Cabuloy)
 | 
			
		||||
 * Fix: Locked pages can no longer be unpublished (Alex Bridge)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,6 +28,7 @@ Minor features
 | 
			
		|||
 * ``wagtailadmin.utils.send_mail`` now passes extra keyword arguments to Django's ``send_mail`` function (Matthew Downey)
 | 
			
		||||
 * ``page_unpublish`` signal is now fired for each page that was unpublished by a call to ``PageQuerySet.unpublish()``
 | 
			
		||||
 * Add `get_upload_to` method to `AbstractImage`, to allow overriding the default image upload path (Ben Emery)
 | 
			
		||||
 * Notification emails are now sent per user (Matthew Downey)
 | 
			
		||||
 * New translations for Arabic and Latvian
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,11 @@
 | 
			
		|||
{% extends 'wagtailadmin/notifications/base_notification.html' %}{% block notification %}{% load i18n %}{% blocktrans with title=revision.page.title|safe %}The page "{{ title }}" has been approved{% endblocktrans %}
 | 
			
		||||
{% extends 'wagtailadmin/notifications/base_notification.html' %}
 | 
			
		||||
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
 | 
			
		||||
{% block subject %}{% blocktrans with title=revision.page.title|safe %}The page "{{ title }}" has been approved{% endblocktrans %}{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block notification %}
 | 
			
		||||
{% blocktrans with title=revision.page.title|safe %}The page "{{ title }}" has been approved.{% endblocktrans %}
 | 
			
		||||
 | 
			
		||||
{% trans "You can view the page here:" %} {{ revision.page.full_url }}{% endblock %}
 | 
			
		||||
{% trans "You can view the page here:" %} {{ revision.page.full_url }}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,4 @@
 | 
			
		|||
{% load i18n %}{% block notification %}{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% load i18n %}{% block subject %}{% endblock %}
 | 
			
		||||
{% block greeting %}{% trans "Hello" %} {{ user.get_short_name }},{% endblock %}
 | 
			
		||||
{% block notification %}{% endblock %}
 | 
			
		||||
{% trans "Edit your notification preferences here:" %} {{ settings.BASE_URL }}{% url 'wagtailadmin_account_notification_preferences' %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,11 @@
 | 
			
		|||
{% extends 'wagtailadmin/notifications/base_notification.html' %}{% block notification %}{% load i18n %}{% blocktrans with title=revision.page.title|safe %}The page "{{ title }}" has been rejected{% endblocktrans %}
 | 
			
		||||
{% extends 'wagtailadmin/notifications/base_notification.html' %}
 | 
			
		||||
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
 | 
			
		||||
{% block subject %}{% blocktrans with title=revision.page.title|safe %}The page "{{ title }}" has been rejected{% endblocktrans %}{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block notification %}
 | 
			
		||||
{% blocktrans with title=revision.page.title|safe %}The page "{{ title }}" has been rejected.{% endblocktrans %}
 | 
			
		||||
 | 
			
		||||
{% trans "You can edit the page here:"%} {{ settings.BASE_URL }}{% url 'wagtailadmin_pages:edit' revision.page.id %}{% endblock %}
 | 
			
		||||
{% trans "You can edit the page here:"%} {{ settings.BASE_URL }}{% url 'wagtailadmin_pages:edit' revision.page.id %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,12 @@
 | 
			
		|||
{% extends 'wagtailadmin/notifications/base_notification.html' %}{% block notification %}{% load i18n %}{% blocktrans with page=revision.page|safe %}The page "{{ page }}" has been submitted for moderation{% endblocktrans %}
 | 
			
		||||
{% extends 'wagtailadmin/notifications/base_notification.html' %}
 | 
			
		||||
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
 | 
			
		||||
{% block subject %}{% blocktrans with page=revision.page|safe %}The page "{{ page }}" has been submitted for moderation{% endblocktrans %}{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block notification %}
 | 
			
		||||
{% blocktrans with page=revision.page|safe %}The page "{{ page }}" has been submitted for moderation.{% endblocktrans %}
 | 
			
		||||
 | 
			
		||||
{% trans "You can preview the page here:" %} {{ settings.BASE_URL }}{% url 'wagtailadmin_pages:preview_for_moderation' revision.id %}
 | 
			
		||||
{% trans "You can edit the page here:" %} {{ settings.BASE_URL }}{% url 'wagtailadmin_pages:edit' revision.page.id %}{% endblock %}
 | 
			
		||||
{% trans "You can edit the page here:" %} {{ settings.BASE_URL }}{% url 'wagtailadmin_pages:edit' revision.page.id %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2224,10 +2224,12 @@ class TestNotificationPreferences(TestCase, WagtailTestUtils):
 | 
			
		|||
        self.submit()
 | 
			
		||||
 | 
			
		||||
        # Check that both the moderators got an email, and no others
 | 
			
		||||
        self.assertEqual(len(mail.outbox), 1)
 | 
			
		||||
        self.assertIn(self.moderator.email, mail.outbox[0].to)
 | 
			
		||||
        self.assertIn(self.moderator2.email, mail.outbox[0].to)
 | 
			
		||||
        self.assertEqual(len(mail.outbox[0].to), 2)
 | 
			
		||||
        self.assertEqual(len(mail.outbox), 2)
 | 
			
		||||
        email_to = mail.outbox[0].to + mail.outbox[1].to
 | 
			
		||||
        self.assertIn(self.moderator.email, email_to)
 | 
			
		||||
        self.assertIn(self.moderator2.email, email_to)
 | 
			
		||||
        self.assertEqual(len(mail.outbox[0].to), 1)
 | 
			
		||||
        self.assertEqual(len(mail.outbox[1].to), 1)
 | 
			
		||||
 | 
			
		||||
    def test_submit_notification_preferences_respected(self):
 | 
			
		||||
        # moderator2 doesn't want emails
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -153,8 +153,8 @@ def send_notification(page_revision_id, notification, excluded_user_id):
 | 
			
		|||
        return
 | 
			
		||||
 | 
			
		||||
    # Get list of email addresses
 | 
			
		||||
    email_addresses = [
 | 
			
		||||
        recipient.email for recipient in recipients
 | 
			
		||||
    email_recipients = [
 | 
			
		||||
        recipient for recipient in recipients
 | 
			
		||||
        if recipient.email and recipient.id != excluded_user_id and getattr(
 | 
			
		||||
            UserProfile.get_for_user(recipient),
 | 
			
		||||
            notification + '_notifications'
 | 
			
		||||
| 
						 | 
				
			
			@ -162,14 +162,25 @@ def send_notification(page_revision_id, notification, excluded_user_id):
 | 
			
		|||
    ]
 | 
			
		||||
 | 
			
		||||
    # Return if there are no email addresses
 | 
			
		||||
    if not email_addresses:
 | 
			
		||||
    if not email_recipients:
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
    # Get email subject and content
 | 
			
		||||
    # Get template
 | 
			
		||||
    template = 'wagtailadmin/notifications/' + notification + '.html'
 | 
			
		||||
    rendered_template = render_to_string(template, dict(revision=revision, settings=settings)).split('\n')
 | 
			
		||||
    email_subject = rendered_template[0]
 | 
			
		||||
    email_content = '\n'.join(rendered_template[1:])
 | 
			
		||||
 | 
			
		||||
    # Send email
 | 
			
		||||
    send_mail(email_subject, email_content, email_addresses)
 | 
			
		||||
    # Common context to template
 | 
			
		||||
    context = {
 | 
			
		||||
        "revision": revision,
 | 
			
		||||
        "settings": settings,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    # Send emails
 | 
			
		||||
    for recipient in email_recipients:
 | 
			
		||||
        # update context with this recipient
 | 
			
		||||
        context["user"] = recipient
 | 
			
		||||
 | 
			
		||||
        # Get email subject and content
 | 
			
		||||
        email_subject, email_content = render_to_string(template, context).split('\n', 1)
 | 
			
		||||
 | 
			
		||||
        # Send email
 | 
			
		||||
        send_mail(email_subject, email_content, [recipient.email])
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue