def post(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {'error': 'You must be logged in to bump.', 'redirect': True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post['voted_users']: if u['username'] == self.current_user: can_vote = False if not can_vote: msg = {'error': 'You have already upvoted this post.'} else: user = userdb.get_user_by_screen_name(self.current_user) # Increment the vote count post['votes'] += 1 post['voted_users'].append(user['user']) postsdb.save_post(post) msg = {'votes': post['votes']} # send email notification to post author author = userdb.get_user_by_screen_name(post['user']['username']) if 'email_address' in author.keys(): subject = "[#usvconversation] @%s just bumped up your post: %s" % (self.current_user, post['title']) text = "Woo!\n\n%s" % template_helpers.post_permalink(post) logging.info('sent email to %s' % author['email_address']) self.send_email('*****@*****.**', author['email_address'], subject, text) self.api_response(msg)
def get(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {'error': 'You must be logged in to bump.', 'redirect': True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post['voted_users']: if u['username'] == self.current_user: can_vote = False if not can_vote: msg = {'error': 'You have already upvoted this post.'} else: user = userdb.get_user_by_screen_name(self.current_user) # Increment the vote count post['votes'] += 1 post['voted_users'].append(user['user']) postsdb.save_post(post) msg = {'votes': post['votes']} # send email notification to post author author = userdb.get_user_by_screen_name(post['user']['username']) if 'email_address' in author.keys(): subject = "[#usvconversation] @%s just bumped up your post: %s" % (self.current_user, post['title']) text = "Woo!\n\n%s" % template_helpers.post_permalink(post) logging.info('sent email to %s' % author['email_address']) self.send_email('*****@*****.**', author['email_address'], subject, text) self.api_response(msg)
def get(self, slug): post = postsdb.get_post_by_slug(slug) if not post: raise tornado.web.HTTPError(404) topics = topicsdb.get_all() comments = commentsdb.get_comments_by_post(post) current_user_can_edit = False current_user = userdb.get_user_by_screen_name(self.current_user) if current_user: current_user_can_edit = (current_user.role == "staff" or post.user == current_user.user) # remove dupes from voted_users voted_users = [] for i in post.voted_users: if i not in voted_users: voted_users.append(i) post.voted_users = voted_users self.vars.update({ 'post': post, 'comments': comments, 'topics': topics, 'current_user_can_edit': current_user_can_edit }) self.render('post/view_post.html', **self.vars)
def get(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {"error": "You must be logged in to bump.", "redirect": True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post["voted_users"]: if u["username"] == self.current_user: can_vote = False if not can_vote: msg = {"error": "You have already upvoted this post."} else: user = userdb.get_user_by_screen_name(self.current_user) # Increment the vote count post["votes"] += 1 post["voted_users"].append(user["user"]) postsdb.save_post(post) msg = {"votes": post["votes"]} # send email notification to post author author = userdb.get_user_by_screen_name(post["user"]["username"]) if "email_address" in author.keys(): subject = "[#usvconversation] @%s just bumped up your post: %s" % ( self.current_user, post["title"], ) text = "Woo!\n\nhttp://%s" % template_helpers.post_permalink(post) logging.info("sent email to %s" % author["email_address"]) self.send_email("*****@*****.**", author["email_address"], subject, text) self.api_response(msg)
def get(self): comment = self.get_argument('comment', '') post_slug = self.get_argument('post', '') post = postsdb.get_post_by_slug(post_slug) if post: # increment the comment count for this post post['comment_count'] += 1 postsdb.save_post(post) # determine if anyone is subscribed to this post (for email alerts) if len(post['subscribed']) > 0: # attempt to get the current user's email (we don't need to alert them) author_email = '' if self.current_user: author = userdb.get_user_by_screen_name(self.current_user) if author and 'email_address' in author.keys() and author['email_address'].strip() != '': author_email = author['email_address'] # get the message details from Disqus message = disqus.get_post_details(comment) if message['message'].strip() != '': # send the emails with details logging.info(message) subject = 'New message on: %s' % post['title'] text = 'The following comment was just added to your share on usv.com.\n\n%s\n\nYou can engaged in the conversation, and manage your alert settings for this share, at http://www.usv.com/posts/%s' % (message['message'], post['slug']) for email in post['subscribed']: # attempt to send to each of these subscribed people (don't send to author) if email.lower() != author_email.lower() and email.strip() != '': self.send_email('*****@*****.**', email, subject, text) self.api_response('OK')
def post(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {'error': 'You must be logged in to bump.', 'redirect': True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post['voted_users']: if u['username'] == self.current_user: can_vote = False if not can_vote: msg = {'error': 'You have already upvoted this post.'} else: user_info = userdb.get_user_by_screen_name(self.current_user) # Increment the vote count post.votes += 1 post.update(push__voted_users=user_info.user) post.save() msg = {'votes': post.votes} # send email notification to post author author = userdb.get_user_by_screen_name(post.user.username) if author.email_address: subject = "[#theconversation] @%s just bumped up your post: %s" % (self.current_user, post.title) text = "Woo!\n\n%s" % post.permalink() logging.info('sent email to %s' % author.email_address) self.send_email(settings.get('system_email_address'), author.email_address, subject, text) self.api_response(msg)
def construct_daily_email(slugs): from_email = "*****@*****.**" subject = "Top USV.com posts for %s" % datetime.datetime.today().strftime("%a %b %d, %Y") body_html = "<p>Here are the posts with the mosts for today:</p><hr />" posts = [] for slug in slugs: post = postsdb.get_post_by_slug(slug) posts.append(post) for post in posts: post['url'] = post.get('url', '') source = post.get('domain', '') body_html += "<p><b><a href='%s'>%s</a></b></p>" % (post['url'], post['title']) body_html += "<p>posted by @<a href='http://%s/user/%s'>%s</a> | %s comments | %s ↑</p>" % (settings.get('base_url'), post['user']['username'], post['user']['username'], post['comment_count'], post['votes']) body_html += "<p>%s</p>" % post['body_html'] body_html += "<p>discussion: <a href='http://%s/posts/%s'>http://%s/posts/%s</a></p>" % (settings.get('base_url'), post['slug'], settings.get('base_url'), post['slug']) body_html += "<hr />" email = { 'from': from_email, 'subject': subject, 'body_html': body_html } return email
def get(self): comment = self.get_argument("comment", "") post_slug = self.get_argument("post", "") post = postsdb.get_post_by_slug(post_slug) if post: # increment the comment count for this post post["comment_count"] += 1 postsdb.save_post(post) # determine if anyone is subscribed to this post (for email alerts) if len(post["subscribed"]) > 0: # attempt to get the current user's email (we don't need to alert them) author_email = "" if self.current_user: author = userdb.get_user_by_screen_name(self.current_user) if author and "email_address" in author.keys() and author["email_address"].strip() != "": author_email = author["email_address"] # get the message details from Disqus message = disqus.get_post_details(comment) if message["message"].strip() != "": # send the emails with details logging.info(message) subject = "New message on: %s" % post["title"] text = ( "The following comment was just added to your share on usv.com.\n\n%s\n\nYou can engaged in the conversation, and manage your alert settings for this share, at http://www.usv.com/posts/%s" % (message["message"], post["slug"]) ) for email in post["subscribed"]: # attempt to send to each of these subscribed people (don't send to author) if email.lower() != author_email.lower() and email.strip() != "": self.send_email("*****@*****.**", email, subject, text) self.api_response("OK")
def get(self, slug): post = postsdb.get_post_by_slug(slug) if post and post["user"]["screen_name"] == self.current_user or self.current_user_can("edit_posts"): # available to edit this post self.render("post/edit_post.html", post=post) else: # not available to edit right now self.redirect("/posts/%s" % slug)
def get(self, slug): post = postsdb.get_post_by_slug(slug) if post and post['user']['screen_name'] == self.current_user or self.current_user_can('edit_posts'): # available to edit this post self.render('post/edit_post.html', post=post) else: # not available to edit right now self.redirect('/posts/%s' % slug)
def get(self, slug): post = postsdb.get_post_by_slug(slug) if post and self.current_user_can('mute_posts'): post['muted'] = True postsdb.save_post(post) self.redirect('/?sort_by=hot')
def get(self, slug): post = postsdb.get_post_by_slug(slug) if self.current_user_can('downvote_posts'): post['sort_score'] -= 0.25 postsdb.save_post(post) self.redirect('/?sort_by=hot')
def get(self, day="today", page=1, sort_by="hot"): view = "list" sort_by = self.get_argument('sort_by', sort_by) page = abs(int(self.get_argument('page', page))) per_page = abs(int(self.get_argument('per_page', '20'))) msg = self.get_argument('msg', '') slug = self.get_argument('slug', '') new_post = None featured_topics = topicsdb.get_featured() if slug: new_post = postsdb.get_post_by_slug(slug) featured_posts = postsdb.get_featured_posts(1) posts = [] hot_tags = tagsdb.get_hot_tags() is_today = False if day == "today": is_today = True day = datetime.datetime.today() else: day = datetime.datetime.strptime(day, "%Y-%m-%d") show_day_permalink = True infinite_scroll = False if self.request.path == ('/'): show_day_permalink = False infinite_scroll = True is_blacklisted = False if self.current_user: is_blacklisted = self.is_blacklisted(self.current_user) posts = postsdb.get_hot_posts_24hr(day) previous_day_posts = postsdb.get_hot_posts_24hr(datetime.datetime.now() - datetime.timedelta(hours=24)) midpoint = 7 #midpoint = (len(posts) - 1) / 2 # midpoint determines where post list breaks from size=md to size=sm hot_posts_past_week = postsdb.get_hot_posts_past_week() self.vars.update({ 'is_today': is_today, 'view': view, 'posts': posts, 'previous_day_posts': previous_day_posts, 'hot_posts_past_week': hot_posts_past_week, 'day': day, 'show_day_permalink': show_day_permalink, 'infinite_scroll': infinite_scroll, 'new_post': new_post, 'msg': msg, 'featured_posts': featured_posts, 'midpoint': midpoint, 'featured_topics': featured_topics }) self.render('post/list_posts.html', **self.vars)
def post(self): next_page = self.get_argument('next', '') next_page += "&finished=true" close_popup = self.get_argument('close_popup', '') email = self.get_argument('email', '') subscribe_to = self.get_argument('subscribe_to', '') error = '' status = '' slug = '' if close_popup != '': status = 'close_popup' # get the current user's email value user = userdb.get_user_by_screen_name(self.current_user) if user: # Clear the existing email address if email == '': if subscribe_to == '': user['email_address'] = '' self.set_secure_cookie('email_address', '') userdb.save_user(user) error = 'Your email address has been cleared.' else: # make sure someone else isn't already using this email existing = userdb.get_user_by_email(email) if existing and existing['user']['id_str'] != user['user']['id_str']: error = 'This email address is already in use.' else: # OK to save as user's email user['email_address'] = email userdb.save_user(user) self.set_secure_cookie('email_address', email) if subscribe_to != '': post = postsdb.get_post_by_slug(subscribe_to) if post: slug = post['slug'] # Attempt to create the post's thread thread_id = 0 try: # Attempt to create the thread. thread_details = disqus.create_thread(post, user['disqus_access_token']) thread_id = thread_details['response']['id'] except: try: # trouble creating the thread, try to just get the thread via the slug thread_details = disqus.get_thread_details(slug) thread_id = thread_details['response']['id'] except: thread_id = 0 if thread_id != 0: # Subscribe a user to the thread specified in response disqus.subscribe_to_thread(thread_id, user['disqus_access_token']) self.redirect("/user/%s/settings?msg=updated" % user['user']['screen_name'])
def get(self, slug): voted_users = [] post = postsdb.get_post_by_slug(slug) if post: voted_users = post["voted_users"] for user in voted_users: if user.get("username") == post["user"]["username"]: voted_users.remove(user) self.render("post/voted_users.html", voted_users=voted_users)
def get(self, slug): voted_users = [] post = postsdb.get_post_by_slug(slug) if post: voted_users = post['voted_users'] for user in voted_users: if user.get('username') == post['user']['username']: voted_users.remove(user) self.render('post/voted_users.html', voted_users=voted_users)
def post(self): if not self.current_user_can('delete_users'): self.redirect('/') else: msg = self.get_argument('msg', '') post_slug = self.get_argument('post_slug', '') post = postsdb.get_post_by_slug(post_slug) if post: # get the author of this post screen_name = post['user']['screen_name'] postsdb.delete_all_posts_by_user(screen_name) self.ender('admin/delete_user.html', msg=msg)
def post(self, post_slug): post = postsdb.get_post_by_slug(post_slug) post_owner = userdb.get_user_by_screen_name(post.user.screen_name) user_info = userdb.get_user_by_screen_name(self.current_user) firebase_id = self.get_argument('firebase_id', None) parent_comment = None if self.get_argument('parent_comment_id', '') != "": parent_comment = commentsdb.get_comment_by_id(self.get_argument('parent_comment_id', '')) comment = commentsdb.add_comment(post, user_info, self.get_argument('comment_body_text', ''), parent_comment, firebase_id) if comment.status == "published": #self.set_secure_cookie("flash", "Comment added!") #self.redirect(post.permalink()) self.write('success') else: self.write('error')
def post(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {'error': 'You must be logged in to super downvote.', 'redirect': True} elif not self.current_user_can('super_downvote'): msg = {'error': 'You are not authorized to super downvote', 'redirect': True} else: post = postsdb.get_post_by_slug(slug) if post: # Increment the vote count post.super_downvotes += 1 post.save() msg = {'supervotes': post.super_downvotes} self.api_response(msg)
def post(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {'error': 'You must be logged in to super downvote.', 'redirect': True} elif not self.current_user_can('super_downvote'): msg = {'error': 'You are not authorized to super downvote', 'redirect': True} else: post = postsdb.get_post_by_slug(slug) if post: # Increment the vote count super_downvotes = post.get('super_downvotes') or 0 super_downvotes += 1 post['super_downvotes'] = super_downvotes postsdb.save_post(post) msg = {'supervotes': post['super_downvotes']} self.api_response(msg)
def construct_daily_email(slugs): from_email = "*****@*****.**" subject = "Top USV.com posts for %s" % datetime.today().strftime( "%a %b %d, %Y") body_html = "<p>Here are the posts with the mosts for today:</p><hr />" email_name = "Daily %s" % datetime.today().strftime("%a %b %d, %Y") posts = [] for slug in slugs: post = postsdb.get_post_by_slug(slug) posts.append(post) for post in posts: post['url'] = post.get('url', '') source = post.get('domain', '') body_html += "<p><b><a href='%s'>%s</a></b></p>" % (post['url'], post['title']) body_html += "<p>posted by @<a href='http://%s/user/%s'>%s</a> | %s comments | %s ↑</p>" % ( settings.get('base_url'), post['user']['username'], post['user']['username'], post['comment_count'], post['votes']) body_html += "<p>%s</p>" % post['body_html'] body_html += "<p>discussion: <a href='http://%s/posts/%s'>http://%s/posts/%s</a></p>" % ( settings.get('base_url'), post['slug'], settings.get('base_url'), post['slug']) body_html += "<hr />" body_html += "Want to unsubscribe? Visit http://%s/user/settings" % settings.get( 'base_url') email = {'from': from_email, 'subject': subject, 'body_html': body_html} # create the email # POST https://api.sendgrid.com/api/newsletter/add.json # @identity (created in advance == the sender's identity), @name (of email), @subject, @text, @html api_link = 'https://api.sendgrid.com/api/newsletter/add.json' params = { 'identity': settings.get('sendgrid_sender_identity'), 'name': email_name, 'subject': email['subject'], 'text': '', #to do get text version, 'html': email['body_html'] } result = do_api_request(api_link, method="POST", params=params) return result
def get(self, slug): post = postsdb.get_post_by_slug(slug) if not post: raise tornado.web.HTTPError(404) tag_posts = [] all_keeper_posts = [] if 'tags' in post.keys() and len(post['tags']) > 0: for t in post['tags']: posts = postsdb.get_related_posts_by_tag(t) tag_keeper_posts = [] for p in posts: if p['slug'] != slug and p not in all_keeper_posts: tag_keeper_posts.append(p) all_keeper_posts.append(p) obj = {'tag': t, 'posts': tag_keeper_posts} tag_posts.append(obj) msg = self.get_argument('msg', None) user = None if self.current_user: user = userdb.get_user_by_screen_name(self.current_user) # remove dupes from voted_users voted_users = [] for i in post['voted_users']: if i not in voted_users: voted_users.append(i) post['voted_users'] = voted_users hot_posts_past_week = postsdb.get_hot_posts_past_week() featured_posts = {} view = "single" self.render('post/view_post.html', user_obj=user, post=post, msg=msg, tag_posts=tag_posts, hot_posts_past_week=hot_posts_past_week, featured_posts=featured_posts, view=view)
def get(self, slug): post = postsdb.get_post_by_slug(slug) if not post: raise tornado.web.HTTPError(404) msg = self.get_argument("msg", None) user = None if self.current_user: user = userdb.get_user_by_screen_name(self.current_user) # remove dupes from voted_users voted_users = [] for i in post["voted_users"]: if i not in voted_users: voted_users.append(i) post["voted_users"] = voted_users self.render("post/view_post.html", user_obj=user, post=post, msg=msg)
def construct_daily_email(slugs): from_email = "*****@*****.**" subject = "Top USV.com posts for %s" % datetime.today().strftime("%a %b %d, %Y") body_html = "<p>Here are the posts with the mosts for today:</p><hr />" email_name = "Daily %s" % datetime.today().strftime("%a %b %d, %Y") posts = [] for slug in slugs: post = postsdb.get_post_by_slug(slug) posts.append(post) for post in posts: post['url'] = post.get('url', '') source = post.get('domain', '') body_html += "<p><b><a href='%s'>%s</a></b></p>" % (post['url'], post['title']) body_html += "<p>posted by @<a href='http://%s/user/%s'>%s</a> | %s comments | %s ↑</p>" % (settings.get('base_url'), post['user']['username'], post['user']['username'], post['comment_count'], post['votes']) body_html += "<p>%s</p>" % post['body_html'] body_html += "<p>discussion: <a href='http://%s/posts/%s'>http://%s/posts/%s</a></p>" % (settings.get('base_url'), post['slug'], settings.get('base_url'), post['slug']) body_html += "<hr />" body_html += "Want to unsubscribe? Visit http://%s/user/settings" % settings.get('base_url') email = { 'from': from_email, 'subject': subject, 'body_html': body_html } # create the email # POST https://api.sendgrid.com/api/newsletter/add.json # @identity (created in advance == the sender's identity), @name (of email), @subject, @text, @html api_link = 'https://api.sendgrid.com/api/newsletter/add.json' params = { 'identity': settings.get('sendgrid_sender_identity'), 'name': email_name, 'subject': email['subject'], 'text': '', #to do get text version, 'html': email['body_html'] } result = do_api_request(api_link, method="POST", params=params) return result
def get(self, slug): post = postsdb.get_post_by_slug(slug) if not post: raise tornado.web.HTTPError(404) tag_posts = [] all_keeper_posts = [] if 'tags' in post.keys() and len(post['tags']) > 0: for t in post['tags']: posts = postsdb.get_related_posts_by_tag(t) tag_keeper_posts = [] for p in posts: if p['slug'] != slug and p not in all_keeper_posts: tag_keeper_posts.append(p) all_keeper_posts.append(p) obj = { 'tag': t, 'posts': tag_keeper_posts } tag_posts.append(obj) msg = self.get_argument('msg', None) user = None if self.current_user: user = userdb.get_user_by_screen_name(self.current_user) # remove dupes from voted_users voted_users = [] for i in post['voted_users']: if i not in voted_users: voted_users.append(i) post['voted_users'] = voted_users hot_posts_past_week = postsdb.get_hot_posts_past_week() featured_posts = {} view = "single" self.render('post/view_post.html', user_obj=user, post=post, msg=msg, tag_posts=tag_posts, hot_posts_past_week=hot_posts_past_week, featured_posts=featured_posts, view=view)
def get(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {'error': 'You must be logged in to bump.', 'redirect': True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post['voted_users']: if u['username'] == self.current_user: can_unbump = True if not can_unbump: msg = {'error': "You can't unbump this post!"} else: user = userdb.get_user_by_screen_name(self.current_user) post['votes'] -= 1 post['voted_users'].remove(user['user']) postsdb.save_post(post) msg = {'votes': post['votes']} self.api_response(msg)
def get(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {"error": "You must be logged in to bump.", "redirect": True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post["voted_users"]: if u["username"] == self.current_user: can_unbump = True if not can_unbump: msg = {"error": "You can't unbump this post!"} else: user = userdb.get_user_by_screen_name(self.current_user) post["votes"] -= 1 post["voted_users"].remove(user["user"]) postsdb.save_post(post) msg = {"votes": post["votes"]} self.api_response(msg)
def post(self, slug): # user must be logged in msg = {} if not self.current_user: msg = {'error': 'You must be logged in to bump.', 'redirect': True} else: post = postsdb.get_post_by_slug(slug) if post: can_vote = True for u in post['voted_users']: if u['username'] == self.current_user: can_unbump = True if not can_unbump: msg = {'error': "You can't unbump this post!"} else: user_info = userdb.get_user_by_screen_name(self.current_user) post.votes -= 1 post.update(pull_voted_users=user_info.user) post.save() msg = {'votes': post.votes} self.api_response(msg)
def post(self): sort_by = self.get_argument('sort_by', 'hot') page = abs(int(self.get_argument('page', '1'))) per_page = abs(int(self.get_argument('per_page', '9'))) is_blacklisted = False msg = 'success' if self.current_user: is_blacklisted = self.is_blacklisted(self.current_user) post = {} post['slug'] = self.get_argument('slug', None) post['title'] = self.get_argument('title', '') post['url'] = self.get_argument('url', '') post['body_raw'] = self.get_argument('body_raw', '') post['tags'] = self.get_argument('tags', '').split(',') post['featured'] = self.get_argument('featured', '') post['has_hackpad'] = self.get_argument('has_hackpad', '') post['slug'] = self.get_argument('slug', '') post['sort_score'] = 0 post['daily_sort_score'] = 0 # handle topics if self.get_argument('primary_topic', '') == "" or self.get_argument('primary_topic', '') == "+other+": post['topic_slug'] = slugify(unicode(self.get_argument('secondary_topic', ''))) else: post['topic_slug'] = self.get_argument('primary_topic', '') if post['has_hackpad'] != '': post['has_hackpad'] = True else: post['has_hackpad'] = False deleted = self.get_argument('deleted', '') if deleted != '': post['deleted'] = True post['date_deleted'] = datetime.datetime.now() bypass_dup_check = self.get_argument('bypass_dup_check', '') is_edit = False if post['slug']: bypass_dup_check = "true" is_edit = True dups = [] # make sure user isn't blacklisted if not self.is_blacklisted(self.current_user): # check if there is an existing URL if post['url'] != '': url = urlparse(post['url']) netloc = url.netloc.split('.') if netloc[0] == 'www': del netloc[0] path = url.path if path and path[-1] == '/': path = path[:-1] url = '%s%s' % ('.'.join(netloc), path) post['normalized_url'] = url long_url = post['url'] if long_url.find('goo.gl') > -1: long_url = google.expand_url(post['url']) if long_url.find('bit.ly') > -1 or long_url.find('bitly.com') > -1: long_url = bitly.expand_url(post['url'].replace('http://bitly.com','').replace('http://bit.ly','')) post['domain'] = urlparse(long_url).netloc ok_to_post = True dups = postsdb.get_posts_by_normalized_url(post.get('normalized_url', ""), 1) if post['url'] != '' and len(dups) > 0 and bypass_dup_check != "true": ## ## If there are dupes, kick them back to the post add form ## return (self.render('post/new_post.html', post=post, dups=dups)) # Handle tags post['tags'] = [t.strip().lower() for t in post['tags']] post['tags'] = [t for t in post['tags'] if t] userdb.add_tags_to_user(self.current_user, post['tags']) for tag in post['tags']: tagsdb.save_tag(tag) # format the content as needed post['body_html'] = sanitize.html_sanitize(post['body_raw'], media=self.current_user_can('post_rich_media')) post['body_text'] = sanitize.html_to_text(post['body_html']) post['body_truncated'] = sanitize.truncate(post['body_text'], 500) # determine if this should be a featured post or not if self.current_user_can('feature_posts') and post['featured'] != '': post['featured'] = True post['date_featured'] = datetime.datetime.now() else: post['featured'] = False post['date_featured'] = None user_info = userdb.get_user_by_screen_name(self.current_user) if not post['slug'] or post.get('slug') == "" or post.get('slug') == "None": # No slug -- this is a new post. # initiate fields that are new post['disqus_shortname'] = settings.get('disqus_short_code') post['muted'] = False post['comment_count'] = 0 post['disqus_thread_id_str'] = '' post['sort_score'] = 0.0 post['downvotes'] = 0 post['hackpad_url'] = '' post['date_created'] = datetime.datetime.now() post['user'] = user_info.user post['votes'] = 1 post['voted_users'] = [user_info.user] #save it saved_post = postsdb.insert_post(post) print "new post" # send notification to customer.io # if post is in a topic if saved_post.topic_slug != "": topic = topicsdb.get_topic_by_slug(saved_post.topic_slug) data ={ 'topic_name': topic.name, 'post_author': saved_post.user.username, 'post_title': saved_post.title, 'post_permalink': saved_post.permalink(), 'post_id': str(saved_post.id) } # find topic followers followers = userdb.get_followers(topic.slug) # for each follower, ping customer.io about this post. for follower in followers: cio.track(customer_id=follower.user.username, name='new_post_notification', **data) else: # this is an existing post. print "existing post" # attempt to edit the post (make sure they are the author) saved_post = postsdb.get_post_by_slug(post['slug']) if saved_post: if self.current_user == saved_post['user']['screen_name'] or self.current_user_can('edit_posts'): # looks good - let's update the saved_post values to new values for key in post.keys(): saved_post[key] = post[key] # finally let's save the updates postsdb.save_post(saved_post) msg = 'success' if saved_post and self.current_user == saved_post['user']['screen_name']: # looks good - let's update the saved_post values to new values saved_post.set_fields(**post) # finally let's save the updates saved_post.save() msg = 'success' # # From here on out, we have a saved_post, which is a mongoengine Post object. # # log any @ mentions in the post mentions = re.findall(r'@([^\s]+)', saved_post.body_raw) for mention in mentions: mentionsdb.add_mention(mention.lower(), saved_post.slug) if is_edit: self.set_secure_cookie('flash', 'Edited!') self.redirect(saved_post.permalink()) else: self.set_secure_cookie('flash', 'Nice one!') self.redirect(saved_post.permalink())
def post(self): sort_by = self.get_argument("sort_by", "hot") page = abs(int(self.get_argument("page", "1"))) per_page = abs(int(self.get_argument("per_page", "9"))) is_blacklisted = False msg = "success" if self.current_user: is_blacklisted = self.is_blacklisted(self.current_user) post = {} post["slug"] = self.get_argument("slug", None) post["title"] = self.get_argument("title", "") post["url"] = self.get_argument("url", "") post["body_raw"] = self.get_argument("body_raw", "") post["tags"] = self.get_argument("tags", "").split(",") post["featured"] = self.get_argument("featured", "") post["has_hackpad"] = self.get_argument("has_hackpad", "") post["slug"] = self.get_argument("slug", "") if post["has_hackpad"] != "": post["has_hackpad"] = True else: post["has_hackpad"] = False deleted = self.get_argument("deleted", "") if deleted != "": post["deleted"] = True post["date_deleted"] = datetime.now() bypass_dup_check = self.get_argument("bypass_dup_check", "") is_edit = False if post["slug"]: bypass_dup_check = "true" is_edit = True dups = [] # make sure user isn't blacklisted if not self.is_blacklisted(self.current_user): # check if there is an existing URL if post["url"] != "": url = urlparse(post["url"]) netloc = url.netloc.split(".") if netloc[0] == "www": del netloc[0] path = url.path if path and path[-1] == "/": path = path[:-1] url = "%s%s" % (".".join(netloc), path) post["normalized_url"] = url long_url = post["url"] if long_url.find("goo.gl") > -1: long_url = google.expand_url(post["url"]) if long_url.find("bit.ly") > -1 or long_url.find("bitly.com") > -1: long_url = bitly.expand_url( post["url"].replace("http://bitly.com", "").replace("http://bit.ly", "") ) post["domain"] = urlparse(long_url).netloc ok_to_post = True dups = postsdb.get_posts_by_normalized_url(post.get("normalized_url", ""), 1) if post["url"] != "" and len(dups) > 0 and bypass_dup_check != "true": ## ## If there are dupes, kick them back to the post add form ## return self.render("post/new_post.html", post=post, dups=dups) # Handle tags post["tags"] = [t.strip().lower() for t in post["tags"]] post["tags"] = [t for t in post["tags"] if t] userdb.add_tags_to_user(self.current_user, post["tags"]) for tag in post["tags"]: tagsdb.save_tag(tag) # format the content as needed post["body_html"] = sanitize.html_sanitize(post["body_raw"], media=self.current_user_can("post_rich_media")) post["body_text"] = sanitize.html_to_text(post["body_html"]) post["body_truncated"] = sanitize.truncate(post["body_text"], 500) # determine if this should be a featured post or not if self.current_user_can("feature_posts") and post["featured"] != "": post["featured"] = True post["date_featured"] = datetime.now() else: post["featured"] = False post["date_featured"] = None user = userdb.get_user_by_screen_name(self.current_user) if not post["slug"]: # No slug -- this is a new post. # initiate fields that are new post["disqus_shortname"] = settings.get("disqus_short_code") post["muted"] = False post["comment_count"] = 0 post["disqus_thread_id_str"] = "" post["sort_score"] = 0.0 post["downvotes"] = 0 post["hackpad_url"] = "" post["date_created"] = datetime.now() post["user_id_str"] = user["user"]["id_str"] post["username"] = self.current_user post["user"] = user["user"] post["votes"] = 1 post["voted_users"] = [user["user"]] # save it post["slug"] = postsdb.insert_post(post) msg = "success" else: # this is an existing post. # attempt to edit the post (make sure they are the author) saved_post = postsdb.get_post_by_slug(post["slug"]) if saved_post and self.current_user == saved_post["user"]["screen_name"]: # looks good - let's update the saved_post values to new values for key in post.keys(): saved_post[key] = post[key] # finally let's save the updates postsdb.save_post(saved_post) msg = "success" # log any @ mentions in the post mentions = re.findall(r"@([^\s]+)", post["body_raw"]) for mention in mentions: mentionsdb.add_mention(mention.lower(), post["slug"]) # Send email to USVers if OP is staff if self.current_user in settings.get("staff"): subject = 'USV.com: %s posted "%s"' % (self.current_user, post["title"]) if "url" in post and post["url"]: # post.url is the link to external content (if any) post_link = "External Link: %s \n\n" % post["url"] else: post_link = "" post_url = "http://%s/posts/%s" % (settings.get("base_url"), post["slug"]) text = '"%s" ( %s ) posted by %s. \n\n %s %s' % ( post["title"].encode("ascii", errors="ignore"), post_url, self.current_user, post_link, post.get("body_text", ""), ) # now attempt to actually send the emails for u in settings.get("staff"): if u != self.current_user: acc = userdb.get_user_by_screen_name(u) if acc: self.send_email("*****@*****.**", acc["email_address"], subject, text) # Subscribe to Disqus # Attempt to create the post's thread acc = userdb.get_user_by_screen_name(self.current_user) thread_id = 0 try: # Attempt to create the thread. thread_details = disqus.create_thread(post, acc["disqus_access_token"]) thread_id = thread_details["response"]["id"] except: try: # trouble creating the thread, try to just get the thread via the slug thread_details = disqus.get_thread_details(post.slug) thread_id = thread_details["response"]["id"] except: thread_id = 0 if thread_id != 0: # Subscribe a user to the thread specified in response disqus.subscribe_to_thread(thread_id, acc["disqus_access_token"]) # update the thread with the disqus_thread_id_str saved_post = postsdb.get_post_by_slug(post["slug"]) saved_post["disqus_thread_id_str"] = thread_id postsdb.save_post(saved_post) featured_posts = postsdb.get_featured_posts(6, 1) sort_by = "newest" posts = postsdb.get_new_posts(per_page, page) if is_edit: self.redirect("/posts/%s?msg=updated" % post["slug"]) else: self.render( "post/lists_posts.html", sort_by=sort_by, msg=msg, page=page, posts=posts, featured_posts=featured_posts, is_blacklisted=is_blacklisted, new_post=post, dups=dups, )
def post(self): sort_by = self.get_argument('sort_by', 'hot') page = abs(int(self.get_argument('page', '1'))) per_page = abs(int(self.get_argument('per_page', '9'))) is_blacklisted = False msg = 'success' if self.current_user: is_blacklisted = self.is_blacklisted(self.current_user) post = {} post['slug'] = self.get_argument('slug', None) post['title'] = self.get_argument('title', '') post['url'] = self.get_argument('url', '') post['body_raw'] = self.get_argument('body_raw', '') post['tags'] = self.get_argument('tags', '').split(',') post['featured'] = self.get_argument('featured', '') post['has_hackpad'] = self.get_argument('has_hackpad', '') post['slug'] = self.get_argument('slug', '') post['sort_score'] = 0 post['daily_sort_score'] = 0 if post['has_hackpad'] != '': post['has_hackpad'] = True else: post['has_hackpad'] = False deleted = self.get_argument('deleted', '') if deleted != '': post['deleted'] = True post['date_deleted'] = datetime.datetime.now() bypass_dup_check = self.get_argument('bypass_dup_check', '') is_edit = False if post['slug']: bypass_dup_check = "true" is_edit = True dups = [] # make sure user isn't blacklisted if not self.is_blacklisted(self.current_user): # check if there is an existing URL if post['url'] != '': url = urlparse(post['url']) netloc = url.netloc.split('.') if netloc[0] == 'www': del netloc[0] path = url.path if path and path[-1] == '/': path = path[:-1] url = '%s%s' % ('.'.join(netloc), path) post['normalized_url'] = url long_url = post['url'] if long_url.find('goo.gl') > -1: long_url = google.expand_url(post['url']) if long_url.find('bit.ly') > -1 or long_url.find( 'bitly.com') > -1: long_url = bitly.expand_url(post['url'].replace( 'http://bitly.com', '').replace('http://bit.ly', '')) post['domain'] = urlparse(long_url).netloc ok_to_post = True dups = postsdb.get_posts_by_normalized_url( post.get('normalized_url', ""), 1) if post['url'] != '' and len( dups) > 0 and bypass_dup_check != "true": ## ## If there are dupes, kick them back to the post add form ## return (self.render('post/new_post.html', post=post, dups=dups)) # Handle tags post['tags'] = [t.strip().lower() for t in post['tags']] post['tags'] = [t for t in post['tags'] if t] userdb.add_tags_to_user(self.current_user, post['tags']) for tag in post['tags']: tagsdb.save_tag(tag) # format the content as needed post['body_html'] = sanitize.html_sanitize( post['body_raw'], media=self.current_user_can('post_rich_media')) post['body_text'] = sanitize.html_to_text(post['body_html']) post['body_truncated'] = sanitize.truncate(post['body_text'], 500) # determine if this should be a featured post or not if self.current_user_can( 'feature_posts') and post['featured'] != '': post['featured'] = True post['date_featured'] = datetime.datetime.now() else: post['featured'] = False post['date_featured'] = None user = userdb.get_user_by_screen_name(self.current_user) if not post['slug']: # No slug -- this is a new post. # initiate fields that are new post['disqus_shortname'] = settings.get('disqus_short_code') post['muted'] = False post['comment_count'] = 0 post['disqus_thread_id_str'] = '' post['sort_score'] = 0.0 post['downvotes'] = 0 post['hackpad_url'] = '' post['date_created'] = datetime.datetime.now() post['user_id_str'] = user['user']['id_str'] post['username'] = self.current_user post['user'] = user['user'] post['votes'] = 1 post['voted_users'] = [user['user']] #save it post['slug'] = postsdb.insert_post(post) msg = 'success' else: # this is an existing post. # attempt to edit the post (make sure they are the author) saved_post = postsdb.get_post_by_slug(post['slug']) if saved_post and self.current_user == saved_post['user'][ 'screen_name']: # looks good - let's update the saved_post values to new values for key in post.keys(): saved_post[key] = post[key] # finally let's save the updates postsdb.save_post(saved_post) msg = 'success' # log any @ mentions in the post mentions = re.findall(r'@([^\s]+)', post['body_raw']) for mention in mentions: mentionsdb.add_mention(mention.lower(), post['slug']) # Send email to USVers if OP is staff if self.current_user in settings.get('staff'): subject = 'USV.com: %s posted "%s"' % (self.current_user, post['title']) if 'url' in post and post[ 'url']: # post.url is the link to external content (if any) post_link = 'External Link: %s \n\n' % post['url'] else: post_link = '' post_url = "http://%s/posts/%s" % (settings.get('base_url'), post['slug']) text = '"%s" ( %s ) posted by %s. \n\n %s %s' % ( post['title'].encode('ascii', errors='ignore'), post_url, self.current_user, post_link, post.get('body_text', "")) # now attempt to actually send the emails for u in settings.get('staff'): if u != self.current_user: acc = userdb.get_user_by_screen_name(u) if acc: self.send_email('*****@*****.**', acc['email_address'], subject, text) # Subscribe to Disqus # Attempt to create the post's thread acc = userdb.get_user_by_screen_name(self.current_user) thread_id = 0 try: # Attempt to create the thread. thread_details = disqus.create_thread( post, acc['disqus']['access_token']) thread_id = thread_details['response']['id'] except: try: # trouble creating the thread, try to just get the thread via the slug thread_details = disqus.get_thread_details(post) thread_id = thread_details['response']['id'] except: thread_id = 0 if thread_id != 0: # Subscribe a user to the thread specified in response disqus.subscribe_to_thread(thread_id, acc['disqus']['access_token']) # update the thread with the disqus_thread_id_str saved_post = postsdb.get_post_by_slug(post['slug']) saved_post['disqus_thread_id_str'] = thread_id postsdb.save_post(saved_post) if is_edit: self.redirect('/posts/%s?msg=updated' % post['slug']) else: self.redirect('/?msg=success&slug=%s' % post['slug'])
def get(self, day="today", page=1, sort_by="hot"): view = "list" sort_by = self.get_argument('sort_by', sort_by) page = abs(int(self.get_argument('page', page))) per_page = abs(int(self.get_argument('per_page', '20'))) msg = self.get_argument('msg', '') slug = self.get_argument('slug', '') new_post = None if slug: new_post = postsdb.get_post_by_slug(slug) featured_posts = postsdb.get_featured_posts(1) posts = [] post = {} hot_tags = tagsdb.get_hot_tags() is_today = False if day == "today": is_today = True day = datetime.datetime.today() else: day = datetime.datetime.strptime(day, "%Y-%m-%d") previous_day = day - datetime.timedelta(days=1) two_days_ago = previous_day - datetime.timedelta(days=1) day_str = str(datetime.date(day.year, day.month, day.day)) previous_day_str = str( datetime.date(previous_day.year, previous_day.month, previous_day.day)) two_days_ago_str = str( datetime.date(two_days_ago.year, two_days_ago.month, two_days_ago.day)) show_day_permalink = True infinite_scroll = False if self.request.path == ('/'): show_day_permalink = False infinite_scroll = True is_blacklisted = False if self.current_user: is_blacklisted = self.is_blacklisted(self.current_user) posts = postsdb.get_hot_posts_by_day(day) #posts = postsdb.get_hot_posts_24hr() previous_day_posts = postsdb.get_hot_posts_by_day(previous_day) #midpoint = (len(posts) - 1) / 2 # midpoint determines where post list breaks from size=md to size=sm midpoint = 7 hot_posts_past_week = postsdb.get_hot_posts_past_week() self.vars.update({ 'is_today': is_today, 'view': view, 'msg': msg, 'posts': posts, 'previous_day_posts': previous_day_posts, 'hot_posts_past_week': hot_posts_past_week, 'featured_posts': featured_posts, 'post': post, #'featured_posts': featured_posts, 'is_blacklisted': is_blacklisted, 'tags': hot_tags, 'day': day, 'day_str': day_str, 'previous_day': previous_day, 'previous_day_str': previous_day_str, 'two_days_ago': two_days_ago, 'two_days_ago_str': two_days_ago_str, 'show_day_permalink': show_day_permalink, 'infinite_scroll': infinite_scroll, 'midpoint': midpoint, 'new_post': new_post, 'datetime': datetime }) self.render('post/lists_posts.html', **self.vars)
def get(self, slug): voted_users = [] post = postsdb.get_post_by_slug(slug) if post: voted_users = post['voted_users'] self.render('post/voted_users.html', voted_users=voted_users)
def post(self): next_page = self.get_argument('next', '') next_page += "&finished=true" close_popup = self.get_argument('close_popup', '') email = self.get_argument('email', '') subscribe_to = self.get_argument('subscribe_to', '') error = '' status = '' slug = '' if close_popup != '': status = 'close_popup' # get the current user's email value user = userdb.get_user_by_screen_name(self.current_user) if user: # Clear the existing email address if email == '': if subscribe_to == '': user['email_address'] = '' self.set_secure_cookie('email_address', '') userdb.save_user(user) error = 'Your email address has been cleared.' else: # make sure someone else isn't already using this email existing = userdb.get_user_by_email(email) if existing and existing['user']['id_str'] != user['user'][ 'id_str']: error = 'This email address is already in use.' else: # OK to save as user's email user['email_address'] = email userdb.save_user(user) self.set_secure_cookie('email_address', email) if subscribe_to != '': post = postsdb.get_post_by_slug(subscribe_to) if post: slug = post['slug'] # Attempt to create the post's thread thread_id = 0 try: # Attempt to create the thread. thread_details = disqus.create_thread( post, user['disqus_access_token']) thread_id = thread_details['response']['id'] except: try: # trouble creating the thread, try to just get the thread via the slug thread_details = disqus.get_thread_details( post) thread_id = thread_details['response']['id'] except: thread_id = 0 if thread_id != 0: # Subscribe a user to the thread specified in response disqus.subscribe_to_thread( thread_id, user['disqus_access_token']) #save email prefs user['wants_daily_email'] = self.get_argument('wants_daily_email', False) if user['wants_daily_email'] == "on": user['wants_daily_email'] = True user['wants_email_alerts'] = self.get_argument('wants_email_alerts', False) if user['wants_email_alerts'] == "on": user['wants_email_alerts'] = True userdb.save_user(user) self.redirect("/user/%s/settings?msg=updated" % user['user']['screen_name'])
def post(self): sort_by = self.get_argument('sort_by', 'hot') page = abs(int(self.get_argument('page', '1'))) per_page = abs(int(self.get_argument('per_page', '9'))) is_blacklisted = False msg = 'success' if self.current_user: is_blacklisted = self.is_blacklisted(self.current_user) post = {} post['slug'] = self.get_argument('slug', None) post['title'] = self.get_argument('title', '') post['url'] = self.get_argument('url', '') post['body_raw'] = self.get_argument('body_raw', '') post['tags'] = self.get_argument('tags', '').split(',') post['featured'] = self.get_argument('featured', '') post['has_hackpad'] = self.get_argument('has_hackpad', '') post['slug'] = self.get_argument('slug', '') post['sort_score'] = 0 post['daily_sort_score'] = 0 if post['has_hackpad'] != '': post['has_hackpad'] = True else: post['has_hackpad'] = False deleted = self.get_argument('deleted', '') if deleted != '': post['deleted'] = True post['date_deleted'] = datetime.datetime.now() bypass_dup_check = self.get_argument('bypass_dup_check', '') is_edit = False if post['slug']: bypass_dup_check = "true" is_edit = True dups = [] # make sure user isn't blacklisted if not self.is_blacklisted(self.current_user): # check if there is an existing URL if post['url'] != '': url = urlparse(post['url']) netloc = url.netloc.split('.') if netloc[0] == 'www': del netloc[0] path = url.path if path and path[-1] == '/': path = path[:-1] url = '%s%s' % ('.'.join(netloc), path) post['normalized_url'] = url long_url = post['url'] if long_url.find('goo.gl') > -1: long_url = google.expand_url(post['url']) if long_url.find('bit.ly') > -1 or long_url.find('bitly.com') > -1: long_url = bitly.expand_url(post['url'].replace('http://bitly.com','').replace('http://bit.ly','')) post['domain'] = urlparse(long_url).netloc ok_to_post = True dups = postsdb.get_posts_by_normalized_url(post.get('normalized_url', ""), 1) if post['url'] != '' and len(dups) > 0 and bypass_dup_check != "true": ## ## If there are dupes, kick them back to the post add form ## return (self.render('post/new_post.html', post=post, dups=dups)) # Handle tags post['tags'] = [t.strip().lower() for t in post['tags']] post['tags'] = [t for t in post['tags'] if t] userdb.add_tags_to_user(self.current_user, post['tags']) for tag in post['tags']: tagsdb.save_tag(tag) # format the content as needed post['body_html'] = sanitize.html_sanitize(post['body_raw'], media=self.current_user_can('post_rich_media')) post['body_text'] = sanitize.html_to_text(post['body_html']) post['body_truncated'] = sanitize.truncate(post['body_text'], 500) # determine if this should be a featured post or not if self.current_user_can('feature_posts') and post['featured'] != '': post['featured'] = True post['date_featured'] = datetime.datetime.now() else: post['featured'] = False post['date_featured'] = None user = userdb.get_user_by_screen_name(self.current_user) if not post['slug']: # No slug -- this is a new post. # initiate fields that are new post['disqus_shortname'] = settings.get('disqus_short_code') post['muted'] = False post['comment_count'] = 0 post['disqus_thread_id_str'] = '' post['sort_score'] = 0.0 post['downvotes'] = 0 post['hackpad_url'] = '' post['date_created'] = datetime.datetime.now() post['user_id_str'] = user['user']['id_str'] post['username'] = self.current_user post['user'] = user['user'] post['votes'] = 1 post['voted_users'] = [user['user']] #save it post['slug'] = postsdb.insert_post(post) msg = 'success' else: # this is an existing post. # attempt to edit the post (make sure they are the author) saved_post = postsdb.get_post_by_slug(post['slug']) if saved_post and self.current_user == saved_post['user']['screen_name']: # looks good - let's update the saved_post values to new values for key in post.keys(): saved_post[key] = post[key] # finally let's save the updates postsdb.save_post(saved_post) msg = 'success' # log any @ mentions in the post mentions = re.findall(r'@([^\s]+)', post['body_raw']) for mention in mentions: mentionsdb.add_mention(mention.lower(), post['slug']) # Send email to USVers if OP is staff if self.current_user in settings.get('staff'): subject = 'USV.com: %s posted "%s"' % (self.current_user, post['title']) if 'url' in post and post['url']: # post.url is the link to external content (if any) post_link = 'External Link: %s \n\n' % post['url'] else: post_link = '' post_url = "http://%s/posts/%s" % (settings.get('base_url'), post['slug']) text = '"%s" ( %s ) posted by %s. \n\n %s %s' % (post['title'].encode('ascii', errors='ignore'), post_url, self.current_user, post_link, post.get('body_text', "")) # now attempt to actually send the emails for u in settings.get('staff'): if u != self.current_user: acc = userdb.get_user_by_screen_name(u) if acc: self.send_email('*****@*****.**', acc['email_address'], subject, text) # Subscribe to Disqus # Attempt to create the post's thread acc = userdb.get_user_by_screen_name(self.current_user) thread_id = 0 try: # Attempt to create the thread. thread_details = disqus.create_thread(post, acc['disqus']['access_token']) thread_id = thread_details['response']['id'] except: try: # trouble creating the thread, try to just get the thread via the slug thread_details = disqus.get_thread_details(post) thread_id = thread_details['response']['id'] except: thread_id = 0 if thread_id != 0: # Subscribe a user to the thread specified in response disqus.subscribe_to_thread(thread_id, acc['disqus']['access_token']) # update the thread with the disqus_thread_id_str saved_post = postsdb.get_post_by_slug(post['slug']) saved_post['disqus_thread_id_str'] = thread_id postsdb.save_post(saved_post) if is_edit: self.redirect('/posts/%s?msg=updated' % post['slug']) else: self.redirect('/?msg=success&slug=%s' % post['slug'])
def get(self, day="today", page=1, sort_by="hot"): view = "list" sort_by = self.get_argument('sort_by', sort_by) page = abs(int(self.get_argument('page', page))) per_page = abs(int(self.get_argument('per_page', '20'))) msg = self.get_argument('msg', '') slug = self.get_argument('slug', '') new_post = None if slug: new_post = postsdb.get_post_by_slug(slug) featured_posts = postsdb.get_featured_posts(1) posts = [] post = {} hot_tags = tagsdb.get_hot_tags() is_today = False if day == "today": is_today = True day = datetime.datetime.today() else: day = datetime.datetime.strptime(day, "%Y-%m-%d") previous_day = day - datetime.timedelta(days=1) two_days_ago = previous_day - datetime.timedelta(days=1) day_str = str(datetime.date(day.year, day.month, day.day)) previous_day_str = str(datetime.date(previous_day.year, previous_day.month, previous_day.day)) two_days_ago_str = str(datetime.date(two_days_ago.year, two_days_ago.month, two_days_ago.day)) show_day_permalink = True infinite_scroll = False if self.request.path == ('/'): show_day_permalink = False infinite_scroll = True is_blacklisted = False if self.current_user: is_blacklisted = self.is_blacklisted(self.current_user) posts = postsdb.get_hot_posts_by_day(day) #posts = postsdb.get_hot_posts_24hr() previous_day_posts = postsdb.get_hot_posts_by_day(previous_day) #midpoint = (len(posts) - 1) / 2 # midpoint determines where post list breaks from size=md to size=sm midpoint = 7 hot_posts_past_week = postsdb.get_hot_posts_past_week() self.vars.update({ 'is_today': is_today, 'view': view, 'msg': msg, 'posts': posts, 'previous_day_posts': previous_day_posts, 'hot_posts_past_week': hot_posts_past_week, 'featured_posts': featured_posts, 'post': post, #'featured_posts': featured_posts, 'is_blacklisted': is_blacklisted, 'tags': hot_tags, 'day': day, 'day_str': day_str, 'previous_day': previous_day, 'previous_day_str': previous_day_str, 'two_days_ago': two_days_ago, 'two_days_ago_str': two_days_ago_str, 'show_day_permalink': show_day_permalink, 'infinite_scroll': infinite_scroll, 'midpoint': midpoint, 'new_post': new_post, 'datetime': datetime }) self.render('post/lists_posts.html', **self.vars)