def format_comment(comment, is_reply=False, is_team=False, replies=None): """Format a comment node into a simpler dictionary. :param comment: the comment object :param is_reply: True if the comment is a reply to another comment :param is_team: True if the author belongs to the group that owns the node :param replies: list of replies (formatted with this function) """ try: is_own = (current_user.objectid == comment.user._id) \ if current_user.is_authenticated() else False except AttributeError: bugsnag.notify(Exception('Missing user for embedded user ObjectId'), meta_data={'nodes_info': { 'node_id': comment['_id'] }}) return is_rated = False is_rated_positive = None if comment.properties.ratings: for rating in comment.properties.ratings: if current_user.is_authenticated( ) and rating.user == current_user.objectid: is_rated = True is_rated_positive = rating.is_positive continue return dict(_id=comment._id, gravatar=gravatar(comment.user.email, size=32), time_published=pretty_date(comment._created), rating_up=comment.properties.rating_positive, rating_down=comment.properties.rating_negative, author=comment.user.full_name, content=comment.properties.content, is_reply=is_reply, is_own=is_own, is_rated=is_rated, is_rated_positive=is_rated_positive, is_team=is_team, replies=replies)
def format_comment(comment, is_reply=False, is_team=False, replies=None): """Format a comment node into a simpler dictionary. :param comment: the comment object :param is_reply: True if the comment is a reply to another comment :param is_team: True if the author belongs to the group that owns the node :param replies: list of replies (formatted with this function) """ try: is_own = (current_user.objectid == comment.user._id) \ if current_user.is_authenticated() else False except AttributeError: bugsnag.notify(Exception('Missing user for embedded user ObjectId'), meta_data={'nodes_info': {'node_id': comment['_id']}}) return is_rated = False is_rated_positive = None if comment.properties.ratings: for rating in comment.properties.ratings: if current_user.is_authenticated() and rating.user == current_user.objectid: is_rated = True is_rated_positive = rating.is_positive continue return dict(_id=comment._id, gravatar=gravatar(comment.user.email, size=32), time_published=pretty_date(comment._created), rating_up=comment.properties.rating_positive, rating_down=comment.properties.rating_negative, author=comment.user.full_name, content=comment.properties.content, is_reply=is_reply, is_own=is_own, is_rated=is_rated, is_rated_positive=is_rated_positive, is_team=is_team, replies=replies)
def notification_parse(notification): if notification.actor: username = notification.actor['username'] avatar = notification.actor['avatar'] else: return None return dict( _id=notification['_id'], username=username, username_avatar=avatar, action=notification.action, object_type=notification.object_type, object_name=notification.object_name, object_url=url_for( 'nodes.redirect_to_context', node_id=notification.object_id), context_object_type=notification.context_object_type, context_object_name=notification.context_object_name, context_object_url=url_for( 'nodes.redirect_to_context', node_id=notification.context_object_id), date=pretty_date(notification['_created']), is_read=notification.is_read, is_subscribed=notification.is_subscribed, subscription=notification.subscription )
def pretty_edit_date(self): return pretty_date(self.edit_date)
def pretty_creation_date(self): return pretty_date(self.creation_date)
def notification_parse(notification): notification_object = NotificationObject.query.get(notification.notification_object_id) actor = User.query.get_or_404(notification_object.actor_user_id) # Context is optional context_object_type = None context_object_name = None context_object_url = None if notification_object.object_type_id == 2: # Initial support only for comments comment = Comment.query.get_or_404(notification_object.object_id) post = comment.post object_type = "comment" object_name = "" post_url = url_for("posts.view", category=post.category.url, uuid=post.uuid, slug=post.slug) # Handmade anchor appended to url object_url = "{0}#comment-{1}".format(post_url, comment.id) if comment.parent_id: context_object_type = "comment" parent_comment = Comment.query.get(comment.parent_id) if parent_comment.user_id == current_user.id: owner = "your comment" else: owner = "{0}'s comment".format(parent_comment.user.username) context_object_name = owner context_object_url = "{0}#comment-{1}".format(post_url, comment.parent_id) else: context_object_type = "post" context_object_name = post.title context_object_url = post_url if notification_object.verb == "replied": action = "replied to" elif notification_object.verb == "commented": action = "left a comment on" else: action = notification_object.verb return dict( _id=notification.id, username=actor.username, username_avatar=actor.gravatar(), username_url=url_for("users.view", user_id=actor.id), action=action, object_type=object_type, object_name=object_name, object_url=object_url, context_object_type=context_object_type, context_object_name=context_object_name, context_object_url=context_object_url, date=pretty_date(notification_object.date_creation), is_read=notification.is_read, is_subscribed=notification.is_subscribed, )
def notification_parse(notification): notification_object = NotificationObject.query\ .get(notification.notification_object_id) actor = User.query.get_or_404(notification_object.actor_user_id) # Context is optional context_object_type = None context_object_name = None context_object_url = None if notification_object.object_type_id == 2: # Initial support only for comments comment = Comment.query.get_or_404(notification_object.object_id) post = comment.post object_type = 'comment' object_name = '' post_url = url_for( 'posts.view', category=post.category.url, uuid=post.uuid, slug=post.slug, ) # Handmade anchor appended to url object_url = "{0}#comment-{1}".format(post_url, comment.id) if comment.parent_id: context_object_type = 'comment' parent_comment = Comment.query.get(comment.parent_id) if parent_comment.user_id == current_user.id: owner = 'your comment' else: owner = "{0}'s comment".format(parent_comment.user.username) context_object_name = owner context_object_url = "{0}#comment-{1}".format( post_url, comment.parent_id) else: context_object_type = 'post' context_object_name = post.title context_object_url = post_url if notification_object.verb == 'replied': action = 'replied to' elif notification_object.verb == 'commented': action = 'left a comment on' else: action = notification_object.verb return dict(_id=notification.id, username=actor.username, username_avatar=actor.gravatar(), username_url=url_for('users.view', user_id=actor.id), action=action, object_type=object_type, object_name=object_name, object_url=object_url, context_object_type=context_object_type, context_object_name=context_object_name, context_object_url=context_object_url, date=pretty_date(notification_object.date_creation), is_read=notification.is_read, is_subscribed=notification.is_subscribed)