]> git.openstreetmap.org Git - osqa.git/commitdiff
make RSS items decoratable, add an option to block email notifications per node,...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sun, 8 Apr 2012 00:25:31 +0000 (00:25 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sun, 8 Apr 2012 00:25:31 +0000 (00:25 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1246 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/feed.py
forum/models/node.py
forum/subscriptions.py

index 60c2d3fe0ab3bf32a26d663e1039580f4dba7c0c..c52e64bf8214b3df9b299cfa8b1d31c50cbf6c88 100644 (file)
@@ -78,8 +78,11 @@ class RssQuestionFeed(BaseNodeFeed):
     def item_categories(self, item):
         return item.tagname_list()  
 
     def item_categories(self, item):
         return item.tagname_list()  
 
+    def _items(self):
+       return self._question_list
+
     def items(self):
     def items(self):
-       return self._question_list[:30]
+        return self._items()[:30]
 
 class RssAnswerFeed(BaseNodeFeed):
     if old_version:
 
 class RssAnswerFeed(BaseNodeFeed):
     if old_version:
@@ -94,13 +97,16 @@ class RssAnswerFeed(BaseNodeFeed):
         self._question = question
         self._include_comments = include_comments
 
         self._question = question
         self._include_comments = include_comments
 
-    def items(self):
+    def _items(self):
         if self._include_comments:
             qs = self._question.all_children
         else:
             qs = self._question.answers
 
         if self._include_comments:
             qs = self._question.all_children
         else:
             qs = self._question.answers
 
-        return qs.filter_state(deleted=False).order_by('-added_at')[:30]
+        return qs.filter_state(deleted=False).order_by('-added_at')
+
+    def items(self):
+        return self._items()[:30]
 
     def item_title(self, item):
         if item.node_type == "answer":
 
     def item_title(self, item):
         if item.node_type == "answer":
index 83b9ab72b3096d9ca867b8dbe168b538b0bdb006..387f8870b8525df3aca59e1b7319f0ff10b36ee9 100644 (file)
@@ -330,6 +330,14 @@ class Node(BaseModel, NodeContent):
 
         return content
 
 
         return content
 
+    # Can be used to block subscription notifications for a specific node from a module
+    def _is_notifiable(self):
+        return True
+
+    @property
+    def is_notifiable(self):
+        return self._is_notifiable()
+
     @models.permalink
     def get_revisions_url(self):
         return ('revisions', (), {'id': self.id})
     @models.permalink
     def get_revisions_url(self):
         return ('revisions', (), {'id': self.id})
index 24479b74ced3819747c45eab84f0a00abefbc798..fad24a5c95fa3a16e38548263f8407e0e39c3e1f 100644 (file)
@@ -12,9 +12,17 @@ from django.db.models import Q, F
 def create_subscription_if_not_exists(question, user):
     try:
         subscription = QuestionSubscription.objects.get(question=question, user=user)
 def create_subscription_if_not_exists(question, user):
     try:
         subscription = QuestionSubscription.objects.get(question=question, user=user)
-    except:
+        return subscription
+    except QuestionSubscription.MultipleObjectsReturned:
+        pass
+    except QuestionSubscription.DoesNotExist:
         subscription = QuestionSubscription(question=question, user=user)
         subscription.save()
         subscription = QuestionSubscription(question=question, user=user)
         subscription.save()
+        return subscription
+    except Exception, e:
+        logging.error(e)
+
+    return False
 
 def filter_subscribers(subscribers):
     subscribers = subscribers.exclude(is_active=False)
 
 def filter_subscribers(subscribers):
     subscribers = subscribers.exclude(is_active=False)
@@ -27,6 +35,9 @@ def filter_subscribers(subscribers):
 def question_posted(action, new):
     question = action.node
 
 def question_posted(action, new):
     question = action.node
 
+    if not question.is_notifiable:
+        return
+
     subscribers = User.objects.filter(
             Q(subscription_settings__enable_notifications=True, subscription_settings__new_question='i') |
             (Q(subscription_settings__new_question_watched_tags='i') &
     subscribers = User.objects.filter(
             Q(subscription_settings__enable_notifications=True, subscription_settings__new_question='i') |
             (Q(subscription_settings__new_question_watched_tags='i') &
@@ -57,6 +68,11 @@ def answer_posted(action, new):
     answer = action.node
     question = answer.question
 
     answer = action.node
     question = answer.question
 
+    logging.error("Answer posted: %s" % str(answer.is_notifiable))
+
+    if not answer.is_notifiable or not question.is_notifiable:
+        return
+
     subscribers = question.subscribers.filter(
             subscription_settings__enable_notifications=True,
             subscription_settings__notify_answers=True,
     subscribers = question.subscribers.filter(
             subscription_settings__enable_notifications=True,
             subscription_settings__notify_answers=True,
@@ -76,6 +92,9 @@ def comment_posted(action, new):
     comment = action.node
     post = comment.parent
 
     comment = action.node
     post = comment.parent
 
+    if not comment.is_notifiable or not post.is_notifiable:
+        return
+
     if post.__class__ == Question:
         question = post
     else:
     if post.__class__ == Question:
         question = post
     else:
@@ -106,6 +125,9 @@ CommentAction.hook(comment_posted)
 def answer_accepted(action, new):
     question = action.node.question
 
 def answer_accepted(action, new):
     question = action.node.question
 
+    if not question.is_notifiable:
+        return
+
     subscribers = question.subscribers.filter(
             subscription_settings__enable_notifications=True,
             subscription_settings__subscribed_questions='i'
     subscribers = question.subscribers.filter(
             subscription_settings__enable_notifications=True,
             subscription_settings__subscribed_questions='i'