Permalink
Browse files

Convert search subscriptions to use new notify command.

  • Loading branch information...
onyxfish committed May 30, 2012
1 parent e92745f commit e5522a84df4204678f3d78370059760d8a823ebc
@@ -1,15 +1,13 @@
#!/usr/bin/env python
import logging
-from urllib import unquote
from celery.task import Task
from django.conf import settings
from django.utils.timezone import now
-from livesettings import config_value
from panda import solr
-from panda.utils.mail import send_mail
+from panda.utils.notifications import notify
class RunSubscriptionsTask(Task):
"""
@@ -45,33 +43,18 @@ def run(self, *args, **kwargs):
# TODO
pass
- self.send_notification(sub, count)
+ notify(
+ sub.user,
+ 'subscription_results',
+ 'info',
+ related_task=None,
+ related_dataset=sub.dataset,
+ related_export=None,
+ extra_context={
+ 'query': sub.query,
+ 'count': count
+ }
+ )
log.info('Finished running subscribed searches')
- def send_notification(self, sub, count):
- """
- Send a user a notification of new results.
- """
- from panda.models import Notification
-
- dataset_name = unquote(sub.dataset.name)
-
- email_subject = 'New search results for "%s" in %s' % sub.query, dataset_name
- # TODO: links
- email_message = 'See just the new results:\n\nhttp://%s/#dataset/%s/%s\n\nSee all results for your search:\n\nhttp://%s/#dataset/%s/%s' % (config_value('DOMAIN', 'SITE_DOMAIN'), sub.dataset.slug, sub.query, config_value('DOMAIN', 'SITE_DOMAIN'), sub.dataset.slug, sub.query)
- notification_message = 'New search results for: <strong>%s</strong>' % sub.query
-
- notification_type = 'Info'
-
- Notification.objects.create(
- recipient=sub.user,
- related_task=None,
- related_dataset=sub.dataset,
- related_export=None,
- message=notification_message,
- type=notification_type
- )
-
- send_mail(email_subject, email_message, [sub.user.username])
-
@@ -0,0 +1,7 @@
+New search results for "{{ query }}" in {{ related_dataset.name }}'
+
+See just the new results:
+TODO
+
+See all results for your search query:
+http://{{ site_domain }}/#dataset/{{ related_dataset.slug }}/{{ query }}
@@ -0,0 +1 @@
+New search results for "{{ query }}" in {{ related_dataset.name }}'
@@ -0,0 +1 @@
+New search results for: "{{ query }}"
@@ -38,6 +38,6 @@ def test_subscription_datasets(self):
self.assertNotEqual(last_run, sub.last_run)
- self.assertEqual(Notification.objects.filter(recipient=sub.user).count(), 1)
- self.assertEqual(Notification.objects.filter(related_dataset=sub.dataset).count(), 1)
+ self.assertEqual(Notification.objects.filter(recipient=sub.user).count(), 2)
+ self.assertEqual(Notification.objects.filter(related_dataset=sub.dataset).count(), 2)

0 comments on commit e5522a8

Please sign in to comment.