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()
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()