From: Jan Szejko Date: Fri, 20 Jan 2017 11:27:24 +0000 (+0100) Subject: notification for new publications X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/f1c6ff102206aa2b0903d61eb648691d5e2e028c?ds=sidebyside;hp=0b3783ec46a66fc06e1fd0323303146dac4cd620 notification for new publications --- diff --git a/apps/catalogue/migrations/0011_document_published.py b/apps/catalogue/migrations/0011_document_published.py new file mode 100644 index 00000000..c2246f6c --- /dev/null +++ b/apps/catalogue/migrations/0011_document_published.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +def set_published(apps, schema_editor): + Document = apps.get_model('catalogue', 'Document') + Document.objects.exclude(publish_log=None).update(published=True) + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0010_auto_20170119_1321'), + ] + + operations = [ + migrations.AddField( + model_name='document', + name='published', + field=models.BooleanField(default=False), + ), + migrations.RunPython(set_published), + ] diff --git a/apps/catalogue/models/document.py b/apps/catalogue/models/document.py index 38c21100..4f084804 100755 --- a/apps/catalogue/models/document.py +++ b/apps/catalogue/models/document.py @@ -26,6 +26,8 @@ class Document(Ref): assigned_to = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, related_name='assignments') deleted = models.BooleanField(default=False) tags = models.ManyToManyField(Tag, blank=True) + # we need to know if it were ever published (for notifications) + published = models.BooleanField(default=False) # Where to cache searchable stuff from metadata? # Probably in some kind of search index. diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index bde9dc00..658b3d4c 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -13,6 +13,7 @@ from django.conf import settings from django.contrib import auth from django.contrib.auth.models import User from django.contrib.auth.decorators import login_required +from django.contrib.sites.models import Site from django.core.urlresolvers import reverse from django import http from django.http import Http404, HttpResponse @@ -24,6 +25,7 @@ from django.views.decorators.http import require_POST from catalogue import forms from catalogue.helpers import active_tab from librarian import BuildError +from redakcja.utlis import send_notify_email from .constants import STAGES from .models import Document, Plan from dvcs.models import Revision @@ -404,7 +406,17 @@ def publish(request, pk): # FIXME: check if in tree # if PublishRecord.objects.filter(revision=rev, document=doc).exists(): # return http.HttpResponse('exists') + if not doc.published: + site = Site.objects.get_current() + send_notify_email( + 'New published document in MIL/PEER', + '''New published document in MIL/PEER: %s. View it in browser: https://%s%s. + +-- +MIL/PEER team.''' % (doc.meta()['title'], site.domain, reverse('catalogue_html', args=[doc.pk]))) PublishRecord.objects.create(revision=rev, document=doc, user=request.user) + doc.published = True + doc.save() if request.is_ajax(): return http.HttpResponse('ok') else: diff --git a/apps/organizations/forms.py b/apps/organizations/forms.py index 298da489..55807663 100644 --- a/apps/organizations/forms.py +++ b/apps/organizations/forms.py @@ -4,10 +4,9 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django import forms -from constance import config from django.contrib.sites.models import Site -from django.core.mail import send_mail +from redakcja.utlis import send_notify_email from .models import Organization, UserCard, countries @@ -21,13 +20,12 @@ class OrganizationForm(forms.ModelForm): def save(self, commit=True): organization = super(OrganizationForm, self).save(commit=commit) site = Site.objects.get_current() - send_mail( + send_notify_email( 'New organization in MIL/PEER', '''New organization in MIL/PEER: %s. View their profile: https://%s%s. -- -MIL/PEER team.''' % (organization.name, site.domain, organization.get_absolute_url()), - 'milpeer@mdrn.pl', [config.NOTIFY_EMAIL]) +MIL/PEER team.''' % (organization.name, site.domain, organization.get_absolute_url())) return organization diff --git a/redakcja/settings/__init__.py b/redakcja/settings/__init__.py index 68a2c2f5..39823f5d 100644 --- a/redakcja/settings/__init__.py +++ b/redakcja/settings/__init__.py @@ -20,7 +20,8 @@ DATABASES = { CONSTANCE_CONFIG = { 'NOTIFY_EMAIL': ('zofia.radziwill@nowoczesnapolska.org.pl', - 'e-mail address for notifications about new organizations and published projects'), + 'e-mail addresses (separated with semicolons) to be notified about new organizations ' + 'and published documents'), } CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend' diff --git a/redakcja/utlis.py b/redakcja/utlis.py new file mode 100644 index 00000000..806d106e --- /dev/null +++ b/redakcja/utlis.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# +# This file is part of MIL/PEER, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from constance import config +from django.core.mail import send_mail + + +def send_notify_email(subject, content): + addresses = [part.strip() for part in config.NOTIFY_EMAIL.split(';') if '@' in part] + send_mail(subject, content, 'milpeer@mdrn.pl', addresses)