{%- macro user_score_and_badge_summary(user) -%} {{user.reputation}} {% if user.gold or user.silver or user.bronze %} {% if user.gold %} {{user.gold}} {% endif %} {% if user.silver %} {{user.silver}} {% endif %} {% if user.bronze %} {{user.bronze}} {% endif %} {% endif %} {%- endmacro -%} {%- macro user_long_score_and_badge_summary(user) -%} {% trans %}karma:{% endtrans %} {{user.reputation}} {% if user.gold or user.silver or user.bronze %} {% trans %}badges:{% endtrans %} {% if user.gold %} {{user.gold}} {% endif %} {% if user.silver %} {{user.silver}} {% endif %} {% if user.bronze %} {{user.bronze}} {% endif %} {% endif %} {%- endmacro -%} {%- macro paginator(p) -%}{# p is paginator context dictionary #} {% spaceless %} {% if p.is_paginated %}
{% if p.has_previous %} « {% trans %}previous{% endtrans %} {% endif %} {% if not p.in_leading_range %} {% for num in p.pages_outside_trailing_range %} {{ num }} {% endfor %} ... {% endif %} {% for num in p.page_numbers %} {% if num == p.page and p.pages != 1%} {{ num }} {% else %} {{ num }} {% endif %} {% endfor %} {% if not p.in_trailing_range %} ... {% for num in p.pages_outside_leading_range|reverse %} {{ num }} {% endfor %} {% endif %} {% if p.has_next %} {% trans %}next page{% endtrans %} » {% endif %}
{% endif %} {% endspaceless %} {%- endmacro -%} {%- macro pagesize_switch(p) -%}{# p is paginator context #} {% spaceless %} {% if p.is_paginated %}
{% trans %}posts per page{% endtrans %} {% if p.page_size == 10 %} 10 {% else %} 10 {% endif %} {% if p.page_size == 30 %} 30 {% else %} 30 {% endif %} {% if p.page_size == 50 %} 50 {% else %} 50 {% endif %}
{% endif %} {% endspaceless %} {%- endmacro -%} {%- macro gravatar(user, size) -%} {% spaceless %} {% trans username=user.username %}{{username}} gravatar image{% endtrans %} {% endspaceless %} {%- 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" %} {% if is_wiki %}

{%- if post.__class__.__name__ == 'Question' -%} {%- trans %}asked{% endtrans %} {% elif post.__class__.__name__ == 'Answer' %} {%- trans %}answered{% endtrans %} {% else %} {%- trans %}posted{% endtrans %} {% endif %} {{post.added_at|diff_date}}

{% trans %}this post is marked as community wiki{% endtrans %}

{% trans %}This post is a wiki. Anyone with karma >{{wiki_min_rep}} is welcome to improve it.{% endtrans %}

{% else %}

{# 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') %} {{post.revised_at|diff_date}} {% else %} {{post.added_at|diff_date}} {% endif %}

{{ gravatar(post.author, 32) }}

{{post.author.get_profile_link()}}
{{ user_score_and_badge_summary(post.author) }}

{% 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 %}

{% trans %}updated{% endtrans %} {{ last_edited_at|diff_date }}

{% if original_author != update_author or is_wiki %} {{ gravatar(update_author, 32) }}

{{update_author.get_profile_link()}}
{{ user_score_and_badge_summary(update_author) }}

{% endif %} {% endif %} {% endif %}
{%- endmacro -%} {%- macro question_summary(question, extra_class=None) -%}
{{question.score|humanize_counter}}
{% trans cnt=question.score %}vote{% pluralize %}votes{% endtrans %}
{{question.answer_count|humanize_counter}}{% if question.answer_accepted%}✓{% endif %}
{% trans cnt=question.answer_count %}answer{% pluralize %}answers{% endtrans %}
{{question.view_count|humanize_counter}}
{% trans cnt=question.view_count %}view{% pluralize %}views{% endtrans %}

{{question.title|escape}}

{{ question.last_activity_at|diff_date }} {{question.last_activity_by.username}} {{user_score_and_badge_summary(question.last_activity_by)}}
{% for tag in question.get_tag_names() %} {% endfor %}
{%- endmacro -%} {%- macro post_comments_widget(post=None, user=None, max_comments=None) -%} {% set comments = post.get_comments()[:max_comments] %} {% spaceless %}
{% for comment in comments %}
{{comment.html}} - {{comment.user.username}}  ({{comment.added_at|diff_date}}) {% if user|can_delete_comment(comment) %} {% endif %}
{% endfor %}
{% endspaceless %}
{% if user|can_post_comment(post) or post.comment_count > max_comments %} {% if user|can_post_comment(post) %} {% trans %}add comment{% endtrans %} {% endif %} {% if post.comment_count > max_comments %} {% set remaining_comments = post.comment_count - max_comments %} {% if user|can_post_comment(question) %}/ {% trans counter=remaining_comments %}see {{counter}} more{% pluralize %}see {{counter}} more{% endtrans %} {% else %} {% trans counter=remaining_comments %}see {{counter}} more comment{% pluralize %}see {{counter}} more comments {% endtrans %} {% endif %} {% endif %} {% endif %}
{%- endmacro -%} {%- macro reversible_sort_button(button_sort_criterium=None, asc_tooltip=None, asc_label=None, desc_tooltip=None, desc_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 #} {{asc_label}} {% elif sort == key_name + "-desc" %}{# "best first" #} {{desc_label}} {% else %}{# default, when other button is active #} {{desc_label}} {% endif %} {%- endmacro %} {%- macro edit_post(post_form, wiki_on, post_type=None, edit_title=False) -%} {% if edit_title %}

{{ post_form.title }} {{ post_form.title.errors }}
{{ post_form.title.help_text }}
{% endif %}
{{ post_form.text }}{# this element is resizable and will be wrapped by js #} {% if wiki_on %}
{{ post_form.wiki }} {{ post_form.wiki.label_tag() }}
{% endif %}
{# need label element for resizable input, b/c form validation won't find span #} {% if post_type == 'question' %}
{{ post_form.tags.label_tag() }}: {% trans %}(required){% endtrans %} {{ post_form.tags.errors }}
{{ post_form.tags }}
{{ post_form.tags.help_text }}
{% endif %} {% if 'summary' in post_form['fields'] %}
{{ post_form.summary.label_tag() }}
{{ post_form.summary }}
{{ post_form.summary.help_text }}
{{ post_form.summary.errors }}
{% endif %}
[{% trans %}hide preview{% endtrans %}]
{%- endmacro -%}