flask 留言板页面(flask 65)

2019-08-15 18:56:04 浏览数 (1)

代码语言:javascript复制
        <div class="comments" id="comments">
            <h3>{{ pagination.total }} Comments
                <small>
                    <a href="{{ url_for('.show_post', post_id=post.id, page=pagination.pages or 1) }}#comments">
                        latest</a>
                </small>
                {% if current_user.is_authenticated %}
                    <form class="float-right" method="post"
                          action="{{ url_for('admin.set_comment', post_id=post.id, next=request.full_path) }}">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                        <button type="submit" class="btn btn-warning btn-sm">
                            {% if post.can_comment %}Disable{% else %}Enable{% endif %} Comment
                        </button>
                    </form>
                {% endif %}
            </h3>
            {% if comments %}
                <ul class="list-group">
                    {% for comment in comments %}
                        <li class="list-group-item list-group-item-action flex-column">
                            <div class="d-flex w-100 justify-content-between">
                                <h5 class="mb-1">
                                    <a href="{% if comment.site %}{{ comment.site }}{% else %}#{% endif %}"
                                       target="_blank">
                                        {% if comment.from_admin %}
                                            {{ admin.name }}
                                        {% else %}
                                            {{ comment.author }}
                                        {% endif %}
                                    </a>
                                    {% if comment.from_admin %}
                                        <span class="badge badge-primary">Author</span>{% endif %}
                                    {% if comment.replied %}<span class="badge badge-light">Reply</span>{% endif %}
                                </h5>
                                <small data-toggle="tooltip" data-placement="top" data-delay="500"
                                       data-timestamp="{{ comment.timestamp.strftime('%Y-%m-%dT%H:%M:%SZ') }}">
                                    {{ moment(comment.timestamp).fromNow() }}
                                </small>
                            </div>
                            {% if comment.replied %}
                                <p class="alert alert-dark reply-body">{{ comment.replied.author }}:
                                    <br>{{ comment.replied.body }}
                                </p>
                            {%- endif -%}
                            <p class="mb-1">{{ comment.body }}</p>
                            <div class="float-right">
                                <a class="btn btn-light btn-sm"
                                   href="{{ url_for('.reply_comment', comment_id=comment.id) }}">Reply</a>
                                {% if current_user.is_authenticated %}
                                    <a class="btn btn-light btn-sm" href="mailto:{{ comment.email }}">Email</a>
                                    <form class="inline" method="post"
                                          action="{{ url_for('admin.delete_comment', comment_id=comment.id, next=request.full_path) }}">
                                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                                        <button type="submit" class="btn btn-danger btn-sm"
                                                onclick="return confirm('Are you sure?');">Delete
                                        </button>
                                    </form>
                                {% endif %}
                            </div>
                        </li>
                    {% endfor %}
                </ul>
            {% else %}
                <div class="tip"><h5>No comments.</h5></div>
            {% endif %}
        </div>
        {% if comments %}
            {{ render_pagination(pagination, fragment='#comments') }}
        {% endif %}
        {% if request.args.get('reply') %}
            <div class="alert alert-dark">
                Reply to <strong>{{ request.args.get('author') }}</strong>:
                <a class="float-right" href="{{ url_for('.show_post', post_id=post.id) }}">Cancel</a>
            </div>
        {% endif %}
        {% if post.can_comment %}
            <div id="comment-form">
                {{ render_form(form, action=request.full_path) }}
            </div>
        {% else %}
            <div class="tip"><h5>Comment disabled.</h5></div>
        {% endif %}
    </div>

0 人点赞