summaryrefslogtreecommitdiffstats
path: root/askbot/skins/default/templates/macros.html
blob: 27dddfb969336d7d44c13e802cc9467dc92be202 (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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
{%- macro share(site = None, site_label = None, icon = False) -%}
    <a class="{{ site }}-share{% if icon == True %} icon{% endif %}"
        title="{% trans %}Share this question on {{site}}{% endtrans %}"
    >{% if icon == False %}{% if site_label %}{{ site_label }}{% else %}{{ site }}{% endif %}{% endif %}</a>
{%- endmacro -%}

{%- macro follow_toggle(follow, name, alias, id) -%}
    {# follow - boolean; name - object type name; alias - e.g. users name; id - object id #}
    <div 
        class="follow-toggle" 
        id="follow-{{ name }}-{{ id }}"
    >
        {% if follow %}
        <div class="follow">{% trans %}follow {{alias}}{% endtrans %}</div>
        {% else %}
        <div class="unfollow">
          <div class="unfollow-red">{% trans %}unfollow {{alias}}{% endtrans %}</div>
          <div class="unfollow-green">{% trans %}following {{alias}}{% endtrans %}</div>
        </div>
        {% endif %}
    </div>
{%- endmacro -%}

{%- macro post_vote_buttons(post = None, visitor_vote = None) -%}
<div
    id="{{post.post_type}}-img-upvote-{{ post.id }}"
    class="{{post.post_type}}-img-upvote post-vote{% if visitor_vote == 1 %} on{% endif %}" 
    {% if post.post_type == 'question' %}
        title="{% trans %}i like this question (click again to cancel){% endtrans %}"
    {% else %}
        title="{% trans %}i like this answer (click again to cancel){% endtrans %}"
    {% endif %}
/></div>
<div 
    id="{{post.post_type}}-vote-number-{{ post.id }}"
    class="vote-number"
    title="{% trans %}current number of votes{% endtrans %}"
>{{ post.score }}</div>
<div
    id="{{post.post_type}}-img-downvote-{{ post.id }}"
    class="{{post.post_type}}-img-downvote post-vote{% if visitor_vote == -1 %} on{% endif %}" 
    {% if post.post_type == 'question' %}
        title="{% trans %}i dont like this question (click again to cancel){% endtrans %}" 
    {% else %}
        title="{% trans %}i dont like this answer (click again to cancel){% endtrans %}" 
    {% endif %}
/></div>
{%- endmacro -%}

{%- macro post_contributor_avatar_and_credentials(post, user) -%}
    {% if post.is_anonymous %}
        <img alt="{% trans %}anonymous user{% endtrans %}" src="{{ '/images/anon.png'|media }} " class="gravatar" width="32" height="32" />
        <p>{{ user.get_anonymous_name() }}</p>
    {% else %}
        {{ gravatar(user, 32) }}
        {{ user.get_profile_link()}}{{ user_country_flag(user) }}<br/>
        {{ user_score_and_badge_summary(user) }}<br/>
        {{ user_website_link(user) }}
    {% endif %}
{%- endmacro -%}

{%- macro post_contributor_info(post, contributor_type, is_wiki, wiki_min_rep) -%}
{# 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" %}
    <div class='post-update-info'>
    {% if is_wiki %}
        <p>
           {%- if post.post_type == 'question' -%}
                {%- trans %}asked{% endtrans %}
           {% elif post.post_type == 'answer' %}
                {%- trans %}answered{% endtrans %}
           {% else %}
                {%- trans %}posted{% endtrans %}
           {% endif %}
           <strong>{{post.added_at|diff_date}}</strong>
        </p>
        <img width="35" height="35"
            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.post_type == 'question' %}
                {% trans %}asked{% endtrans %}
            {% elif post.post_type == 'answer' %}
                {% trans %}answered{% endtrans %}
            {% else %}
                {% trans %}posted{% endtrans %}
            {% endif %}
            {% if post.__class__.__name__ == 'PostRevision' %}
                <strong>{{post.revised_at|diff_date}}</strong>
            {% else %}
                <strong>{{post.added_at|diff_date}}</strong>
            {% endif %}
        </p>
        {{ post_contributor_avatar_and_credentials(post, post.author) }}
    {% endif %}
    </div>
{% elif contributor_type=="last_updater" %}
    {% if post.post_type 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__ == 'PostRevision' %}
        {% 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 %}
    <div class='post-update-info'>
        <p style="line-height:12px;">
            <a 
        {% if post.post_type == '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 %}
            {{ post_contributor_avatar_and_credentials(post, update_author) }}
        {% endif %}
    </div>
    {% endif %}
{% endif %}
{%- endmacro -%}

{%- macro post_last_updater_and_creator_info(post, min_rep_to_edit_wiki) -%}
    {{ 
       post_contributor_info(
            post,
            "original_author",
            post.wiki,
            min_rep_to_edit_wiki
        )
    }}
    {{ 
        post_contributor_info(
            post,
            "last_updater",
            post.wiki,
            min_rep_to_edit_wiki,
        )
    }}
{%- endmacro -%}

{%- macro if_else(condition, if_true, if_false) -%}
    {%- if condition == True -%}
        {{if_true}}
    {%- else -%}
        {{if_false}}
    {%- endif -%}
{%- endmacro -%}

{%- macro tag_cloud(tags = None, font_sizes = None) -%}
    {% for tag in tags %}
    <span class="tag-size-{{ font_sizes[tag.name] }}">
        <a class="link-typeA" title="Number of entries: {{ tag.used_count }}" href="{% url questions %}?tags={{ tag.name }}">{{ tag.name }}</a>
    </span>
    {% endfor %}
{%- endmacro -%}

{%- macro tag_list_widget(
        tags,
        id = None,
        deletable = False,
        make_links = True,
        url_params = None,
        css_class = None,
        tag_css_class = None,
        tag_html_tag = 'li'
    )
-%}
<ul {% if id %}id="{{ id }}"{% endif %}
    class="tags{% if css_class %} {{css_class}}{% endif %}"
>
    {% if tags %}
        {% for tag in tags %}
            {{ tag_widget(
                tag,
                css_class = tag_css_class,
                deletable = deletable,
                is_link = make_links,
                url_params = url_params,
                html_tag = tag_html_tag 
            )}}
        {% endfor %}
    {% endif %}
</ul>
{%- endmacro -%}

{# todo: remove the extra content argument to make its usage more explicit #}
{%- macro tag_widget(
            tag,
            deletable = False,
            is_link = True,
            delete_link_title = None,
            css_class = None,
            url_params = None,
            html_tag = 'div',
            extra_content = ''
        )
-%}
    {% spaceless %}
    <{{ html_tag }} class="tag-left{% if deletable %} deletable-tag{% endif %}">
    <{% if not is_link or tag[-1] == '*' %}span{% else %}a{% endif %}
            class="tag tag-right{% if css_class %} {{ css_class }}{% endif %}"
            {% if is_link %}
            href="{% url questions %}?tags={{tag|urlencode}}{{ 
                                                        if_else(
                                                            url_params != None,
                                                            '&' ~ url_params,
                                                            ''
                                                        )|escape
                                                    }}"
            title="{% trans %}see questions tagged '{{ tag }}'{% endtrans %}"
            {% endif %}
            rel="tag"
        >{{ tag|replace('*', '&#10045;')|truncate(20,True)}}</{% if not is_link or tag[-1] == '*' %}span{% else %}a{% endif %}>
        {% if deletable %}
            <div class="delete-icon"
                {% if delete_link_title %}
                    title="{{ delete_link_title }}"
                {% endif %}
            >x</div>
        {% endif %}
    </{{ html_tag }}>
    {{ extra_content }}
    {% endspaceless %}
{%- endmacro -%}

{%- macro radio_select(name = None, value = None, choices = None) -%}
    {% for choice in choices %}
        <p class="choice">
            {% set id = "id_" ~ name ~ "_" ~ choice[0] %}
            <input 
                id="{{ id }}"
                name="{{ name }}"
                value="{{ choice[0] }}"
                type="radio"
                {% if value == choice[0] %}
                checked="checked"
                {% endif %}
            />
            <label for="{{ id }}">{{ choice[1] }}</label>
        </p>
    {% endfor %}
{%- endmacro -%}

{%- macro question_summary(question, extra_class=None) -%}
{%include "widgets/question_summary.html" %}
{%- endmacro -%}

{%- macro comment_votes(comment = None) -%}
    <div class="comment-votes">
        {% if comment.score > 0 %}
        <div class="upvote{% if comment.upvoted_by_user %} upvoted{% endif %}">{{comment.score}}</div>
        {% else %}
        <div class="upvote"></div>
        {% endif %}
    </div>
{%- endmacro -%}

{# Warning! Any changes to the comment markup here must be duplicated in post.js
for the purposes of the AJAX comment editor #}

{%- macro comment_list(comments = None, user = None) -%}
    {% for comment in comments %}
    <div class="comment" id="comment-{{comment.id}}">
        {{ comment_votes(comment = comment) }}
        <div class="comment-delete">
            {% if user|can_delete_comment(comment) %}
                <span class="delete-icon" title="{% trans %}delete this comment{% endtrans %}"></span>
            {% endif %}
        </div>
        <div class="comment-body">
            {{comment.html}}
            <a 
                class="author" 
                href="{{comment.user.get_profile_url()}}"
            >{{comment.user.username}}</a>
            <span class="age">&nbsp;({{comment.added_at|diff_date}})</span>
            {% if user|can_edit_comment(comment) %}
                <a class="edit">{% trans %}edit{% endtrans %}</a>
            {% endif %}
        </div>
    </div>
    {% endfor %}
{%- endmacro -%}

{%- macro add_or_show_comments_button(post = None, can_post = None, max_comments = None, widget_id = None) -%}
    <script type="text/javascript">
        askbot['data']['{{widget_id}}'] = {
            can_post: {% if can_post %}true{% else %}false{% endif %},
            truncated: {% if post.comment_count > max_comments %}true{% else %}false{% endif %}
        };
    </script>
    {% if post.comment_count > max_comments %}
        {% set remaining_comments = post.comment_count - max_comments %}
        <a class="button">
        {% if can_post %}
            {% trans %}add comment{% endtrans %} /
            {% trans counter=remaining_comments %}see <strong>{{counter}}</strong> more{% pluralize %}see <strong>{{counter}}</strong> more{% endtrans %}
        {% else %}
            {% trans counter=remaining_comments %}see <strong>{{counter}}</strong> more comment{% pluralize %}see <strong>{{counter}}</strong> more comments
            {% endtrans %}
        {% endif %}
        </a>
    {% elif can_post %}
        <a class="button">{% trans %}add comment{% endtrans %}</a>
    {% endif %}
{%- endmacro -%}

{%- macro post_comments_widget(
        post=None,
        show_post = None,
        show_comment = None,
        show_comment_position = None,
        user=None,
        max_comments=None
    )
-%}
    {% spaceless %}
    {% if post.comment_count > 0 %}
        <h2 id="comment-title">Comments</h2>
    {% endif %}
    {% set widget_id = 'comments-for-' + post.post_type + '-' + post.id|string %}
    <div class="comments" id="{{widget_id}}">
        <div class="content">
            {% if show_post == post and show_comment %}
                {% if show_comment_position > max_comments %}
                    {% set comments = post.get_comments(visitor = user)[:show_comment_position] %}
                    {{ comment_list(comments = comments, user = user) }}
                {% else %}
                    {% set comments = post.get_comments(visitor = user)[:max_comments] %}
                    {{ comment_list(comments = comments, user = user) }}
                {% endif %}
            {% else %}
                {% set comments = post.get_comments(visitor = user)[:max_comments] %}
                {{ comment_list(comments = comments, user = user) }}
            {% endif %}
        </div>
        <div class="controls">
            {% set can_post = user|can_post_comment(post) %}
            {% if show_post == post and show_comment %}
                {% if show_comment_position > max_comments %}
                    {{
                        add_or_show_comments_button(
                                            post = post,
                                            can_post = can_post,
                                            max_comments = show_comment_position,
                                            widget_id = widget_id
                                        )
                    }}
                {% else %}
                    {{
                        add_or_show_comments_button(
                                            post = post,
                                            can_post = can_post,
                                            max_comments = max_comments,
                                            widget_id = widget_id
                                        )
                    }}
                {% endif %}
            {% else %}
                {{
                    add_or_show_comments_button(
                                        post = post,
                                        can_post = can_post,
                                        max_comments = max_comments,
                                        widget_id = widget_id
                                    )
                }}
            {% endif %}
        </div>
    </div>
    {% endspaceless %}
{%- endmacro -%}

{%- macro reversible_sort_button(button_sort_criterium=None, asc_tooltip=None,
            desc_tooltip=None, label=None, current_sort_method=None) -%}
{# 
    sort button where descending sort is default
    and the search method is togglable between ascending and descending 
    buttons are rendered as links with id constructed as
    "by_" + button_sort_criterium
    class "on" is added when current_sort_method is one of
    button_sort_criterium + "asc" or "desc"
#}
    {% set key_name = button_sort_criterium %}
    {% set sort = current_sort_method %}
    {% if sort == key_name + "-asc" %}{# "worst" first #}
    <a id="by_{{key_name}}" 
        href="?sort={{key_name}}-desc" 
        class="rev on" 
        title="{{desc_tooltip}}"><span>{{label}} &#9650;</span></a>
    {% elif sort == key_name + "-desc" %}{# "best first" #}
    <a id="by_{{key_name}}"
        href="?sort={{key_name}}-asc" 
        class="rev on"
        title="{{asc_tooltip}}"><span>{{label}} &#9660;</span></a>
    {% else %}{# default, when other button is active #}
    <a id="by_{{key_name}}"
        href="?sort={{key_name}}-desc" 
        class="off"
        title="{{desc_tooltip}}"><span>{{label}}</span></a>
    {% endif %}
    <script type="text/javascript">{# need to pass on text translations to js #}
        var sortButtonData = sortButtonData || {};
        sortButtonData["{{key_name}}"] = {
            label: "{{label}}",
            asc_tooltip: "{{asc_tooltip}}",
            desc_tooltip: "{{desc_tooltip}}"
        };
    </script>
{%- endmacro %}

{%- macro checkbox_in_div(checkbox_field, class = 'checkbox') -%}
    <div{% if class %} class="{{class}}"{% endif %}
        title="{{checkbox_field.help_text}}">
        {{ checkbox_field }} 
        {{ checkbox_field.label_tag() }} 
        {{ checkbox_field.errors }}
    </div>
{%- endmacro -%}

{%- macro edit_post(
                post_form,
                post_type = None,
                mandatory_tags = None,
                edit_title = False
            )
-%}
{%include "widgets/edit_post.html" %}
{%- endmacro -%}

{%- macro tag_autocomplete_js(id = '#id_tags') -%}
    var tagAc = new AutoCompleter({
            url: '{% url "get_tag_list" %}',
            preloadData: true,
            minChars: 1,
            useCache: true,
            matchInside: true,
            maxCacheLength: 100,
            delay: 10
    });
    tagAc.decorate($("{{ id }}"));
{%- endmacro -%}

{%- macro answer_classes(answer, question) -%}
answer {% if answer.accepted %}accepted-answer{% endif %} {% if answer.author_id==question.author_id %} answered-by-owner{% endif %} {% if answer.deleted %}deleted{% endif -%}
{%- endmacro -%}

{%- macro user_score_and_badge_summary(user) -%}
  {%include "widgets/user_score_and_badge_summary.html"%}
{%- endmacro -%}

{%- macro follow_toggle(follow, name, alias, id) -%}
    {# follow - boolean; name - object type name; alias - e.g. users name; id - object id #}
    <div 
        class="follow-toggle" 
        id="follow-{{ name }}-{{ id }}"
    >
        {% if follow %}
        <div class="follow">{% trans %}follow {{alias}}{% endtrans %}</div>
        {% else %}
        <div class="unfollow">
          <div class="unfollow-red">{% trans %}unfollow {{alias}}{% endtrans %}</div>
          <div class="unfollow-green">{% trans %}following {{alias}}{% endtrans %}</div>
        </div>
        {% endif %}
    </div>
{%- endmacro -%}

{%- macro follow_user_toggle(visitor = None, subject = None) -%}
    {% if visitor.is_anonymous() %}
        {{ follow_toggle(True, 'user', subject.username, subject.id) }}
    {% else %}
        {% if visitor != subject %}
            {% if visitor.is_following(subject) %}
                {{ follow_toggle(False, 'user', subject.username, subject.id) }}
            {% else %}
                {{ follow_toggle(True, 'user', subject.username, subject.id) }}
            {% endif %}
        {% endif %}
    {% endif %}
{%- endmacro -%}

{%- macro user_long_score_and_badge_summary(user) -%}
  {% include "widgets/user_long_score_and_badge_summary.html" %}
{%- endmacro -%}

{%- macro user_country_flag(user) -%}
    {% if user.country and user.show_country %}
        <img class="flag" 
            src="{{ ('/images/flags/' ~ user.country.code|lower ~ '.gif')|media }}"
            alt="{% trans 
                    country=user.country.name 
                    %}flag of {{country}}{% 
                endtrans %}"
            title="{% trans 
                    country=user.country.name, 
                    person=user.username %}{{person}} is from {{country}}{%
                 endtrans %}"
        />
    {% endif %}
{%- endmacro -%}

{%- macro user_country_name_and_flag(user) -%}
    {% if user.country and user.show_country %}
        {{ user.country.name }}
        {{ user_country_flag(user) }}
    {% endif %}
{%- endmacro -%}

{%- macro user_full_location(user) -%}
    {% if user.location %}
        {{ user.location }},
    {% endif %}
    {{ user_country_name_and_flag(user) }}
{%- endmacro -%}

{%- macro user_list(users, profile_section = None) -%}
{% include "widgets/user_list.html"%}
{%- endmacro -%}

{#todo: rename this to avatar #}
{%- macro gravatar(user, size) -%}
{% spaceless %}
<a style="text-decoration:none"
    href="{{ user.get_absolute_url() }}"
><img class="gravatar" 
    width="{{size}}" height="{{size}}"
    src="{{ user.get_avatar_url(size) }}"
    title="{{user.username}}" 
    alt="{% trans username=user.username %}{{username}} gravatar image{% endtrans %}" 
/></a>
{% endspaceless %}
{%- endmacro -%}

{%- macro user_website_link(user, max_display_length=25) -%}
    {% if user.website %}
        <a 
            href="{{user.website}}"
            title="{% trans username=user.username|escape, url=user.website %}{{username}}'s website is {{url}}{% endtrans %}"
            {% if user.can_have_strong_url() == False %}
            rel="nofollow"
            {% endif %}
        >
        {{user.website|truncate(length=max_display_length, killwords=True, end='...')}}
        </a>
    {% endif %}
{%- endmacro -%}

{%- macro paginator(p, position='left') -%}{# p is paginator context dictionary #}
{% spaceless %}
    {% if p.is_paginated %}
        <div class="paginator" style="float:{{position}}">
        {% if p.has_previous %}
            <span class="prev"><a href="{{p.base_url}}page={{ p.previous }}{{ 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={{ p.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, position='left') -%}{# p is paginator context #}
{% spaceless %}
{% if p.is_paginated %}
    <div class="paginator" style="float:{{position}}">
        <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 inbox_link(user) -%}
    {% if user.new_response_count > 0 or user.seen_response_count > 0 %}
    <a id='ab-responses' href="{{user.get_absolute_url()}}?sort=inbox&section=forum">
        <img 
            alt="{% trans username=user.username %}responses for {{username}}{% endtrans %}"
            {% if user.new_response_count > 0 %}
                src="{{ "/images/mail-envelope-full.png"|media }}"
                title="{% trans response_count=user.new_response_count %}you have a new response{% pluralize %}you have {{response_count}} new responses{% endtrans %}"
            {% elif user.seen_response_count > 0 %}
                src="{{ "/images/mail-envelope-empty.png"|media }}"
                title="{% trans %}no new responses yet{% endtrans %}"
            {% endif %}
        />
    </a>
    {% endif %}
{%- endmacro -%}

{%- macro moderation_items_link(user, moderation_items) -%}
    {% if moderation_items %}
        <a id="ab-responses"
            href="{{user.get_absolute_url()}}?sort=inbox&section=flags"
        >
        {% if moderation_items['new_count'] > 0 %}
            <img src="{{'/images/dialog-warning.png'|media}}"
            {% if moderation_items['seen_count'] > 0 %}
                alt="{% trans new=moderation_items['new_count'], seen=moderation_items['seen_count']%}{{new}} new flagged posts and {{seen}} previous{% endtrans %}"
                title="{% trans new=moderation_items['new_count'], seen=moderation_items['seen_count']%}{{new}} new flagged posts and {{seen}} previous{% endtrans %}"
            {% else %}
                alt="{% trans new=moderation_items['new_count'] %}{{new}} new flagged posts{% endtrans %}"
                title="{% trans new=moderation_items['new_count'] %}{{new}} new flagged posts{% endtrans %}"
            {% endif %}
            />
        {% elif moderation_items['seen_count'] > 0 %}
            <img src={{'/images/dialog-warning-off.png'|media}} 
                alt="{% trans seen=moderation_items['seen_count'] %}{{seen}} flagged posts{% endtrans %}" 
                title="{% trans seen=moderation_items['seen_count'] %}{{seen}} flagged posts{% endtrans %}" 
            />
        {% endif %}
        </a>
    {% endif %}
{%- endmacro -%}