def get(self, static_id): user = users.get_current_user() params = { 'user': user, 'static_id': static_id } self.response.write(template.render('static/' + static_id + '.html', params))
def full_render(self, handler, template_info, more_params): """Render a dynamic page from scatch.""" logging.debug("Doing full render using template_file: %s", template_info['file']) url = handler.request.uri scheme, netloc, path, query, fragment = urlparse.urlsplit(url) global NUM_FULL_RENDERS if not path in NUM_FULL_RENDERS: NUM_FULL_RENDERS[path] = 0 NUM_FULL_RENDERS[path] += 1 # This lets us see % of cached views # in /admin/timings (see timings.py) tags = Tag.list() years = Year.get_all_years() # Define some parameters it'd be nice to have in views by default. template_params = { "current_url": url, "bloog_version": config.BLOG['bloog_version'], "user": users.get_current_user(), "user_is_admin": users.is_current_user_admin(), "login_url": users.create_login_url(handler.request.uri), "logout_url": users.create_logout_url(handler.request.uri), "blog": config.BLOG, "blog_tags": tags, "archive_years": years, } template_params.update(config.PAGE) template_params.update(more_params) return template.render(template_info['file'], template_params, debug=config.DEBUG, template_dirs=template_info['dirs'])
def full_render(self, handler, template_info, more_params): """Render a dynamic page from scatch.""" logging.debug("Doing full render using template_file: %s", template_info['file']) url = handler.request.uri scheme, netloc, path, query, fragment = urlparse.urlsplit(url) global NUM_FULL_RENDERS if not path in NUM_FULL_RENDERS: NUM_FULL_RENDERS[path] = 0 NUM_FULL_RENDERS[path] += 1 # This lets us see % of cached views # in /admin/timings (see timings.py) tags = Tag.list() # Define some parameters it'd be nice to have in views by default. template_params = { "current_url": url, "bloog_version": config.BLOG['bloog_version'], "user": users.get_current_user(), "user_is_admin": users.is_current_user_admin(), "login_url": users.create_login_url(handler.request.uri), "logout_url": users.create_logout_url(handler.request.uri), "blog": config.BLOG, "blog_tags": tags } template_params.update(config.PAGE) template_params.update(more_params) return template.render(template_info['file'], template_params, debug=config.DEBUG, template_dirs=template_info['dirs'])
def get(self, content_id): user = users.get_current_user() comments = Comment.get_by_content_id(content_id) params = { 'user': user, 'content_id': content_id, 'comments': comments } self.response.write(template.render('content/' + content_id + '.html', params))
def get(self): user = users.get_current_user() if (user): self.redirect('/home') else: params = { 'login_url': users.create_login_url(self.request.uri), 'login': self.request.get('login') } self.response.write(template.render('index.html', params))
def get(self): page = self.request.get('page', '1') page = int(page) user = users.get_current_user() awards = AwardModel.get_many(limit=NUMPERPAGE, offset=(page-1)*NUMPERPAGE) params = { 'user': user, 'awards': awards, 'page': page } self.response.write(template.render('award/list.html', params))
def get(self): page = self.request.get('page', '1') page = int(page) user = users.get_current_user() bidinfos = BidInformationModel.get_many(limit=NUMPERPAGE, offset=(page-1)*NUMPERPAGE) params = { 'user': user, 'bidinfos': bidinfos, 'page': page } self.response.write(template.render('bidinfo/list.html', params))
def full_render(self, handler, params): "Carrega e popula o arquivo de template do handler" template_path, ctype = get_view_file(handler) full_template_path = path.join(config.TEMPLATES_DIR, template_path) # se o template não existe... if not path.exists( full_template_path ): logging.debug("template '%s' não existe." % full_template_path) if config.DEBUG: template_path = config.MISSING_TMPL ctype = guess_type(template_path) params = {"template":full_template_path} return template.render(template_path, params), ctype else: handler.redirect("/404.xhtml") return { "file":template_path, "body":template.render(template_path, params, debug=config.DEBUG), "content_type":ctype }
def get_line_item(self, ref_id, line_item_id): user = users.get_current_user() bidinfo = BidInformationModel.getOne(ref_id) bidinfo = bidinfo[0] org = OrganizationModel.getOne(bidinfo['org_id']) org = org[0] lineitem = BidInformationModel.getLineItem(ref_id, line_item_id) lineitem = lineitem[0] print bidinfo params = { 'user': user, 'bidinfo': bidinfo, 'org': org, 'lineitem': lineitem } self.response.write(template.render('bidinfo/line_item.html', params))
def get_one(self, ref_id): user = users.get_current_user() bidinfo = BidInformationModel.getOne(ref_id) bidinfo = bidinfo[0] lineitems = BidInformationModel.getLineItems(ref_id) org = OrganizationModel.getOne(bidinfo['org_id']) org = org[0] print bidinfo for key, val in bidinfo.items(): bidinfo[key] = parseutil.process(val) params = { 'user': user, 'bidinfo': bidinfo, 'org': org, 'lineitems': lineitems } self.response.write(template.render('bidinfo/item.html', params))
def get_one(self, award_id): user = users.get_current_user() award = AwardModel.getOne(award_id) award = award[0] bidinfo = BidInformationModel.getOne(award['ref_id']) flag = Flag.get_by_award_email(award_id, user.email()) print '------------------------' print flag.get() if '_id' in bidinfo: for key, val in bidinfo.items(): bidinfo[key] = parseutil.process(val) params = { 'user': user, 'award': award, 'bidinfo': bidinfo, 'flag': flag.get() } self.response.write(template.render('award/item.html', params))
def get(self): #self.response.write(template.render('d3/test.html', {})) self.response.write(template.render('test/email.html', {}))
def process_comment_submission(handler, parent=None): sanitize_comment = get_sanitizer_func(handler, allow_attributes=['href', 'src'], blacklist_tags=['img', 'script']) property_hash = restful.get_sent_properties( handler.request.get, [('name', cgi.escape), ('email', cgi.escape), ('homepage', cgi.escape), ('title', cgi.escape), ('body', sanitize_comment), ('article_id', cgi.escape), 'recaptcha_challenge_field', 'recaptcha_response_field', ('published', get_datetime)]) # If we aren't administrator, abort if bad captcha if not users.is_current_user_admin(): cap_challenge = property_hash.get('recaptcha_challenge_field') cap_response = property_hash.get('recaptcha_response_field') cap_validation = captcha.RecaptchaResponse(False) if cap_challenge and cap_response: cap_validation = captcha.submit(cap_challenge, cap_response, config.BLOG['recap_private_key'], handler.request.remote_addr) if not cap_validation.is_valid: logging.info("Invalid captcha: %s", cap_validation.error_code) handler.response.set_status(401, 'Invalid Captcha') # Unauthorized return if 'article_id' not in property_hash: return handler.error(400) article = db.Query(models.blog.Article).filter( 'permalink =', property_hash['article_id']).get() # Generate a thread string. if parent: logging.debug("Comment has parent: %s", parent.key()) thread_string = parent.next_child_thread_string() else: logging.debug("Comment is off main article") thread_string = article.next_comment_thread_string() property_hash['thread'] = thread_string # Get and store some pieces of information from parent article. # TODO: See if this overhead can be avoided if not article.num_comments: article.num_comments = 1 else: article.num_comments += 1 property_hash['article'] = article.put() try: comment = models.blog.Comment(**property_hash) comment.put() except: logging.debug("Bad comment: %s", property_hash) return handler.error(400) # Notify the author of a new comment (from matteocrippa.it) if config.BLOG[ 'send_comment_notification'] and not users.is_current_user_admin(): recipient = "%s <%s>" % (config.BLOG['author'], config.BLOG['email']) article_link = config.BLOG['root_url'] + "/" + article.permalink comment_link = '%s#comment-%s' % (article_link, comment.key()) body = ('''A new comment has just been posted on %s by %s:\n\n"%s" \n\nReply to the comment here: %s''' % (article_link, comment.name, comment.body, comment_link)) mail.send_mail(sender=config.BLOG['email'], to=recipient, subject="New comment by %s" % (comment.name), body=body) # Render just this comment and send it to client view_path = view.find_file(view.templates, "bloog/blog/comment.html") response = template.render(os.path.join("views", view_path), { 'comment': comment, "use_gravatars": config.BLOG["use_gravatars"] }, debug=config.DEBUG) handler.response.out.write(response) view.invalidate_cache(comment.article.permalink)
def process_comment_submission(handler, parent=None): sanitize_comment = get_sanitizer_func(handler, allow_attributes=['href', 'src'], blacklist_tags=['img', 'script']) property_hash = restful.get_sent_properties(handler.request.get, [('name', cgi.escape), ('email', cgi.escape), ('homepage', cgi.escape), ('title', cgi.escape), ('body', sanitize_comment), ('article_id', cgi.escape), 'recaptcha_challenge_field', 'recaptcha_response_field', ('published', get_datetime)]) # If we aren't administrator, abort if bad captcha if not users.is_current_user_admin(): cap_challenge = property_hash.get('recaptcha_challenge_field') cap_response = property_hash.get('recaptcha_response_field') cap_validation = captcha.RecaptchaResponse(False) if cap_challenge and cap_response: cap_validation = captcha.submit( cap_challenge, cap_response, config.BLOG['recap_private_key'], handler.request.remote_addr ) if not cap_validation.is_valid: logging.info( "Invalid captcha: %s", cap_validation.error_code ) handler.response.set_status(401, 'Invalid Captcha') # Unauthorized return if 'article_id' not in property_hash: return handler.error(400) article = db.Query(models.blog.Article).filter( 'permalink =', property_hash['article_id'] ).get() # Generate a thread string. if parent: logging.debug("Comment has parent: %s", parent.key()) thread_string = parent.next_child_thread_string() else: logging.debug("Comment is off main article") thread_string = article.next_comment_thread_string() property_hash['thread'] = thread_string # Get and store some pieces of information from parent article. # TODO: See if this overhead can be avoided if not article.num_comments: article.num_comments = 1 else: article.num_comments += 1 property_hash['article'] = article.put() try: comment = models.blog.Comment(**property_hash) comment.put() except: logging.debug("Bad comment: %s", property_hash) return handler.error(400) # Notify the author of a new comment (from matteocrippa.it) if config.BLOG['send_comment_notification'] and not users.is_current_user_admin(): recipient = "%s <%s>" % (config.BLOG['author'], config.BLOG['email']) article_link = config.BLOG['root_url'] + "/" + article.permalink comment_link = '%s#comment-%s' % (article_link, comment.key()) body = ('''A new comment has just been posted on %s by %s:\n\n"%s" \n\nReply to the comment here: %s''' % (article_link, comment.name, comment.body, comment_link)) mail.send_mail(sender=config.BLOG['email'], to=recipient, subject="New comment by %s" % (comment.name), body=body) # Render just this comment and send it to client view_path = view.find_file(view.templates, "bloog/blog/comment.html") response = template.render( os.path.join("views", view_path), { 'comment': comment, "use_gravatars": config.BLOG["use_gravatars"] }, debug=config.DEBUG) handler.response.out.write(response) view.invalidate_cache(comment.article.permalink)