changeset 2301:25a934c60b30

fix is_subscribed_to()
author Ana Balica <ana.balica@gmail.com>
date Sun, 10 Nov 2013 14:30:43 +0100
parents 754a1727e0ca
children 9269c5cf2931
files MoinMoin/user.py
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/user.py	Wed Oct 30 11:32:25 2013 +0100
+++ b/MoinMoin/user.py	Sun Nov 10 14:30:43 2013 +0100
@@ -30,6 +30,7 @@
 from flask import current_app as app
 from flask import g as flaskg
 from flask import session, request, url_for, render_template
+from jinja2.runtime import Undefined
 
 from MoinMoin import log
 logging = log.getLogger(__name__)
@@ -575,16 +576,19 @@
         :returns: if user is subscribed to the item
         """
         from MoinMoin.items import NonExistent
-        if not self.valid or isinstance(item, NonExistent):
+        if not self.valid or isinstance(item, (NonExistent, Undefined)):
             return False
 
         meta = item.meta
         item_namespace = meta[NAMESPACE]
-        subscriptions = {"{0}:{1}".format(ITEMID, meta[ITEMID])}
+        subscriptions = set()
+        itemid = meta.get(ITEMID)
+        if itemid is not None:
+            subscriptions.update(["{0}:{1}".format(ITEMID, itemid)])
         subscriptions.update("{0}:{1}:{2}".format(NAME, item_namespace, name)
-                             for name in meta[NAME])
+                             for name in meta.get(NAME, []))
         subscriptions.update("{0}:{1}:{2}".format(TAGS, item_namespace, tag)
-                             for tag in meta[TAGS])
+                             for tag in meta.get(TAGS, []))
         if subscriptions & set(self.subscriptions):
             return True