def user_and_notifications(request): """ Load data that comes from a user profile. Most of this data is currently only needed view /data.js (currently Node does not get access to logged in version of /data.js) """ if not request.user.is_authenticated: return { "interrupting_message_json": InterruptingMessage(attrs=GLOBAL_INTERRUPTING_MESSAGE, request=request).json() } profile = UserProfile(id=request.user.id) if request.path == "/texts": return { "saved": profile.get_user_history(saved=True, secondary=False, serialized=True), "last_place": profile.get_user_history(last_place=True, secondary=False, serialized=True) } notifications = profile.recent_notifications() notifications_json = "[" + ",".join([n.to_JSON() for n in notifications]) + "]" interrupting_message_dict = GLOBAL_INTERRUPTING_MESSAGE or {"name": profile.interrupting_message()} interrupting_message = InterruptingMessage(attrs=interrupting_message_dict, request=request) interrupting_message_json = interrupting_message.json() return { "notifications": notifications, "notifications_json": notifications_json, "notifications_html": notifications.to_HTML(), "notifications_count": profile.unread_notification_count(), "saved": profile.get_user_history(saved=True, secondary=False, serialized=True), "last_place": profile.get_user_history(last_place=True, secondary=False, serialized=True), "interrupting_message_json": interrupting_message_json, "partner_group": profile.partner_group, "partner_role": profile.partner_role, }
def notifications(request): if not request.user.is_authenticated(): if request.COOKIES.get("_ga", None) and not request.COOKIES.get("welcomeToS2LoggedOut", None): # Welcome returning visitors only to the new Sefaria. TODO this should be removed after some time. interrupting_message_json = json.dumps({ "name": "welcomeToS2LoggedOut", "html": render_to_string("messages/welcomeToS2LoggedOut.html") }) else: interrupting_message_json = "null" return {"interrupting_message_json": interrupting_message_json} profile = UserProfile(id=request.user.id) notifications = profile.recent_notifications() notifications_json = "[" + ",".join([n.to_JSON() for n in notifications]) + "]" interrupting_message = profile.interrupting_message() if interrupting_message: interrupting_message_json = json.dumps({"name": interrupting_message, "html": render_to_string("messages/%s.html" % interrupting_message)}) else: interrupting_message_json = "null" return { "notifications": notifications, "notifications_json": notifications_json, "notifications_html": notifications.to_HTML(), "notifications_count": profile.unread_notification_count(), "interrupting_message_json": interrupting_message_json, }
def user_and_notifications(request): """ Load data that comes from a user profile. Most of this data is currently only needed view /data.js (currently Node does not get access to logged in version of /data.js) """ if not request.user.is_authenticated: return { "interrupting_message_json": InterruptingMessage(attrs=GLOBAL_INTERRUPTING_MESSAGE, request=request).json() } profile = UserProfile(id=request.user.id) if request.path == "/texts": return { "saved": profile.get_user_history(saved=True, secondary=False, serialized=True), "last_place": profile.get_user_history(last_place=True, secondary=False, serialized=True) } notifications = profile.recent_notifications() notifications_json = "[" + ",".join([n.to_JSON() for n in notifications]) + "]" interrupting_message_dict = GLOBAL_INTERRUPTING_MESSAGE or { "name": profile.interrupting_message() } interrupting_message = InterruptingMessage(attrs=interrupting_message_dict, request=request) interrupting_message_json = interrupting_message.json() return { "notifications": notifications, "notifications_json": notifications_json, "notifications_html": notifications.to_HTML(), "notifications_count": profile.unread_notification_count(), "saved": profile.get_user_history(saved=True, secondary=False, serialized=True), "last_place": profile.get_user_history(last_place=True, secondary=False, serialized=True), "interrupting_message_json": interrupting_message_json, "partner_group": profile.partner_group, "partner_role": profile.partner_role, "following": json.dumps(profile.followees.uids) }
def user_and_notifications(request): if not request.user.is_authenticated(): return {} profile = UserProfile(id=request.user.id) notifications = profile.recent_notifications() notifications_json = "[" + ",".join([n.to_JSON() for n in notifications]) + "]" interrupting_message = profile.interrupting_message() if interrupting_message: interrupting_message_json = json.dumps({ "name": interrupting_message, "html": render_to_string("messages/%s.html" % interrupting_message) }) else: interrupting_message_json = "null" return { "notifications": notifications, "notifications_json": notifications_json, "notifications_html": notifications.to_HTML(), "notifications_count": profile.unread_notification_count(), "interrupting_message_json": interrupting_message_json, "partner_group": profile.partner_group, "partner_role": profile.partner_role }
def user_and_notifications(request): if not request.user.is_authenticated(): import urlparse recent = json.loads( urlparse.unquote(request.COOKIES.get("recentlyViewed", '[]'))) recent = [] if len(recent) and isinstance( recent[0], dict) else recent # ignore old style cookies return {"recentlyViewed": recent} profile = UserProfile(id=request.user.id) notifications = profile.recent_notifications() notifications_json = "[" + ",".join([n.to_JSON() for n in notifications]) + "]" interrupting_message = profile.interrupting_message() if interrupting_message: interrupting_message_json = json.dumps({ "name": interrupting_message, "html": render_to_string("messages/%s.html" % interrupting_message) }) else: interrupting_message_json = "null" mock_recent = [{ "ref": "Orot, Lights from Darkness, Land of Israel 5", "heRef": "אורות, אורות מאופל, ארץ ישראל ה׳", "book": "Orot", "version": None, "versionLanguage": None, "position": 0 }, { "ref": "Genesis 1", "heRef": "בראשית א׳", "book": "Genesis", "version": None, "versionLanguage": None, "position": 0 }, { "ref": "Berakhot 2a", "heRef": "ברכות ב׳ א", "book": "Berakhot", "version": None, "versionLanguage": None, "position": 0 }] return { "notifications": notifications, "notifications_json": notifications_json, "notifications_html": notifications.to_HTML(), "notifications_count": profile.unread_notification_count(), "recentlyViewed": profile.recentlyViewed, "interrupting_message_json": interrupting_message_json, "partner_group": profile.partner_group, "partner_role": profile.partner_role }
def user_and_notifications(request): """ Load data that comes from a user profile. Most of this data is currently only needed view /data.js /texts requires `recentlyViewed` which is used for server side rendering of recent section (currently Node does not get access to logged in version of /data.js) """ if not request.user.is_authenticated: import urlparse recent = json.loads( urlparse.unquote(request.COOKIES.get("recentlyViewed", '[]'))) recent = [] if len(recent) and isinstance( recent[0], dict) else recent # ignore old style cookies return { "recentlyViewed": recent, "interrupting_message_json": InterruptingMessage(attrs=GLOBAL_INTERRUPTING_MESSAGE, request=request).json() } profile = UserProfile(id=request.user.id) if request.path == "/texts": return { "recentlyViewed": profile.recentlyViewed, } notifications = profile.recent_notifications() notifications_json = "[" + ",".join([n.to_JSON() for n in notifications]) + "]" interrupting_message_dict = GLOBAL_INTERRUPTING_MESSAGE or { "name": profile.interrupting_message() } interrupting_message = InterruptingMessage(attrs=interrupting_message_dict, request=request) interrupting_message_json = interrupting_message.json() return { "notifications": notifications, "notifications_json": notifications_json, "notifications_html": notifications.to_HTML(), "notifications_count": profile.unread_notification_count(), "recentlyViewed": profile.recentlyViewed, "interrupting_message_json": interrupting_message_json, "partner_group": profile.partner_group, "partner_role": profile.partner_role, }
def notifications(request): if not request.user.is_authenticated(): return {} profile = UserProfile(id=request.user.id) notifications = profile.recent_notifications() notifications_json = "[" + ",".join([n.to_JSON() for n in notifications]) + "]" interrupting_message = profile.interrupting_message() if interrupting_message: interrupting_message_json = json.dumps({"name": interrupting_message, "html": render_to_string("messages/%s.html" % interrupting_message)}) else: interrupting_message_json = "null" return { "notifications": notifications, "notifications_json": notifications_json, "notifications_html": notifications.to_HTML(), "notifications_count": profile.unread_notification_count(), "interrupting_message_json": interrupting_message_json, }
def user_and_notifications(request): """ Load data that comes from a user profile. Most of this data is currently only needed view /data.js /texts requires `recentlyViewed` which is used for server side rendering of recent section (currently Node does not get access to logged in version of /data.js) """ if not request.user.is_authenticated: import urlparse recent = json.loads(urlparse.unquote(request.COOKIES.get("recentlyViewed", '[]'))) recent = [] if len(recent) and isinstance(recent[0], dict) else recent # ignore old style cookies return { "recentlyViewed": recent, "interrupting_message_json": InterruptingMessage(attrs=GLOBAL_INTERRUPTING_MESSAGE, request=request).json() } profile = UserProfile(id=request.user.id) if request.path == "/texts": return { "recentlyViewed": profile.recentlyViewed, } notifications = profile.recent_notifications() notifications_json = "[" + ",".join([n.to_JSON() for n in notifications]) + "]" interrupting_message_dict = GLOBAL_INTERRUPTING_MESSAGE or {"name": profile.interrupting_message()} interrupting_message = InterruptingMessage(attrs=interrupting_message_dict, request=request) interrupting_message_json = interrupting_message.json() return { "notifications": notifications, "notifications_json": notifications_json, "notifications_html": notifications.to_HTML(), "notifications_count": profile.unread_notification_count(), "recentlyViewed": profile.recentlyViewed, "interrupting_message_json": interrupting_message_json, "partner_group": profile.partner_group, "partner_role": profile.partner_role, }
def notifications(request): if not request.user.is_authenticated(): if request.COOKIES.get("_ga", None) and not request.COOKIES.get( "welcomeToS2LoggedOut", None): # Welcome returning visitors only to the new Sefaria. TODO this should be removed after some time. interrupting_message_json = json.dumps({ "name": "welcomeToS2LoggedOut", "html": render_to_string("messages/welcomeToS2LoggedOut.html") }) else: interrupting_message_json = "null" return {"interrupting_message_json": interrupting_message_json} profile = UserProfile(id=request.user.id) notifications = profile.recent_notifications() notifications_json = "[" + ",".join([n.to_JSON() for n in notifications]) + "]" interrupting_message = profile.interrupting_message() if interrupting_message: interrupting_message_json = json.dumps({ "name": interrupting_message, "html": render_to_string("messages/%s.html" % interrupting_message) }) else: interrupting_message_json = "null" return { "notifications": notifications, "notifications_json": notifications_json, "notifications_html": notifications.to_HTML(), "notifications_count": profile.unread_notification_count(), "interrupting_message_json": interrupting_message_json, }