--- /dev/null
+# -*- 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),
+ ]
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.
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
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
# 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:
# 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
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
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'
--- /dev/null
+# -*- 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)