-1

Helo. I am trying to list all the comments from one user and a topic that the comment belongs to, but i get double values in comment_list.html. I think i am not nesting it properly.

My Python hadler is following:

class CommentsListHandler(BaseHandler):
def get(self):
    user = users.get_current_user()
    comments = Comment.query(Comment.deleted==False, Comment.author_email==user.email()).fetch()
    topics = Topic.query(Topic.deleted==False).fetch()
    params = {"comments": comments, "topics": topics}
    return self.render_template("comments_list.html", params=params)

My jinja2 is following:

{% for comment in comments|sort(attribute='created') %}
    {% for topic in topics %}
 <div class="panel panel-warning">
        <div class="panel-heading">{{ comment.author_email }} on {{ comment.created.strftime("%d.%m.%Y at %H:%M") }}
            in topic: <a href="/topic-details/{{topic.key.id()}}"> {{ topic.title }} </a></div>
        <div class="panel-body">
            <p>{{ comment.content }}</p>
        </div>
 </div>

    {% endfor %}
{% endfor %}

I would realy appreciate your help. Thank you in advance.

Brg

luckie
  • 9
  • 4
  • Can you add what your actual output looks like vs. what you are the expected HTML would like to be with a sample user, comment and topic? – alpeware May 20 '17 at 14:26

1 Answers1

0

I have managed to solve it:

{% for comment in comments|sort(attribute='created') %}
    {% for topic in topics %}
        {% if topic.key.id() == comment.topic_id %}
 <div class="panel panel-warning">
        <div class="panel-heading">{{ comment.author_email }} on {{ comment.created.strftime("%d.%m.%Y at %H:%M") }}
            in topic: <a href="/topic-details/{{topic.key.id()}}"> {{ topic.title }} </a></div>
        <div class="panel-body">
            <p>{{ comment.content }}</p>
        </div>
 </div>
        {% endif %}
    {% endfor %}
{% endfor %}
luckie
  • 9
  • 4