def create(cls, text_value, logged_user, topic): new_comment = cls( content=text_value, author_email=logged_user.email(), topic_id=topic.key.id(), topic_title=topic.title, ) new_comment.put() subscriptions = TopicSubscription.query(TopicSubscription.topic_id == topic.key.id()).fetch() subscribers = [topic.author_email, ] for subscription in subscriptions: if subscription.user_email != logged_user.email(): subscribers.append(subscription.user_email) # send notification to topic author and subscribers for topic.author_email in subscribers: taskqueue.add( url='/task/email-new-comment', params={"topic-author-email": topic.author_email, "topic-title": topic.title, "topic-id": topic.key.id(), } ) return new_comment
def create(cls, content, user, topic): """Class method to create new comment. :param content: Content text :type content: str :param user: Author user :type user: User :param topic: Topic where the comment belongs to :type topic: Topic :return: New comment """ user_email = normalize_email(user.email()) new_comment = cls( content=escape_html(content), topic_id=topic.key.id(), topic_title=topic.title, author_email=user_email, ) new_comment.put() subscriptions = TopicSubscription.query( TopicSubscription.topic_id == topic.key.id()).fetch() subscribers = [ topic.author_email, ] for subscription in subscriptions: if subscription.user_email != user_email: subscribers.append(subscription.user_email) # Send notification to topic author and subscribers. for email in subscribers: params = { 'topic-author-email': email, 'topic-title': topic.title, 'topic-id': topic.key.id(), } taskqueue.add(url='/task/email-new-comment', params=params) return new_comment