def _copyCommentToForm(self, comment, article_key=None, author=None): """Copy relevant fields from Comment to CommentForm.""" cf = CommentForm() if not author: author = Author.query()\ .filter(Author.authorID==comment.authorID)\ .get() if not article_key: article_key = comment.key.parent() for field in cf.all_fields(): if hasattr(comment, field.name): # convert Date to date string if field.name.startswith('date'): setattr(cf, field.name, str(getattr(comment, field.name))) else: setattr(cf, field.name, getattr(comment, field.name)) # add the fields that are not part of the Comment model elif field.name == "websafeCommentKey": setattr(cf, field.name, comment.key.urlsafe()) elif field.name == "websafeArticleKey": setattr(cf, field.name, article_key.urlsafe()) elif field.name == "websafeAuthorKey": setattr(cf, field.name, author.key.urlsafe()) cf.check_initialized() return cf