{%- macro moderated_post_warning(post) -%}
{% set post_type=post.get_post_type_display() %} {% trans %}This {{ post_type }} is being moderated, please do not repost it!{% endtrans %}
{%- endmacro -%} {%- macro used_count(count=0) -%} ×{{ count }} {%- endmacro -%} {%- macro share(site = None) -%} {%- endmacro -%} {%- macro post_flag_buttons(post) -%} {% trans %}flag offensive{% endtrans %} {{ post.offensive_flag_count }} {% trans %}remove flag{% endtrans %} {%- endmacro -%} {%- macro inbox_message_snippet(message) -%}
{{ gravatar(message.user, 16, hide_rep=True) }} {{ message.user.username|escape }} {{ message.message_type }} ({{ timeago(message.timestamp) }})
{#
{{ message.snippet }}
#}
{{ message.content }}
{%- endmacro -%} {%- macro mailto_link(email) -%} {{ email }} {%- endmacro -%} {%- macro moderation_queue_message(message) -%}
{{ gravatar(message.user, 16, hide_rep=True) }} {{ message.user.username|escape }}| {%- if message['memo_type'] == 'edit' -%} {{ mailto_link(message.user.email) }}| ip={{ message.ip_addr }}| {%- endif %} {{ message.message_type }} ({{ timeago(message.timestamp) }})
{{ message.content }}
{%- endmacro -%} {%- macro post_vote_buttons(post = None) -%}
{{ post.score|humanize_counter }}
{%- endmacro -%} {%- macro post_last_updater_and_creator_info(post, visitor=None) -%}
{% if post.wiki %}
{% set last_rev = post.get_latest_revision(visitor) %}
{{ timeago(post.added_at, action_performed=last_rev.get_action_label()) }}
{% set wiki_min_rep = settings.MIN_REP_TO_EDIT_WIKI %}
{% trans %}This post is a wiki. Anyone with karma >{{wiki_min_rep}} is welcome to improve it.{% endtrans %}
{% else %} {% set first_rev = post.get_earliest_revision(visitor) %} {% set last_rev = post.get_latest_revision(visitor) %} {{ post_contributor_info(first_rev, last_rev) }} {% if first_rev != last_rev and first_rev.author_id != last_rev.author_id %} {{ post_contributor_info(last_rev) }} {% endif %} {% endif %}
{%- endmacro -%} {%- macro post_revision_link(revision) -%} {{ timeago(revision.revised_at, action_performed=revision.get_action_label()) }} {%- endmacro -%} {%- macro post_contributor_info(revision, last_revision=None) -%}
{% if revision.is_anonymous %} {{ anon_avatar(32) }} {% else %} {{ gravatar(revision.author, 32) }} {% endif %}
{% if revision.is_anonymous %} {{ settings.NAME_OF_ANONYMOUS_USER }} {% else %} {{ revision.author.username }} {% if settings.GROUPS_ENABLED %} {{ user_primary_group(revision.author) }} {% endif %} {% endif %}
{{ post_revision_link(revision) }} {%- if revision != last_revision and revision.author_id == last_revision.author_id -%}, {{ post_revision_link(last_revision) }} {% endif %}
{%- 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, search_state = None) -%} {% for tag in tags %} {{ tag.name|escape }} {% endfor %} {%- endmacro -%} {%- macro tag_list_widget( tags, id=None, deletable=False, label=None, make_links=True, search_state=None, css_class=None, truncate_long_tags=False, question_id=None, with_edit_link=False ) -%} {%- endmacro -%} {%- macro user_group_link(group) -%} {{ group.name|escape }} {%- endmacro -%} {%- macro user_group(group, membership_info, show_count=False) -%} {{ user_group_link(group) }} {% if show_count %} {{ group.users_count }} {% endif %} {% if group.description %} {{ group.description.summary }} {% endif %} {%- endmacro -%} {%- macro user_primary_group(user) -%} {% set group=user.get_primary_group() %} {% if group %} {{ group.name|replace('-', ' ')|escape }} {% endif %} {%- endmacro -%} {%- macro group_join_button( group_id=None, acceptance_level='closed', membership_level='none') -%} {% if acceptance_level in ('open', 'moderated') %} {% endif %} {%- endmacro -%} {# todo: remove the extra content argument to make its usage more explicit #} {%- macro tag_widget( tag, deletable=False, is_link=True, css_class=None, search_state=None, extra_content='', truncate_long_tag=False ) -%} {% if not search_state %} {# get empty SearchState() if there's none; CAUTION: for some reason this doesn't work inside `spaceless` tag below! #} {% set search_state=search_state|get_empty_search_state %} {% endif %} {% filter trim %}
<{% if is_link %}a{% else %}span{% endif %} class="js-tag-name{% if css_class %} {{ css_class }}{% endif %}" rel="tag" {% if is_link and not tag.endswith('*') %} href="{{ search_state.add_tag(tag).full_url() }}" {% endif %} data-tag-name="{{ tag|escape }}" >{% if truncate_long_tag -%} {{ tag|truncate(17, True)|escape|replace('*', '✽')}} {%- else -%} {{ tag|escape|replace('*', '✽') }} {%- endif -%} {%- if deletable -%} × {%- endif %} {% if extra_content %} {{ extra_content }} {% endif %}
{% endfilter %} {%- endmacro -%} {%- macro radio_select(name = None, value = None, choices = None) -%} {% for choice in choices %} {% set id = "id_" ~ name ~ "_" ~ choice[0] %} {% endfor %} {%- endmacro -%} {# Warning! Any changes to the comment markup here must be duplicated in post.js for the purposes of the AJAX comment editor #} {%- macro comments_widget_buttons(post=None, max_comments=None, user=None) -%} {% set more_comments = post.get_comments_count(user) > max_comments %} {% trans %}add a comment{% endtrans %} {% trans %}see more comments{% endtrans %} {%- endmacro -%} {%- macro csrf_middleware_token(csrf_token) -%}
{%- endmacro -%} {%- macro comment_widget(comment, csrf_token=None) -%}
{% if comment.score > 0 %}{{ comment.score }}{% endif %}
{% if comment.id %} {% endif %}
{% if comment.needs_moderation() %} {{ moderated_post_warning(comment) }} {% endif %}
{{ comment.summary }}
{# important - the same number for avatar size must be in question/javascript.html #} {% if hasattr(comment.author, 'is_terminated') and comment.author.is_terminated() %} {{ anon_avatar(16) }} {{ comment.author.get_anonymous_name() }} {% else %} {{ gravatar(comment.author, 16, hide_rep=True) }} {{comment.author.username|escape}} {% endif %} ({{ timeago(comment.added_at) }}) {% trans %}edit{% endtrans %}
{% if comment.id %} {% endif %} {%- endmacro -%} {%- macro post_comments( post=None, show_post=None, show_comment=None, show_comment_position=None, user=None, max_comments=None, csrf_token=None ) -%} {% if show_post == post and show_comment and show_comment_position > max_comments %} {% set comments = post.get_cached_comments()[:show_comment_position] %} {% else %} {% set comments = post.get_cached_comments()[:max_comments] %} {% endif %} {% set comments_count = comments|length %}

{% trans %}Comments{% endtrans %}

{% for comment in comments %} {{ comment_widget(comment, csrf_token) }} {% endfor %}
{% if show_post == post and show_comment and show_comment_position > max_comments %} {{ comments_widget_buttons(post=post, max_comments=show_comment_position, user=user) }} {% else %} {{ comments_widget_buttons(post=post, max_comments=max_comments, user=user) }} {% endif %}
{%- endmacro -%} {%- macro reversible_sort_button( sort_by=None, asc_tooltip=None, desc_tooltip=None, label=None, current_sort_method=None, search_state=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" #} {% if current_sort_method == sort_by + "-asc" %}{# "worst" first #} {{label}} {% elif current_sort_method == sort_by + "-desc" %}{# "best first" #} {{label}} {% else %}{# default, when other button is active #} {{label}} {% endif %} {%- endmacro %} {%- macro checkbox_in_div(checkbox_field, class = 'checkbox') -%} {{ checkbox_field.errors }} {{ checkbox_field }} {{ checkbox_field.label_tag() }} {%- endmacro -%} {%- macro edit_post(post_form, settings, post_html=None) -%} {# todo: retire this macro, this will require renaming or using "set" on some template variables #} {% include "editors/rich_text.html" %} {%- endmacro -%} {%- macro tag_autocomplete_js(id = '#id_tags') -%} var tagAc = new AutoCompleter({ url: '{{ url('get_tag_list') }}', minChars: 1, useCache: true, matchInside: true, maxCacheLength: 100, delay: 10 }); tagAc.decorate($("{{ id }}")); {%- 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.country.code != 'none' and user.show_country %} {% trans
              country=user.country.name
              %}flag of {{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|escape }}, {% endif %} {{ user_country_name_and_flag(user) }} {%- endmacro -%} {% macro user_card(user) %} {% include "components/user_card.html" %} {% endmacro %} {%- macro users_list(users) -%} {% include "components/users_list.html" %} {%- endmacro -%} {# does not call any user methods #} {%- macro simple_avatar(user_data) -%} {% set username=user_data['username']|escape %} {% trans %}{{username}}'s avatar{% endtrans %} {%- if user_data['reputation'] and settings.KARMA_MODE == 'public' -%}
{{ user_data['reputation']|humanize_counter }}
{%- endif -%}
{%- endmacro -%} {#todo: rename this to avatar #} {%- macro gravatar(user, size, hide_rep=False) -%} {{ simple_avatar({ 'id': user.id, 'avatar_url': user.get_avatar_url(size), 'profile_url': user.get_absolute_url(), 'username': user.username, 'reputation': (not hide_rep) and user.get_localized_profile().get_reputation() })}} {%- endmacro -%} {%- macro anon_avatar(size) -%} {% trans %}anonymous user{% endtrans %} {%- endmacro -%} {%- macro user_website_link(user, max_display_length=25, force_show=False) -%} {% if user.website and (force_show or (not (user.is_blocked() or user.is_watched()))) %} {{user.website|strip_website_url|truncate(length=max_display_length, killwords=True, end='...')}} {% endif %} {%- endmacro -%} {%- macro paginator(p, anchor='') -%}{# p is paginator context dictionary #} {% filter trim %} {% if p.is_paginated %}
1 {% for num in p.page_numbers %} {% if num == p.page %} {{ num }} {% else %} {{ num }} {% endif %} {% endfor %} {{ p.pages }}
{% endif %} {% endfilter %} {%- endmacro -%} {# p is paginator context dictionary #} {%- macro ajax_paginator(p, class="js-paginator", data_url=None, result_placement_selector=None, request_params=None) -%}
1 {% for num in p.page_numbers %} {% if num == p.page %} {{ num }} {% else %} {{ num }} {% endif %} {% endfor %} {{ p.pages }}
{%- endmacro -%} {%- macro paginator_questions(p, search_state) -%} {# p is paginator context dictionary #} {% filter trim %} {% if p.is_paginated %}
{% 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 %}
{% endif %} {% endfilter %} {%- endmacro -%} {%- macro moderation_items_link(user, moderation_items) -%} {% if moderation_items %} {% if moderation_items['new_count'] > 0 %} 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 %} {% trans seen=moderation_items['seen_count'] %}{{seen}} flagged posts{% endtrans %} {% endif %} {% endif %} {%- endmacro -%} {%- macro timeago(datetime_object, action_performed=None) -%} {%- set when='' ~ datetime_object.replace(microsecond=0)|add_tz_offset ~ '' -%} {%- if action_performed -%} {# action and time can be reversed, depending on language #} {% trans %}{{ action_performed }} {{ when }}{% endtrans %} {%- else -%} {{ when }} {%- endif -%} {%- endmacro -%} {% macro one_shot_form_js(form=None, submit_button=None) %} {% endmacro %} {% macro form_field_with_errors(field) %} {% if field.errors %}

{{ field.errors|join(", ") }}

{% endif %} {{ field }} {% endmacro %}