def get(self): # load articles in from db and github, stuff them in an array date_format = "%a, %d %b %Y" blog_title = "The %s Blog" % config.app_name epoch_start = datetime.datetime(1970, 1, 1) blog_last_updated = epoch_start entries = [] # fetch our articles articles = models.Article.get_all() for article in articles[0:10]: gist_content = github.get_gist_content(article.gist_id) if gist_content: # sanitize article_html = bleach.clean(gist_content, config.bleach_tags, config.bleach_attributes) article_title = bleach.clean(article.title) article_summary = bleach.clean(article.summary) # look up owner owner_info = models.User.get_by_id(article.owner.id()) if article.updated > blog_last_updated: blog_last_updated = article.updated entry = { 'slug': article.slug, 'article_type': article.article_type, 'created': article.created, 'author_email': owner_info.email, 'author_username': owner_info.username, 'updated': article.updated, 'title': article_title, 'summary': article_summary, 'html': article_html, } if not article.draft: entries.append(entry) # didn't get any matches in our loop date_format = "%a, %d %b %Y %H:%M:%S GMT" if blog_last_updated == epoch_start: blog_last_updated = datetime.datetime.utcnow().strftime( date_format) else: blog_last_updated = blog_last_updated.strftime(date_format) params = { 'blog_title': blog_title, 'blog_last_updated': blog_last_updated, 'site_host': self.request.host, 'entries': entries, } self.response.headers['Content-Type'] = 'application/xml' return self.render_template('blog/feed.xml', **params)
def get(self): # load articles in from db and github, stuff them in an array date_format = "%a, %d %b %Y" blog_title = "The %s Blog" % config.app_name epoch_start = datetime.datetime(1970, 1, 1) blog_last_updated = epoch_start entries = [] # fetch our articles articles = models.Article.get_all() for article in articles[0:10]: gist_content = github.get_gist_content(article.gist_id) if gist_content: # sanitize article_html = bleach.clean(gist_content, config.bleach_tags, config.bleach_attributes) article_title = bleach.clean(article.title) article_summary = bleach.clean(article.summary) # look up owner owner_info = models.User.get_by_id(article.owner.id()) if article.updated > blog_last_updated: blog_last_updated = article.updated entry = { 'slug': article.slug, 'article_type': article.article_type, 'created': article.created, 'author_email': owner_info.email, 'author_username': owner_info.username, 'updated': article.updated, 'title': article_title, 'summary': article_summary, 'html': article_html, } if not article.draft: entries.append(entry) # didn't get any matches in our loop date_format = "%a, %d %b %Y %H:%M:%S GMT" if blog_last_updated == epoch_start: blog_last_updated = datetime.datetime.utcnow().strftime(date_format) else: blog_last_updated = blog_last_updated.strftime(date_format) params = { 'blog_title': blog_title, 'blog_last_updated': blog_last_updated, 'site_host': self.request.host, 'entries': entries, } self.response.headers['Content-Type'] = 'application/xml' return self.render_template('blog/feed.xml', **params)
def get(self, username=None): # load articles in from db and github, stuff them in an array articles = models.Article.get_blog_posts(1) # loop through all articles blogposts = [] for article in articles: # if there's content on Github to serve raw_gist_content = github.get_gist_content(article.gist_id) # if github gist exists for the entry if raw_gist_content: article_html = bleach.clean(raw_gist_content, config.bleach_tags, config.bleach_attributes) article_title = bleach.clean(article.title) # created and by whom date_format = "%a, %d %b %Y" created = article.created.strftime(date_format) owner_info = models.User.get_by_id(article.owner.id()) # build entry entry = { 'created': created, 'article_id': article.key.id(), 'article_title': article_title, 'article_type': article.article_type, 'article_html': article_html, 'article_slug': article.slug, 'article_owner': owner_info.username, 'article_host': self.request.host, } blogposts.append(entry) # show other recent articles in sidebar articles = models.Article.get_blog_posts(5) archives = [] for article in articles: owner_info = models.User.get_by_id(article.owner.id()) article_title = bleach.clean(article.title) entry = { 'article_title': article_title, 'article_type': article.article_type, 'article_slug': article.slug, 'article_owner': owner_info.username, 'article_host': self.request.host, } archives.append(entry) # see if we have any blog posts - unlikely we don't if len(blogposts) > 0: params = {'blogpost': blogposts[0], 'archives': archives} else: params = {'blogpost': {}} return self.render_template('site/home.html', **params)
def get(self, username=None): # load articles in from db and github, stuff them in an array articles = models.Article.get_blog_posts(1) # loop through all articles blogposts = [] for article in articles: # if there's content on Github to serve raw_gist_content = github.get_gist_content(article.gist_id) # if github gist exists for the entry if raw_gist_content: article_html = bleach.clean(raw_gist_content, config.bleach_tags, config.bleach_attributes) article_title = bleach.clean(article.title) # created and by whom date_format = "%a, %d %b %Y" created = article.created.strftime(date_format) owner_info = models.User.get_by_id(article.owner.id()) # build entry entry = { 'created': created, 'article_id': article.key.id(), 'article_title': article_title, 'article_type': article.article_type, 'article_html': article_html, 'article_slug': article.slug, 'article_owner': owner_info.username, 'article_host': self.request.host, } blogposts.append(entry) # show other recent articles in sidebar articles = models.Article.get_blog_posts(5) archives = [] for article in articles: owner_info = models.User.get_by_id(article.owner.id()) article_title = bleach.clean(article.title) entry = { 'article_title': article_title, 'article_type': article.article_type, 'article_slug': article.slug, 'article_owner': owner_info.username, 'article_host': self.request.host, } archives.append(entry) # see if we have any blog posts - unlikely we don't if len(blogposts) > 0: params = {'blogpost': blogposts[0], 'archives': archives} else: params = {'blogpost': {} } return self.render_template('site/home.html', **params)
def get(self): # load articles in from db and github, stuff them in an array date_format = "%a, %d %b %Y" articles = models.Article.get_all() blogposts = [] # loop through all articles for article in articles: # if there's content on Github to serve try: gist_content = github.get_gist_content(article.gist_id) except: continue if gist_content: # sanitize javascript article_html = bleach.clean(gist_content, config.bleach_tags, config.bleach_attributes) article_title = bleach.clean(article.title) article_summary = bleach.clean(article.summary) # created and by whom created = article.created.strftime(date_format) owner_info = models.User.get_by_id(article.owner.id()) # build entry entry = { 'created': created, 'article_id': article.key.id(), 'article_title': article_title, 'article_type': article.article_type, 'article_html': article_html, 'article_summary': article_summary, 'article_slug': article.slug, 'article_owner': owner_info.username, 'article_host': self.request.host, } # append article if it's a guide, it's public, and not a draft if article.article_type == 'post' and article.public and not article.draft: blogposts.append(entry) # pack and stuff into template params = {'blogposts': blogposts} return self.render_template('blog/blog.html', **params)
def get(self, username=None): owner_info = models.User.get_by_username(username) if not owner_info: params = {} return self.redirect_to('home', **params) # load name if not owner_info.name: name = bleach.clean(owner_info.username) else: name = "%s %s" % (bleach.clean( owner_info.name), bleach.clean(owner_info.last_name)) # find the browsed user's github username (used for follow button) owner_social_user = models.SocialUser.get_by_user_and_provider( owner_info.key, 'github') twitter_user = models.SocialUser.get_by_user_and_provider( owner_info.key, 'twitter') # load github usernames try: owner_github_username = owner_social_user.uid github_username = social_user.uid except: owner_github_username = None github_username = None # load bio if not owner_info.bio: bio = "User has not completed their bio." else: bio = bleach.clean(owner_info.bio) # load avatar if not owner_info.gravatar_url: gravatar_url = config.gravatar_url_stub else: gravatar_url = owner_info.gravatar_url # load articles in from db and github, stuff them in seperate arrays date_format = "%a, %d %b %Y" articles = models.Article.get_by_user(owner_info.key) blogposts = [] guides = [] # loop through all articles and build a list of both posts and articles for article in articles: # if there's content on Github to serve gist_content = github.get_gist_content(article.gist_id) if gist_content: # sanitize javascript article_html = bleach.clean(gist_content, config.bleach_tags, config.bleach_attributes) article_title = bleach.clean(article.title) article_summary = bleach.clean(article.summary) created = article.created.strftime(date_format) entry = { 'created': created, 'article_id': article.key.id(), 'article_title': article_title, 'article_html': article_html, 'article_type': article.article_type, 'article_slug': article.slug, 'article_summary': article_summary, 'article_host': self.request.host, 'article_owner': bleach.clean( owner_info.username ), # TODO: may not be correct if they have forked another user's article? } # we switch between adding to the two lists here # will need video handling eventually if gist_content and not article.draft: if article.article_type == 'post': blogposts.append(entry) else: guides.append(entry) # add extra single entry items, and then add the posts and guides seperately params = { 'bio': bio, 'name': name, 'blog_username': username, 'owner_github_username': owner_github_username, 'google_plus_profile': owner_info.google_plus_profile, 'gravatar_url': gravatar_url, 'twitter_username': twitter_user.screen_name, 'twitter_widget_id': owner_info.twitter_widget_id, 'blogposts': blogposts, 'guides': guides, } return self.render_template('blog/blog_user.html', **params)
def get(self, username=config.admin_username, article_type='guides', slug=None): # look up our owner user = models.User.get_by_username(username) # look up the article try: article = models.Article.get_by_user_and_slug(user.key, slug) if not article: return self.render_template('errors/default_error.html') except: return self.render_template('errors/default_error.html') gist_content = github.get_gist_content(article.gist_id) # if there's content on Github to serve if gist_content: twitter_user = models.SocialUser.get_by_user_and_provider( user.key, 'twitter') owner_info = models.User.get_by_id(article.owner.id()) # twitter widget stuff if twitter_user: twitter_username = twitter_user.screen_name twitter_widget_id = owner_info.twitter_widget_id else: twitter_username = config.app_twitter_username twitter_widget_id = config.app_twitter_widget_id # set nav menu pill if 'guide' in article_type: menu_choice = 'guides' else: menu_choice = 'blog' # load name if not owner_info.name: name = owner_info.username else: name = "%s %s" % (owner_info.name, owner_info.last_name) # load github use try: github_username = social_user.uid except: github_username = None # load articles in from db and github, stuff them in an array date_format = "%a, %d %b %Y" # sanitize javascript article_html = bleach.clean(gist_content, config.bleach_tags, config.bleach_attributes) article_title = bleach.clean(article.title) article_summary = bleach.clean(article.summary) # serve page if we have contents created = article.created.strftime(date_format) entry = { 'created': created, 'article_id': article.key.id(), 'article_title': article_title, 'article_html': article_html, 'article_slug': article.slug, 'article_type': article.article_type, 'article_owner': owner_info.username, 'article_host': self.request.host, #'twitter_username': twitter_username, } # pack and stuff into template - duplicate on article_type TODO params = { 'name': name, 'github_username': github_username, 'twitter_username': twitter_username, 'twitter_widget_id': twitter_widget_id, 'article_type': article_type, 'menu_choice': menu_choice, 'entry': entry, } return self.render_template('blog/blog_article_detail.html', **params) else: params = {} return self.render_template('errors/default_error.html', **params)
def get(self, username = None): owner_info = models.User.get_by_username(username) if not owner_info: params = {} return self.redirect_to('home', **params) # load name if not owner_info.name: name = bleach.clean(owner_info.username) else: name = "%s %s" % (bleach.clean(owner_info.name), bleach.clean(owner_info.last_name)) # find the browsed user's github username (used for follow button) owner_social_user = models.SocialUser.get_by_user_and_provider(owner_info.key, 'github') twitter_user = models.SocialUser.get_by_user_and_provider(owner_info.key, 'twitter') # load github usernames try: owner_github_username = owner_social_user.uid github_username = social_user.uid except: owner_github_username = None github_username = None # load bio if not owner_info.bio: bio = "User has not completed their bio." else: bio = bleach.clean(owner_info.bio) # load avatar if not owner_info.gravatar_url: gravatar_url = config.gravatar_url_stub else: gravatar_url = owner_info.gravatar_url # load articles in from db and github, stuff them in seperate arrays date_format = "%a, %d %b %Y" articles = models.Article.get_by_user(owner_info.key) blogposts = [] guides = [] # loop through all articles and build a list of both posts and articles for article in articles: # if there's content on Github to serve gist_content = github.get_gist_content(article.gist_id) if gist_content: # sanitize javascript article_html = bleach.clean(gist_content, config.bleach_tags, config.bleach_attributes) article_title = bleach.clean(article.title) article_summary = bleach.clean(article.summary) created = article.created.strftime(date_format) entry = { 'created': created, 'article_id': article.key.id(), 'article_title': article_title, 'article_html': article_html, 'article_type': article.article_type, 'article_slug': article.slug, 'article_summary': article_summary, 'article_host': self.request.host, 'article_owner': bleach.clean(owner_info.username), # TODO: may not be correct if they have forked another user's article? } # we switch between adding to the two lists here # will need video handling eventually if gist_content and not article.draft: if article.article_type == 'post': blogposts.append(entry) else: guides.append(entry) # add extra single entry items, and then add the posts and guides seperately params = { 'bio': bio, 'name': name, 'blog_username': username, 'owner_github_username': owner_github_username, 'google_plus_profile': owner_info.google_plus_profile, 'gravatar_url': gravatar_url, 'twitter_username': twitter_user.screen_name, 'twitter_widget_id': owner_info.twitter_widget_id, 'blogposts': blogposts, 'guides': guides, } return self.render_template('blog/blog_user.html', **params)
def get(self, username=config.admin_username, article_type='guides', slug = None): # look up our owner user = models.User.get_by_username(username) # look up the article try: article = models.Article.get_by_user_and_slug(user.key, slug) if not article: return self.render_template('errors/default_error.html') except: return self.render_template('errors/default_error.html') gist_content = github.get_gist_content(article.gist_id) # if there's content on Github to serve if gist_content: twitter_user = models.SocialUser.get_by_user_and_provider(user.key, 'twitter') owner_info = models.User.get_by_id(article.owner.id()) # twitter widget stuff if twitter_user: twitter_username = twitter_user.screen_name twitter_widget_id = owner_info.twitter_widget_id else: twitter_username = config.app_twitter_username twitter_widget_id = config.app_twitter_widget_id # set nav menu pill if 'guide' in article_type: menu_choice = 'guides' else: menu_choice = 'blog' # load name if not owner_info.name: name = owner_info.username else: name = "%s %s" % (owner_info.name, owner_info.last_name) # load github use try: github_username = social_user.uid except: github_username = None # load articles in from db and github, stuff them in an array date_format = "%a, %d %b %Y" # sanitize javascript article_html = bleach.clean(gist_content, config.bleach_tags, config.bleach_attributes) article_title = bleach.clean(article.title) article_summary = bleach.clean(article.summary) # serve page if we have contents created = article.created.strftime(date_format) entry = { 'created': created, 'article_id': article.key.id(), 'article_title': article_title, 'article_html': article_html, 'article_slug': article.slug, 'article_type': article.article_type, 'article_owner': owner_info.username, 'article_host': self.request.host, #'twitter_username': twitter_username, } # pack and stuff into template - duplicate on article_type TODO params = { 'name': name, 'github_username': github_username, 'twitter_username': twitter_username, 'twitter_widget_id': twitter_widget_id, 'article_type': article_type, 'menu_choice': menu_choice, 'entry': entry, } return self.render_template('blog/blog_article_detail.html', **params) else: params = {} return self.render_template('errors/default_error.html', **params)