def get(self): user = self.models.users.get(username=self.breadcrumbs["profile"])[0] if not user: raise tornado.web.HTTPError(404) self.display["user"] = user self.display["push_hub"] = self.constants['push_hub'] section = self.get_argument('category', '') album_feed = self.get_argument('album_feed', '') comments_url = self.get_argument('comments', '') self.display["comments_url"] = comments_url self.display["thread_url"] = None if comments_url: content_url = url_factory.load_basic_parameters(self, url=comments_url) content = self.models.content.get(username=content_url["profile"], section=content_url["section"], name=content_url["name"])[0] comments = content_remote.get_comments(self, content) thread_url = ('tag:' + self.request.host + ',' + self.display["tag_date"] + ':' + self.content_url(content)) self.display["thread_url"] = thread_url comments.sort(key=lambda x: x.date_created, reverse=True) self.display["feed"] = comments else: common_options = {} if not self.is_owner_viewing(self.breadcrumbs["profile"]): common_options['hidden'] = False content_options = { 'username': user.username, 'redirect': 0, 'forum': 0, 'section !=': 'comments', } if section: content_options['section'] = section if album_feed: content_options['album'] = album_feed content_options = dict(common_options.items() + content_options.items()) feed = self.models.content.get(**content_options).order_by( 'date_created', 'DESC') self.display["feed"] = [ self.ui["modules"].Content(content) \ for content in feed[:100] if content.section != 'main' and \ content.album != 'main' ] # todo, this should move to query really self.display["section"] = section self.display["album_feed"] = album_feed self.display['sup_id'] = hashlib.md5(self.nav_url(host=True, username=user.username, section='feed')).hexdigest()[:10] self.set_header("Content-Type", "application/atom+xml") self.set_header("X-SUP-ID", "http://friendfeed.com/api/public-sup.json#" + self.display['sup_id']) self.fill_template("feed.html")
def reply(handler, content, mentions=None): profile = content.username thread_user_remote = None users = [] users_profile = [] mentioned_users = [] if content.thread: thread_content = handler.models.content_remote.get(to_username=profile, post_id=content.thread)[0] if not thread_content: return thread_user_remote = handler.models.users_remote.get( local_username=profile, profile_url=thread_content.from_user )[0] if thread_user_remote and thread_user_remote.webmention_url: users.append(thread_user_remote) users_profile.append(thread_user_remote.profile_url) mentioned_users.append(thread_user_remote) if mentions: for user in mentions: user_remote = handler.models.users_remote.get(local_username=profile, username=user)[0] if not user_remote or (thread_user_remote and thread_user_remote.profile_url == user_remote.profile_url): continue if user_remote.profile_url in users_profile: continue if user_remote.webmention_url: users.append(user_remote) users_profile.append(user_remote.profile_url) mentioned_users.append(user_remote) if content.comments_count: comments = content_remote.get_comments(handler, content) for comment in comments: user_remote = handler.models.users_remote.get(local_username=profile, username=comment.from_user)[0] if not user_remote: continue if user_remote.profile_url in users_profile: continue # TODO(mime): Necessary to check webmention_url? if user_remote and user_remote.webmention_url: users.append(user_remote) users_profile.append(user_remote.profile_url) for user in users: user_logic.webmention_reply(handler, user, content, thread=content.thread, mentioned_users=mentioned_users)
def render(self, content, simple=True, template_type=None, sanitize=False): content.restricted = False content.is_remote = False content.comments_list = [] if content.comments_count: content.comments_list = content_remote.get_comments( self.handler, content) is_forum = self.handler.display["section_template"] == 'forum' content.comments_list.sort(key=lambda x: x.date_created, reverse=(not is_forum)) try: if not self.handler.authenticate(content=content, auto_login=(not simple)): if simple: content.restricted = True content.view = ( '"You need to <a href="' + self.handler.nav_url(host=True, section="login") + '">login</a> to view this content.') return content else: raise tornado.web.HTTPError(401) except tornado.web.HTTPError as ex: if simple: content.restricted = True content.view = \ '<span style="color:red">Sorry, you don\'t have access to view this content.</span>' return content else: # re-raise raise ex if sanitize: content.view = content_remote.sanitize(content.view) return content
def render(self, content, simple=True, template_type=None, sanitize=False): content.restricted = False content.is_remote = False content.comments_list = [] if content.comments_count: content.comments_list = content_remote.get_comments( self.handler, content) is_forum = self.handler.display["section_template"] == 'forum' content.comments_list.sort(key=lambda x: x.date_created, reverse=( not is_forum)) try: if not self.handler.authenticate(content=content, auto_login=(not simple)): if simple: content.restricted = True content.view = ('"You need to <a href="' + self.handler.nav_url(host=True, section="login") + '">login</a> to view this content.') return content else: raise tornado.web.HTTPError(401) except tornado.web.HTTPError as ex: if simple: content.restricted = True content.view = \ '<span style="color:red">Sorry, you don\'t have access to view this content.</span>' return content else: # re-raise raise ex if sanitize: content.view = content_remote.sanitize(content.view) return content
def get(self): user = self.models.users.get(username=self.breadcrumbs["profile"])[0] if not user: raise tornado.web.HTTPError(404) self.display["user"] = user self.display["push_hub"] = self.constants['push_hub'] section = self.get_argument('category', '') album_feed = self.get_argument('album_feed', '') comments_url = self.get_argument('comments', '') self.display["comments_url"] = comments_url self.display["thread_url"] = None if comments_url: content_url = url_factory.load_basic_parameters(self, url=comments_url) content = self.models.content.get(username=content_url["profile"], section=content_url["section"], name=content_url["name"])[0] comments = content_remote.get_comments(self, content) thread_url = ('tag:' + self.request.host + ',' + self.display["tag_date"] + ':' + self.content_url(content)) self.display["thread_url"] = thread_url comments.sort(key=lambda x: x.date_created, reverse=True) self.display["feed"] = comments else: common_options = {} if not self.is_owner_viewing(self.breadcrumbs["profile"]): common_options['hidden'] = False content_options = { 'username': user.username, 'redirect': 0, 'forum': 0, 'section !=': 'comments', } if section: content_options['section'] = section if album_feed: content_options['album'] = album_feed content_options = dict(common_options.items() + content_options.items()) feed = self.models.content.get(**content_options).order_by( 'date_created', 'DESC') self.display["feed"] = [ self.ui["modules"].Content(content) \ for content in feed[:100] if content.section != 'main' and \ content.album != 'main' ] # todo, this should move to query really self.display["section"] = section self.display["album_feed"] = album_feed self.display['sup_id'] = hashlib.md5( self.nav_url(host=True, username=user.username, section='feed')).hexdigest()[:10] self.set_header("Content-Type", "application/atom+xml") self.set_header( "X-SUP-ID", "http://friendfeed.com/api/public-sup.json#" + self.display['sup_id']) self.fill_template("feed.html")
def reply(handler, content, mentions=None): profile = content.username thread_user_remote = None users = [] users_profile = [] mentioned_users = [] if content.thread: thread_content = handler.models.content_remote.get( to_username=profile, post_id=content.thread)[0] if not thread_content: return thread_user_remote = handler.models.users_remote.get( local_username=profile, profile_url=thread_content.from_user)[0] if thread_user_remote and thread_user_remote.webmention_url: users.append(thread_user_remote) users_profile.append(thread_user_remote.profile_url) mentioned_users.append(thread_user_remote) if mentions: for user in mentions: user_remote = handler.models.users_remote.get( local_username=profile, username=user)[0] if not user_remote or (thread_user_remote and thread_user_remote.profile_url == user_remote.profile_url): continue if user_remote.profile_url in users_profile: continue if user_remote.webmention_url: users.append(user_remote) users_profile.append(user_remote.profile_url) mentioned_users.append(user_remote) if content.comments_count: comments = content_remote.get_comments(handler, content) for comment in comments: user_remote = handler.models.users_remote.get( local_username=profile, username=comment.from_user)[0] if not user_remote: continue if user_remote.profile_url in users_profile: continue # TODO(mime): Necessary to check webmention_url? if user_remote and user_remote.webmention_url: users.append(user_remote) users_profile.append(user_remote.profile_url) for user in users: user_logic.webmention_reply(handler, user, content, thread=content.thread, mentioned_users=mentioned_users)