diff --git a/ietf/community/display.py b/ietf/community/display.py index 4bd5373af..ec4686c19 100644 --- a/ietf/community/display.py +++ b/ietf/community/display.py @@ -35,7 +35,7 @@ class DateField(DisplayField): def get_value(self, document): dates = document.documentchangedates_set.all() if dates and dates[0].new_version_date: - return dates[0].new_version_date + return dates[0].new_version_date.strftime('%Y-%m-%d') return document.time.strftime('%Y-%m-%d') diff --git a/ietf/community/models.py b/ietf/community/models.py index 8706c3715..9c8a09799 100644 --- a/ietf/community/models.py +++ b/ietf/community/models.py @@ -1,8 +1,10 @@ +from django.conf import settings from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.db import models -from django.db.models import signals +from django.db.models import signals, Q +from ietf.utils.mail import send_mail from redesign.doc.models import Document from redesign.group.models import Group, Role @@ -161,6 +163,21 @@ class ListNotification(models.Model): desc = models.TextField() significant = models.BooleanField(default=False) + def notify_by_email(self): + clists = CommunityList.objects.filter( + Q(added_ids=self.document) | Q(rule__cached_ids=self.document)).distinct() + from_email = settings.DEFAULT_FROM_EMAIL + for l in clists: + subject = '%s notification: Changes on %s' % (l.long_name(), self.document.name) + context = {'notification': self, + 'clist': l} + to_email = '' + filter_subscription = {'community_list': l} + if not self.significant: + filter_subscription['significant'] = False + bcc = ','.join(list(set([i.email for i in EmailSubscription.objects.filter(**filter_subscription)]))) + send_mail(None, to_email, from_email, subject, 'community/public/notification_email.txt', context, bcc=bcc) + def save(self, *args, **kwargs): super(ListNotification, self).save(*args, **kwargs) (changes, created) = DocumentChangeDates.objects.get_or_create(document=self.document) @@ -170,6 +187,7 @@ class ListNotification(models.Model): else: changes.normal_change_date = self.notification_date changes.save() + self.notify_by_email() def save_previous_states(sender, instance, **kwargs): diff --git a/ietf/community/rules.py b/ietf/community/rules.py index 822367a1c..33205554b 100644 --- a/ietf/community/rules.py +++ b/ietf/community/rules.py @@ -62,21 +62,34 @@ class ReferenceToRFCRule(RuleManager): codename = 'reference_to_rfc' description = 'All I-Ds that have a reference to a particular RFC' + def get_documents(self): + return Document.objects.filter(Q(type__name='Draft') | Q(state__name='rfc')).filter(relateddocument__target__document__state__name='rfc', relateddocument__target__document__name__icontains=self.value).distinct() + class ReferenceToIDRule(RuleManager): codename = 'reference_to_id' description = 'All I-Ds that have a reference to a particular I-D' + def get_documents(self): + return Document.objects.filter(Q(type__name='Draft') | Q(state__name='rfc')).filter(relateddocument__target__document__type__name='Draft', relateddocument__target__document__name__icontains=self.value).distinct() + class ReferenceFromRFCRule(RuleManager): codename = 'reference_from_rfc' description = 'All I-Ds that are referenced by a particular RFC' + def get_documents(self): + return Document.objects.filter(Q(type__name='Draft') | Q(state__name='rfc')).filter(relateddocument__source__state__name='rfc', relateddocument__source__name__icontains=self.value).distinct() + + class ReferenceFromIDRule(RuleManager): codename = 'reference_from_id' description = 'All I-Ds that are referenced by a particular I-D' + def get_documents(self): + return Document.objects.filter(Q(type__name='Draft') | Q(state__name='rfc')).filter(relateddocument__source__type__name='Draft', relateddocument__source__name__icontains=self.value).distinct() + class WithTextRule(RuleManager): codename = 'with_text' diff --git a/ietf/templates/community/public/notification_email.txt b/ietf/templates/community/public/notification_email.txt new file mode 100644 index 000000000..196405c90 --- /dev/null +++ b/ietf/templates/community/public/notification_email.txt @@ -0,0 +1,15 @@ +{% autoescape off %} +Hello, + +This is a notification from {{ clist.long_name }}. + +Document: {{ notification.document }} + +Change: +{{ notification.desc }} + +Best regards, + + The datatracker login manager service + (for the IETF Secretariat) +{% endautoescape %} diff --git a/ietf/templates/community/public/subscribe_email.txt b/ietf/templates/community/public/subscribe_email.txt index bc18e58f0..8618dcaf4 100644 --- a/ietf/templates/community/public/subscribe_email.txt +++ b/ietf/templates/community/public/subscribe_email.txt @@ -1,9 +1,12 @@ +{% autoescape off %} Hello, In order to complete your subscription for {% if significant %}significant {% endif %}changes on {{ clist.long_name }}, please follow this link or copy it and paste it in your web browser: http://{{ domain }}{% if significant %}{% url confirm_significant_subscription clist.id to_email today auth %}{% else %}{% url confirm_subscription clist.id to_email today auth %}{% endif %} -Best, +Best regards, -Your {{ domain }} team. + The datatracker login manager service + (for the IETF Secretariat) +{% endautoescape %} diff --git a/ietf/templates/community/public/unsubscribe_email.txt b/ietf/templates/community/public/unsubscribe_email.txt index b7e62b8c3..e0711a847 100644 --- a/ietf/templates/community/public/unsubscribe_email.txt +++ b/ietf/templates/community/public/unsubscribe_email.txt @@ -1,9 +1,12 @@ +{% autoescape off %} Hello, In order to complete the cancelation of your subscription to {% if significant %}significant {% endif %}changes on {{ clist.long_name }}, please follow this link or copy it and paste it in your web browser: http://{{ domain }}{% if significant %}{% url confirm_significant_unsubscription clist.id to_email today auth %}{% else %}{% url confirm_unsubscription clist.id to_email today auth %}{% endif %} -Best, +Best regards, -Your {{ domain }} team. + The datatracker login manager service + (for the IETF Secretariat) +{% endautoescape %}