def item_categories(self, item):
return item.tagname_list()
+ def _items(self):
+ return self._question_list
+
def items(self):
- return self._question_list[:30]
+ return self._items()[:30]
class RssAnswerFeed(BaseNodeFeed):
if old_version:
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
- 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":
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})
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()
+ return subscription
+ except Exception, e:
+ logging.error(e)
+
+ return False
def filter_subscribers(subscribers):
subscribers = subscribers.exclude(is_active=False)
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') &
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,
comment = action.node
post = comment.parent
+ if not comment.is_notifiable or not post.is_notifiable:
+ return
+
if post.__class__ == Question:
question = post
else:
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'