macros.jinja 5.58 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
        </div>
Skia's avatar
Skia committed
28
        <div class="ib w_medium" style="font-size: x-small; text-align: center">
Skia's avatar
Skia committed
29 30
            {% if forum.last_message %}
            {{ forum.last_message.author }} <br/>
Skia's avatar
Skia committed
31
            <a href="{{ forum.last_message.get_absolute_url() }}">
Skia's avatar
Skia committed
32 33 34
                {{ forum.last_message.date|localtime|date(DATETIME_FORMAT) }}
                {{ forum.last_message.date|localtime|time(DATETIME_FORMAT) }}<br/>
                {{ forum.last_message.topic }}
Skia's avatar
Skia committed
35
            </a>
Skia's avatar
Skia committed
36 37 38
            {% endif %}
        </div>
    </div>
Skia's avatar
Skia committed
39
    {% endif %}
Skia's avatar
Skia committed
40 41 42
</div>
{% endmacro %}

Skia's avatar
Skia committed
43 44 45 46
{% macro display_topic(topic, user, first_unread=False) %}
<div class="topic">
    <div class="ib w_medium">
        {% if first_unread %}
Skia's avatar
Skia committed
47
        <a class="ib w_big" href="{{ topic.get_first_unread_message(user).get_absolute_url() }}">
Skia's avatar
Skia committed
48 49 50 51 52 53
        {% 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>
54
        {% if user.can_edit(topic) %}
Skia's avatar
Skia committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        <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
70
            {% set last_msg = topic.messages.order_by('id').select_related('author').last() %}
Skia's avatar
Skia committed
71
            {{ user_profile_link(last_msg.author) }} <br/>
Skia's avatar
Skia committed
72 73 74
            <a href="{{ last_msg.get_absolute_url() }}">
                {{ last_msg.date|date(DATETIME_FORMAT) }} {{ last_msg.date|time(DATETIME_FORMAT) }}
            </a>
Skia's avatar
Skia committed
75 76 77 78
        </div>
    </div>
</div>
{% endmacro %}
Skia's avatar
Skia committed
79

Skia's avatar
Skia committed
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 130 131 132 133
{% 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 %}