summaryrefslogtreecommitdiffstats
path: root/askbot/skins/default/templates/macros.html
blob: 6bb4a5d7bdabf2b7091a8a2bfbd1e9e80a80c216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
{%- macro user_score_and_badge_summary(user) -%}
    <span class="reputation-score"
          title="{{user.get_karma_summary}}"
    >{{user.reputation}}</span>
    {% if user.gold or user.silver or user.bronze %}
    <span title="{{user.get_badge_summary}}">
        {% if user.gold %}
        <span class='badge1'>&#9679;</span>
        <span class="badgecount">{{user.gold}}</span>
        {% endif %}
        {% if user.silver %}
        <span class='badge2'>&#9679;</span>
        <span class="badgecount">{{user.silver}}</span>
        {% endif %}
        {% if user.bronze %}
        <span class='badge3'>&#9679;</span>
        <span class="badgecount">{{user.bronze}}</span>
        {% endif %}
    </span>
    {% endif %}
{%- endmacro -%}

{%- macro user_long_score_and_badge_summary(user) -%}
    <a class="user-micro-info" 
       href="{{user.get_absolute_url()}}?sort=reputation"
    >{% trans %}karma:{% endtrans %} {{user.reputation}}</a>
    {% if user.gold or user.silver or user.bronze %}
    <a class="user-micro-info"
       href="{{user.get_absolute_url()}}#badges"
    ><span title="{{user.get_badge_summary}}">{% trans %}badges:{% endtrans %}
        {% if user.gold %}
        <span class='badge1'>&#9679;</span>
        <span class="badgecount">{{user.gold}}</span>
        {% endif %}
        {% if user.silver %}
        <span class='badge2'>&#9679;</span>
        <span class="badgecount">{{user.silver}}</span>
        {% endif %}
        {% if user.bronze %}
        <span class='badge3'>&#9679;</span>
        <span class="badgecount">{{user.bronze}}</span>
        {% endif %}
    </span></a>
    {% endif %}
{%- endmacro -%}

{%- macro paginator(p) -%}{# p is paginator context dictionary #}
{% spaceless %}
    {% if p.is_paginated %}
        <div class="paginator">
        {% if p.has_previous %}
            <span class="prev"><a href="{{p.base_url}}page={{ p.contextprevious }}{{ p.extend_url }}" title="{% trans %}previous{% endtrans %}">
        &laquo; {% trans %}previous{% endtrans %}</a></span>
        {% endif %}
        {% if not p.in_leading_range %}
            {% for num in p.pages_outside_trailing_range %}
                <span class="page"><a href="{{p.base_url}}page={{ num }}{{ p.extend_url }}" >{{ num }}</a></span>
            {% endfor %}
        ...
        {% endif %}
         
        {% for num in p.page_numbers %}
          {% if num == p.page and p.pages != 1%}
            <span class="curr" title="{% trans %}current page{% endtrans %}">{{ num }}</span>
          {% else %}
            <span class="page"><a href="{{p.base_url}}page={{ num }}{{ p.extend_url }}" title="{% trans %}page number {{num}}{% endtrans %}">{{ num }}</a></span>
          {% endif %}
        {% endfor %}
         
        {% if not p.in_trailing_range %}
            ...
            {% for num in p.pages_outside_leading_range|reverse %}
                <span class="page"><a href="{{p.base_url}}page={{ num }}{{ p.extend_url }}" title="{% trans %}page number {{ num }}{% endtrans %}">{{ num }}</a></span>
            {% endfor %}
        {% endif %}
        {% if p.has_next %}
            <span class="next"><a href="{{p.base_url}}page={{ next }}{{ p.extend_url }}" title="{% trans %}next page{% endtrans %}">{% trans %}next page{% endtrans %} &raquo;</a></span>
        {% endif %}
        </div> 
    {% endif %}
{% endspaceless %}
{%- endmacro -%}

{%- macro pagesize_switch(p) -%}{# p is paginator context #}
{% spaceless %}
{% if p.is_paginated %}
    <div class="paginator">
        <span class="text">{% trans %}posts per page{% endtrans %}</span>
        {% if p.page_size == 10 %}
            <span class="curr">10</span>
        {% else %}
            <span class="page"><a href="{{p.base_url}}page_size=10">10</a></span>
        {% endif %}
        
        {% if p.page_size == 30 %}
            <span class="curr">30</span>
        {% else %}
            <span class="page"><a href="{{p.base_url}}page_size=30">30</a></span>
        {% endif %}
        
        {% if p.page_size == 50 %}
            <span class="curr">50</span>
        {% else %}
            <span class="page"><a href="{{p.base_url}}page_size=50">50</a></span>
        {% endif %}
    </div> 
{% endif %}
{% endspaceless %}
{%- endmacro -%}

{%- macro gravatar(user, size) -%}
{% spaceless %}
<a style="text-decoration:none"
    href="{{user.get_absolute_url()}}"
><img class="gravatar" 
    width="{{size}}" height="{{size}}"
    src="http://www.gravatar.com/avatar/{{user.gravatar}}s?s={{size}}&amp;d=identicon&amp;r=PG"
    title="{{user.username}}" 
    alt="{% trans username=user.username %}{{username}} gravatar image{% endtrans %}" 
/></a>
{% endspaceless %}
{%- endmacro -%}

{%- macro post_contributor_info(post, contributor_type, is_wiki, wiki_min_rep) -%}
<div class='post-update-info'>
{# there is a whole bunch of trickery here, probably indicative of 
poor design of the data or methods on data objects #}
{% if contributor_type=="original_author" %}
    {% if is_wiki %}
        <p style="line-height:12px">
           {%- if post.__class__.__name__ == 'Question' -%}
                {%- trans %}asked{% endtrans %}
           {% elif post.__class__.__name__ == 'Answer' %}
                {%- trans %}answered{% endtrans %}
           {% else %}
                {%- trans %}posted{% endtrans %}
           {% endif %}
           <strong>{{post.added_at|diff_date}}</strong>
        </p>
        <img 
            src="{{'/images/wiki.png'|media}}"
            alt="{% trans %}this post is marked as community wiki{% endtrans %}"
            style="float:left"
        />
        <p class="tip">{% trans %}This post is a wiki.
        Anyone with karma &gt;{{wiki_min_rep}} is welcome to improve it.{% endtrans %}</p>
    {% else %}
        <p style="line-height:12px;">
            {# todo: access to class names needs to be removed here #}
            {% if post.__class__.__name__=="Question" %}
                {% trans %}asked{% endtrans %}
            {% elif post.__class__.name__=="Answer" %}
                {% trans %}answered{% endtrans %}
            {% else %}
                {% trans %}posted{% endtrans %}
            {% endif %}
            {% if post.__class__.__name__ in ('QuestionRevision', 'AnswerRevision') %}
                <strong>{{post.revised_at|diff_date}}</strong>
            {% else %}
                <strong>{{post.added_at|diff_date}}</strong>
            {% endif %}
        </p>
        {{ gravatar(post.author, 32) }}
        <p>{{post.author.get_profile_link()}}<br/>
        {{ user_score_and_badge_summary(post.author) }}</p>
    {% endif %}
{% else %}
    {% if post.__class__.__name__ in ('Question', 'Answer') %}
        {% set last_edited_at = post.last_edited_at %}
        {% set original_author = post.author %}
        {% set update_author = post.last_edited_by %}
    {% elif post.__class__.__name__ in ('QuestionRevision', 'AnswerRevision') %}
        {% set last_edited_at = post.revised_at %}
        {% set original_author = None %}{# fake value to force display widget in the revision views #}
        {% set update_author = post.author %}
    {% endif %}
    {% if last_edited_at %}
        <p style="line-height:12px;">
            <a 
        {% if post.__class__.__name__ == 'Question' %}
            href="{% url question_revisions post.id %}"
        {% else %}
            href="{% url answer_revisions post.id %}"
        {% endif %}
            >{% trans %}updated{% endtrans %} <strong>{{ last_edited_at|diff_date }}</strong></a>
        </p>
        {% if original_author != update_author or is_wiki %}
            {{ gravatar(update_author, 32) }}
            <p style="float:left">{{update_author.get_profile_link()}}<br/>
            {{ user_score_and_badge_summary(update_author) }}</p>
        {% endif %}
    {% endif %}
{% endif %}
</div>
{%- endmacro -%}

{%- macro question_summary(question, extra_class=None) -%}
    <div class="short-summary{% if extra_class %} {{extra_class}}{% endif %}">
        <div class="counts">
            <div class="votes">
                <span 
                    class="item-count 
                        {% if question.score == 0 -%}
                            no-votes
                        {% else -%}
                            some-votes
                        {%- endif -%}"
                >{{question.score|humanize_counter}}</span>
                <div>
                {% trans cnt=question.score %}vote{% pluralize %}votes{% endtrans %}
                </div>
            </div>
            <div class="votes"> 
                <span 
                    class="item-count
                    {% if question.answer_count == 0 -%}
                        no-answers
                    {% else -%}
                        {%- if question.answer_accepted -%}
                            accepted
                        {%- else -%}
                            some-answers
                        {%- endif -%}
                    {%- endif -%}"
                >{{question.answer_count|humanize_counter}}{% if question.answer_accepted%}&#10003;{% endif %}</span>
                <div>
                {% trans cnt=question.answer_count %}answer{% pluralize %}answers{% endtrans %}
                </div>
            </div>
            <div class="votes">
                 <span class="item-count
                 {% if question.view_count == 0 -%}
                    no-views
                 {% else -%}
                    some-views
                 {%- endif -%}"
                 >{{question.view_count|humanize_counter}}</span>
                <div>
                {% trans cnt=question.view_count %}view{% pluralize %}views{% endtrans %}
                </div>
            </div>
        </div>
        <h2><a title="{{question.summary|escape}}" href="{{ question.get_absolute_url() }}">{{question.title|escape}}</a></h2>
        <div class="userinfo">
            <span class="relativetime" title="{{question.last_activity_at}}">{{ question.last_activity_at|diff_date }}</span>
            <a href="{% url user_profile question.last_activity_by.id, question.last_activity_by.username|slugify %}">{{question.last_activity_by.username}}</a>
            {{user_score_and_badge_summary(question.last_activity_by)}}
        </div>
        <div class="tags">
            {% for tag in question.get_tag_names() %}
            <a href="{% url questions %}?tags={{tag|urlencode}}" title="{% trans %}see questions tagged '{{ tag }}'{% endtrans %}" rel="tag">{{ tag }}</a>
            {% endfor %}
        </div>
    </div>
{%- endmacro -%}