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 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): """ 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 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, }