macros.jinja 5.39 KB
Newer Older
Skia's avatar
Skia committed
1 2
{% from 'core/macros.jinja' import user_profile_link %}

3
{% macro display_forum(forum, user) %}
Skia's avatar
Skia committed
4
<div class="forum {% if forum.is_category %}category{% endif %}">
Skia's avatar
Skia committed
5 6 7 8 9 10 11 12 13 14 15 16 17
    <div class="ib w_big">
        {% if not forum.is_category %}
        <a class="ib w_big" href="{{ url('forum:view_forum', forum_id=forum.id) }}">
        {% else %}
        <div class="ib w_big">
        {% endif %}
            <h5>{{ forum.name }}</h5>
            <p>{{ forum.description }}</p>
        {% if not forum.is_category %}
        </a>
        {% else %}
        </div>
        {% endif %}
18
        {% if user.is_owner(forum) %}
19 20
        <a class="ib" href="{{ url('forum:edit_forum', forum_id=forum.id) }}">{% trans %}Edit{% endtrans %}</a>
        <a class="ib" href="{{ url('forum:delete_forum', forum_id=forum.id) }}">{% trans %}Delete{% endtrans %}</a>
21
        {% endif %}
Skia's avatar
Skia committed
22 23
    </div>
    {% if not forum.is_category %}
Skia's avatar
Skia committed
24 25
    <div class="ib w_small">
        <div class="ib w_medium">
Skia's avatar
Skia committed
26
            {{ forum.topic_number }}
Skia's avatar
Skia committed
27 28
        </div>
        <div class="ib w_medium">
Skia's avatar
Skia committed
29 30
            {% if forum.last_message %}
            {{ forum.last_message.author }} <br/>
Skia's avatar
Skia committed
31 32 33
            <a href="{{ forum.last_message.get_absolute_url() }}">
                {{ forum.last_message.date|localtime|date(DATETIME_FORMAT) }} {{ forum.last_message.date|localtime|time(DATETIME_FORMAT) }}
            </a>
Skia's avatar
Skia committed
34 35 36
            {% endif %}
        </div>
    </div>
Skia's avatar
Skia committed
37
    {% endif %}
Skia's avatar
Skia committed
38 39 40
</div>
{% endmacro %}

Skia's avatar
Skia committed
41 42 43 44 45 46 47 48 49 50 51
{% macro display_topic(topic, user, first_unread=False) %}
<div class="topic">
    <div class="ib w_medium">
        {% if first_unread %}
        <a class="ib w_big" href="{{ url('forum:view_topic', topic_id=topic.id) }}#first_unread">
        {% else %}
        <a class="ib w_big" href="{{ url('forum:view_topic', topic_id=topic.id) }}">
        {% endif %}
            <h5>{{ topic.title }}</h5>
            <p>{{ topic.description }}</p>
        </a>
52
        {% if user.can_edit(topic) %}
Skia's avatar
Skia committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
        <div class="ib" style="text-align: center;">
            <a href="{{ url('forum:edit_topic', topic_id=topic.id) }}">{% trans %}Edit{% endtrans %}</a>
        </div>
        {% endif %}
    </div>
    <div class="ib w_medium">
        <div class="ib w_medium">
            <div class="ib w_medium" style="text-align: center;">
                {{ user_profile_link(topic.author) }}
            </div>
            <div class="ib w_medium" style="text-align: center;">
                {{ topic.messages.count() }}
            </div>
        </div>
        <div class="ib w_medium" style="text-align: center;">
Skia's avatar
Skia committed
68
            {% set last_msg = topic.messages.order_by('id').select_related('author').last() %}
Skia's avatar
Skia committed
69 70 71 72 73 74
            {{ user_profile_link(last_msg.author) }} <br/>
            {{ last_msg.date|date(DATETIME_FORMAT) }} {{ last_msg.date|time(DATETIME_FORMAT) }}
        </div>
    </div>
</div>
{% endmacro %}
Skia's avatar
Skia committed
75

Skia's avatar
Skia committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
{% macro display_message(m, user, unread=False) %}
{% if user.can_view(m) %}
<div id="msg_{{ m.id }}" class="message {% if unread %}unread{% endif %}">
    <div class="msg_author {% if m.deleted %}deleted{% endif %}">
            {% if m.author.avatar_pict %}
        <img src="{{ m.author.avatar_pict.get_download_url() }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
        {% else %}
        <img src="{{ static('core/img/unknown.jpg') }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
        {% endif %}
        <br/>
        <strong><a href="{{ m.author.get_absolute_url() }}">{{ m.author.get_short_name() }}</a></strong>
    </div>
    <div class="msg_content  {% if m.deleted %}deleted{% endif %}" {% if m.id == first_unread_message_id %}id="first_unread"{% endif %}>
        <div style="display: inline-block; width: 74%;">
            {% if m.title %}
            <h5>{{ m.title }}</h5>
            {% endif %}
        </div>
        <div style="display: inline-block; width: 25%;">
            <span><a href="{{ url('forum:new_message', topic_id=m.topic.id) }}?quote_id={{ m.id }}">
                    {% trans %}Reply as quote{% endtrans %}</a></span>
            {% if user.can_edit(m) %}
            <span> <a href="{{ url('forum:edit_message', message_id=m.id) }}">{% trans %}Edit{% endtrans %}</a></span>
            {% endif %}
            {% if m.can_be_moderated_by(user) %}
            {% if m.deleted %}
            <span> <a href="{{ url('forum:undelete_message', message_id=m.id) }}">{% trans %}Undelete{% endtrans %}</a></span>
            {% else %}
            <span> <a href="{{ url('forum:delete_message', message_id=m.id) }}">{% trans %}Delete{% endtrans %}</a></span>
            {% endif %}
            {% endif %}
            <br/>
            <span>{{ m.date|localtime|date(DATETIME_FORMAT) }} {{ m.date|localtime|time(DATETIME_FORMAT) }}</span>
        </div>
        <hr>
        <div>
        {{ m.message|markdown }}
        </div>
        {% if m.can_be_moderated_by(user) %}
        <ul class="msg_meta">
        {% for meta in m.metas.select_related('user').order_by('id') %}
            <li style="background: {% if m.author == meta.user %}#bfffbf{% else %}#ffffbf{% endif %}">
                {{ meta.get_action_display() }} {{ meta.user.get_display_name() }}
                {% trans %} at {% endtrans %}{{ meta.date|localtime|time(DATETIME_FORMAT) }}
                {% trans %} the {% endtrans %}{{ meta.date|localtime|date(DATETIME_FORMAT)}}</li>
        {% endfor %}
        </ul>
        {% endif %}
    </div>
</div>
{{ m.mark_as_read(user) or "" }}
{% endif %}
{% endmacro %}