本文整理汇总了Python中view.invalidate_cache函数的典型用法代码示例。如果您正苦于以下问题:Python invalidate_cache函数的具体用法?Python invalidate_cache怎么用?Python invalidate_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了invalidate_cache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_article_submission
def process_article_submission(handler, article_type):
property_hash = restful.get_sent_properties(handler.request.get,
['title',
('body', get_sanitizer_func(handler, trusted_source=True)),
'legacy_id',
('format', get_format),
('published', get_datetime),
('updated', get_datetime),
('tags', get_tags),
('html', get_html, 'body', 'format'),
('permalink', permalink_funcs[article_type], 'title', 'published')])
if property_hash:
if 'tags' in property_hash:
property_hash['tag_keys'] = [get_tag_key(name)
for name in property_hash['tags']]
property_hash['format'] = 'html' # For now, convert all to HTML
property_hash['article_type'] = article_type
article = models.blog.Article(**property_hash)
article.set_associated_data(
{'relevant_links': handler.request.get('relevant_links'),
'amazon_items': handler.request.get('amazon_items')})
process_embedded_code(article)
article.put()
for key in article.tag_keys:
db.get(key).counter.increment()
do_sitemap_ping()
restful.send_successful_response(handler, '/' + article.permalink)
view.invalidate_cache()
else:
handler.error(400)
示例2: process_article_edit
def process_article_edit(handler, permalink):
# For http PUT, the parameters are passed in URIencoded string in body
body = handler.request.body
params = cgi.parse_qs(body)
for key,value in params.iteritems():
params[key] = value[0]
property_hash = restful.get_sent_properties(params.get,
['title',
('body', get_sanitizer_func(handler, trusted_source=True)),
('format', get_format),
('updated', get_datetime),
('tags', get_tags),
('html', get_html, 'body', 'format')])
if property_hash:
if 'tags' in property_hash:
property_hash['tag_keys'] = [get_tag_key(name)
for name in property_hash['tags']]
article = db.Query(models.blog.Article).filter('permalink =', permalink).get()
before_tags = set(article.tag_keys)
for key,value in property_hash.iteritems():
setattr(article, key, value)
after_tags = set(article.tag_keys)
for removed_tag in before_tags - after_tags:
db.get(removed_tag).counter.decrement()
for added_tag in after_tags - before_tags:
db.get(added_tag).counter.increment()
process_embedded_code(article)
article.put()
restful.send_successful_response(handler, '/' + article.permalink)
view.invalidate_cache()
else:
handler.error(400)
示例3: process_article_submission
def process_article_submission(handler, article_type):
property_hash = restful.get_hash_from_request(handler.request,
['title',
'body',
'format',
'legacy_id',
('published', get_datetime),
('updated', get_datetime),
('tags', get_tags),
('html', get_html, 'body', 'format'),
('permalink', permalink_funcs[article_type], 'title', 'published')])
article = model.Article(
permalink = property_hash['permalink'],
article_type = article_type,
title = property_hash['title'],
body = property_hash['body'],
html = property_hash['html'],
published = property_hash['published'],
updated = property_hash['updated'],
format = 'html') # We are converting everything to HTML from Drupal
# since it can mix formats within articles
fill_optional_properties(article, property_hash)
article.set_associated_data(
{'relevant_links': handler.request.get('relevant_links'),
'amazon_items': handler.request.get('amazon_items')})
article.put()
restful.send_successful_response(handler, '/' + article.permalink)
view.invalidate_cache()
示例4: delete
def delete(self, year, month, perm_stem):
permalink = year + '/' + month + '/' + perm_stem
logging.debug("Deleting blog entry %s", permalink)
article = db.Query(model.Article). \
filter('permalink =', permalink).get()
article.delete()
view.invalidate_cache()
restful.send_successful_response(self, "/")
示例5: delete
def delete(self, comment_id):
logging.info("Deleting comment %s", comment_id)
comment = models.blog.Comment.get(db.Key(comment_id))
article = comment.article
article.num_comments -= 1
article.put()
comment.delete()
view.invalidate_cache(article.permalink)
restful.send_successful_response(self, "/")
示例6: delete
def delete(self, category, year, month, perm_stem):
permalink = '/'.join((category, year, month, perm_stem))
logging.debug("Deleting %s entry %s" % (category, permalink))
article = db.Query(models.blog.Article). \
filter('permalink =', permalink).get()
for key in article.tag_keys:
db.get(key).counter.decrement()
article.delete()
view.invalidate_cache()
restful.send_successful_response(self, "/")
示例7: delete_entity
def delete_entity(query):
targets = query.fetch(limit=1)
if len(targets) > 0:
permalink = targets[0].permalink
logging.debug('Deleting %s %s', model_class, permalink)
targets[0].delete()
self.response.out.write('Deleted ' + permalink)
view.invalidate_cache()
else:
self.error(404)
示例8: delete
def delete(self, year, month, perm_stem):
permalink = 'blog/' + year + '/' + month + '/' + day + '/' + perm_stem
logging.debug("Deleting blog entry %s", permalink)
article = db.Query(models.blog.Article). \
filter('permalink =', permalink).get()
for key in article.tag_keys:
db.get(key).counter.decrement()
article.delete()
view.invalidate_cache()
restful.send_successful_response(self, "/")
示例9: delete
def delete(self, path):
logging.debug("Deleting article %s", path)
if path=='article': # hack to pick out the 'top' article for bulk delete
return delete_entity(self, models.blog.Article.all())
article = db.Query(models.blog.Article).filter('permalink =', path).get()
if not article: return self.error(404)
for key in article.tag_keys: db.get(key).counter.decrement()
article.delete()
view.invalidate_cache()
restful.send_successful_response(self, "/")
示例10: delete_entity
def delete_entity(handler, query):
target = query.get()
if not target:
return handler.response.set_status(204, 'No more entities')
if hasattr(target, 'title'): title = target.title
elif hasattr(target, 'name'): title = target.name
else: title = ''
logging.debug('Deleting %s', title)
target.delete()
handler.response.out.write('Deleted %s' % title)
view.invalidate_cache()
restful.send_successful_response(handler, "/")
示例11: put
def put(self, comment_id):
logging.debug("CommentHandler#put for comment %s", comment_id)
# For HTTP PUT, the parameters are passed in URIencoded string in body
sanitize_comment = get_sanitizer_func(self,
allow_attributes = ['href', 'src'],
blacklist_tags = ['img', 'script'])
body = self.request.body
params = cgi.parse_qs(body)
for key, value in params.iteritems():
params[key] = value[0]
if not isinstance(params[key], unicode):
params[key] = params[key].decode(config.APP['charset'])
tmp_hash = restful.get_sent_properties(self.request.get,
[('commentEmail', cgi.escape),
('commentHomepage', cgi.escape),
('commentTitle', cgi.escape),
('commentName', cgi.escape),
('commentBody', sanitize_comment)])
property_hash = {}
props = (("commentEmail", "email"), ("commentHomepage", "homepage"),
("commentTitle", "title"), ("commentBody", "body"),
('commentName', 'name'))
for pair in props:
if pair[0] in tmp_hash:
logging.debug("Copying '%s' from received properties to '%s' in property hash (value: %s)", pair[0], pair[1], str(tmp_hash[pair[0]]))
property_hash[pair[1]] = tmp_hash[pair[0]]
if property_hash:
comment = models.blog.Comment.get(db.Key(comment_id))
for key, value in property_hash.iteritems():
setattr(comment, key, value)
comment.put()
# Render just this comment and send it to client
view_path = view.find_file(view.templates, "gablog/blog/comment.html")
allow_comments = comment.article.allow_comments
if allow_comments is None:
age = (datetime.datetime.now() - comment.article.published).days
allow_comments = (age <= config.BLOG['comment_window'])
# response = template.render(os.path.join(config.APP['template_dir'], view_path),
response = render_to_string(os.path.join(config.APP['template_dir'], view_path),
{ 'comment': comment, "use_gravatars": config.BLOG["use_gravatars"],
"allow_comments": allow_comments, "user_is_admin":
users.is_current_user_admin()},
debug = config.DEBUG)
self.response.out.write(response)
view.invalidate_cache(comment.article.permalink)
else:
self.error(400)
示例12: delete_entity
def delete_entity(query):
targets = query.fetch(limit=1)
if len(targets) > 0:
if hasattr(targets[0], 'title'):
title = targets[0].title
elif hasattr(targets[0], 'name'):
title = targets[0].name
else:
title = ''
logging.debug('Deleting %s %s', model_class, title)
targets[0].delete()
self.response.out.write('Deleted ' + model_class + ' ' + title)
view.invalidate_cache()
else:
self.response.set_status(204, 'No more ' + model_class + ' entities')
示例13: process_article_edit
def process_article_edit(handler, permalink):
# For http PUT, the parameters are passed in URIencoded string in body
body = handler.request.body
params = cgi.parse_qs(body)
logging.debug(params)
article = db.Query(model.Article).filter('permalink =', permalink).get()
if 'title' in params:
article.title = params['title'][0]
if 'tags' in params:
article.tags = get_tags(params['tags'][0])
article.body = params['body'][0]
article.html = params['body'][0]
article.updated = get_datetime()
article.put()
restful.send_successful_response(handler, '/' + article.permalink)
view.invalidate_cache()
示例14: process_comment_submission
def process_comment_submission(handler, article):
if not article:
handler.error(404)
return
# 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
article_key = article.put()
property_hash = restful.get_hash_from_request(handler.request,
['name',
'email',
'title',
'body',
'thread',
('published', get_datetime)])
# Compute a comment key by hashing name, email, and body.
# If these aren't different, don't bother adding comment.
comment_key = str(
hash((property_hash['name'],
property_hash['email'],
property_hash['body'])))
comment = model.Comment(
permalink = comment_key,
body = property_hash['body'],
article = article_key,
thread = property_hash['thread'])
fill_optional_properties(comment, property_hash)
comment.put()
restful.send_successful_response(handler, '/' + comment.permalink)
view.invalidate_cache()
示例15: process_comment_submission
def process_comment_submission(handler, article):
sanitize_comment = get_sanitizer_func(handler,
allow_attributes=['href', 'src'],
blacklist_tags=['img'])
property_hash = restful.get_sent_properties(handler.request.get,
['name',
'email',
'homepage',
'title',
('body', sanitize_comment),
'key',
'thread', # If it's given, use it. Else generate it.
'captcha',
('published', get_datetime)])
# If we aren't administrator, abort if bad captcha
if not users.is_current_user_admin():
if property_hash.get('captcha', None) != get_captcha(article.key()):
logging.info("Received captcha (%s) != %s",
property_hash.get('captcha', None),
get_captcha(article.key()))
handler.error(401) # Unauthorized
return
if 'key' not in property_hash and 'thread' not in property_hash:
handler.error(401)
return
# Generate a thread string.
if 'thread' not in property_hash:
matchobj = re.match(r'[^#]+#comment-(?P<key>\w+)',
property_hash['key'])
if matchobj:
logging.debug("Comment has parent: %s", matchobj.group('key'))
comment_key = matchobj.group('key')
# TODO -- Think about GQL injection security issue since
# it can be submitted by public
parent = models.blog.Comment.get(db.Key(comment_key))
thread_string = parent.next_child_thread_string()
else:
logging.debug("Comment is off main article")
comment_key = None
thread_string = article.next_comment_thread_string()
if not thread_string:
handler.error(400)
return
property_hash['thread'] = thread_string
del property_hash['key']
# 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)
handler.error(400)
return
# Notify the author of a new comment (from matteocrippa.it)
if config.BLOG['send_comment_notification']:
recipient = "%s <%s>" % (config.BLOG['author'], config.BLOG['email'],)
body = ("A new comment has just been posted on %s/%s by %s."
% (config.BLOG['root_url'], article.permalink, comment.name))
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()