def build_comment_model_from_fb_comment(json_comment): comment = Comment(user_fb_id=json_comment["from"]["id"], created_at=Utils.parse_utf_format_datetime(json_comment["created_time"]), text=json_comment["message"]) choosie_user = CacheController.get_user_by_fb_id(json_comment["from"]["id"]) if choosie_user is None: comment.is_scraped = True comment.scraped_user_details = str(ScrapeCommentsHandler.build_user_details(json_comment)) return comment
def get_serialized_comments(self): # updated_post.comments is a StringListProperty. Each comment_str is inflated to a dictionary # that looks like: # {"text": "blahblah", # "user": {"fb_uid": "152343", # ...} # } return [Comment.from_string_for_choosie_post(comment_str) for comment_str in self.comments if comment_str]
def post(self): fb_uid = str(self.request.get('fb_uid')) # TODO: Make sure text is Unicode text = self.request.get('text') # Since the post is taken from the cache, it might not be the most updated version # but that's ok, as it is only used as 'parent' choosie_post = CacheController.get_model(self.request.get('post_key')) comment = Comment(parent=choosie_post, user_fb_id=self.request.get('fb_uid'), text=text) comment.put() choosie_post.add_comment_to_post(comment) # Make sure the ChoosiePost's comments are invalidated in cache, so that next time # they are asked for, the updated are retreived. Comment.invalidate_comments(self.request.get('post_key')) self.response.write('Comment added.')
def get_serialized_comments(self): # updated_post.comments is a StringListProperty. Each comment_str is inflated to a dictionary # that looks like: # {"text": "blahblah", # "user": {"fb_uid": "152343", # ...} # } return [ Comment.from_string_for_choosie_post(comment_str) for comment_str in self.comments if comment_str ]
def get_cached_comments(self): return Comment.get_comments_for_post(str(self.key()))