{% load extra_filters_jinja %} {%- macro share(site = None, site_label = None, icon = False) -%} {% if icon == False %}{% if site_label %}{{ site_label }}{% else %}{{ site }}{% endif %}{% endif %} {%- endmacro -%} {%- macro inbox_message_snippet(message) -%}
{{ gravatar(message.user, 24) }} {{ message.user.username|escape }} {{ message.message_type }} ({{ timeago(message.timestamp) }}) {#
{{ message.snippet }}
#}
{{ message.content }}
{%- endmacro -%} {%- macro moderation_queue_message(message) -%}
{{ gravatar(message.user, 24) }} {{ message.user.username|escape }} | {% if message['memo_type'] == 'edit' %} {{ message.user.email }} | ip={{ message.ip_addr }} | {% endif %} {{ message.message_type }} ({{ timeago(message.timestamp) }}) {#
{{ message.snippet }}
#}
{{ message.content }}
{%- endmacro -%} {%- macro post_vote_buttons(post = None) -%}
{{ post.score }}
{%- endmacro -%} {%- macro post_contributor_avatar_and_credentials(revision) -%} {% if revision.is_anonymous %} {% trans %}anonymous user{% endtrans %}

{{ revision.author.get_anonymous_name() }}

{% else %} {{ user_card(revision.author) }} {% endif %} {% if settings.GROUPS_ENABLED %} {{ user_primary_group(revision.author) }} {% endif %} {%- endmacro -%} {%- macro post_last_updater_and_creator_info(post) -%} {% if post.wiki %}

{%- if post.post_type == 'question' -%} {{ settings.WORDS_ASKED|escape }} {% elif post.post_type == 'answer' %} {{ settings.WORDS_ANSWERED|escape }} {% else %} {%- trans %}posted{% endtrans %} {% endif %} {{ timeago(post.added_at) }}

{% trans %}this post is marked as community wiki{% endtrans %} {% 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() %} {% set last_rev = post.get_latest_revision() %} {{ post_contributor_info(first_rev, "original_author") }} {% if first_rev != last_rev %} {{ post_contributor_info(last_rev, "last_updater") }} {% endif %} {% endif %} {%- endmacro -%} {%- macro post_contributor_info(revision, contributor_type) -%}
{% if contributor_type=="original_author" %} {% if revision.post.post_type == 'question' %} {% set action_label = settings.WORDS_ASKED|escape %} {% elif revision.post.post_type == 'answer' %} {% set action_label = settings.WORDS_ANSWERED|escape %} {% else %} {% set action_label = gettext('posted') %} {% endif %} {% else %} {% set action_label = gettext('updated') %} {% endif %} {% if revision.post.post_type in ('question', 'answer') %} {% set original_author = revision.post.author %} {% else %} {% set original_author = None %} {% endif %}

{{ action_label }} {{ timeago(revision.revised_at) }}

{% set show_user_info = (contributor_type == 'original_author' or (contributor_type == 'last_updater' and original_author != revision.author )) %} {% if show_user_info %} {{ post_contributor_avatar_and_credentials(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, make_links = True, search_state = None, css_class = None, tag_css_class = None, tag_html_tag = 'li', truncate_long_tags = 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 %} {% if membership_info %}
{{ group_join_button( group_id = group.id, acceptance_level = membership_info['aceptance_level'], membership_level = membership_info['membership_level'] ) }} {% 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, delete_link_title = None, css_class = None, search_state = None, html_tag = 'div', 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 %} {% 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="{{ search_state.add_tag(tag).full_url() }}" {% endif %} rel="tag" data-tag-name="{{ tag|replace('*', '✽')|escape }}" >{% if truncate_long_tag -%} {{ tag|replace('*', '✽')|truncate(17, True)|escape }} {%- else -%} {{ tag|replace('*', '✽')|escape }} {%- endif %} {% if deletable %}
x
{% endif %} {{ extra_content }} {% endspaceless %} {%- endmacro -%} {%- macro radio_select(name = None, value = None, choices = None) -%} {% for choice in choices %}

{% set id = "id_" ~ name ~ "_" ~ choice[0] %}

{% endfor %} {%- endmacro -%} {%- macro question_summary(thread, question, extra_class=None, search_state=None, visitor = None) -%} {%include "widgets/question_summary.html" %} {%- endmacro -%} {# Warning! Any changes to the comment markup here must be duplicated in post.js for the purposes of the AJAX comment editor #} {%- macro add_or_show_comments_button(post = None, max_comments = None, widget_id = None) -%} {% if post.comment_count > max_comments %} {% set remaining_comment_count = post.comment_count - max_comments %} {% else %} {% set remaining_comment_count = 0 %} {% endif %} {%- endmacro -%} {%- macro csrf_middleware_token(csrf_token) -%}
{%- endmacro -%} {%- macro post_comments_widget( post=None, show_post = None, show_comment = None, show_comment_position = None, user=None, max_comments=None, csrf_token=None ) -%} {% spaceless %} {% 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 %} {% if comments_count > 0 %}

{% trans %}Comments{% endtrans %}

{% endif %} {% set widget_id = 'comments-for-' + post.post_type + '-' + post.id|string %}
{% for comment in comments %} {# Warning! Any changes to the comment markup IN THIS `FOR` LOOP must be duplicated in post.js for the purposes of the AJAX comment editor #}
{% if comment.score > 0 %}
{{comment.score}}
{% else %}
{% endif %}
{% if comment.needs_moderation() %}

{% trans %}This post is awaiting moderation{% endtrans %}

{% endif %}
{{ comment.summary }} {{comment.author.username|escape}}  ({{ timeago(comment.added_at) }}) {% trans %}edit{% endtrans %}
{% endfor %}
{% if show_post == post and show_comment %} {% if show_comment_position > max_comments %} {{ add_or_show_comments_button( post = post, max_comments = show_comment_position, widget_id = widget_id ) }} {% else %} {{ add_or_show_comments_button( post = post, max_comments = max_comments, widget_id = widget_id ) }} {% endif %} {% else %} {{ add_or_show_comments_button( post = post, max_comments = max_comments, widget_id = widget_id ) }} {% endif %}
{% endspaceless %} {%- endmacro -%} {%- macro reversible_sort_button(button_sort_criterium=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" #} {% set key_name = button_sort_criterium %} {% if current_sort_method == key_name + "-asc" %}{# "worst" first #} {{label}} ▲ {% elif current_sort_method == key_name + "-desc" %}{# "best first" #} {{label}} ▼ {% else %}{# default, when other button is active #} {{label}} {% endif %} {%- endmacro %} {%- macro checkbox_in_div(checkbox_field, class = 'checkbox') -%} {{ checkbox_field }} {{ checkbox_field.label_tag() }} {{ checkbox_field.errors }} {%- endmacro -%} {%- macro edit_post( post_form, post_type = None, post_html = None, mandatory_tags = None, use_category_selector = False, tag_names = None, editor_type = None, user = None ) -%} {%include "widgets/edit_post.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 answer_classes(answer, question) -%} {% if answer.accepted() %}accepted-answer{% endif %} {% if answer.author_id==question.author_id %} answered-by-owner{% endif %} {% if answer.deleted %}deleted{% endif -%} {%- endmacro -%} {%- macro follow_toggle(follow, name, alias, id) -%} {# follow - boolean; name - object type name; alias - e.g. users name; id - object id #}
{% if follow %} {% else %}
{% trans %}unfollow {{alias}}{% endtrans %}
{% trans %}following {{alias}}{% endtrans %}
{% endif %}
{%- endmacro -%} {%- macro follow_user_toggle(visitor = None, subject = None) -%} {% if visitor.is_anonymous() %} {{ follow_toggle(True, 'user', subject.username|escape, subject.id) }} {% else %} {% if visitor != subject %} {% if visitor.is_following(subject) %} {{ follow_toggle(False, 'user', subject.username|escape, subject.id) }} {% else %} {{ follow_toggle(True, 'user', subject.username|escape, 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 country_flag(country_code, flag_label) -%} {{ flag_label }} {%- endmacro -%} {%- macro user_country_flag(user) -%} {% if user.country 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 "widgets/user_card.html" %} {% endmacro %} {%- macro user_list(users) -%} {% include "widgets/user_list.html" %} {%- endmacro -%} {#todo: rename this to avatar #} {%- macro gravatar(user, size) -%} {% spaceless %} {% trans username=user.username|escape %}{{username}} gravatar image{% endtrans %} {% endspaceless %} {%- endmacro -%} {%- macro user_website_link(user, max_display_length=25) -%} {% if user.website and (not user.is_blocked()) %} {{user.website|truncate(length=max_display_length, killwords=True, end='...')}} {% endif %} {%- endmacro -%} {%- macro paginator(p, position='left', anchor='') -%}{# p is paginator context dictionary #} {% spaceless %} {% if p.is_paginated %}
« {% trans %}previous{% endtrans %} 1 ... {% for num in p.page_numbers %} {% if num == p.page %} {{ num }} {% else %} {{ num }} {% endif %} {% endfor %} {# the "last page" navigation #} ... {{ p.pages }} {# "next" nav link #} {% trans %}next{% endtrans %} »
{% endif %} {% endspaceless %} {%- endmacro -%} {%- macro paginator_main_page(p, position, search_state) -%} {# 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 inbox_link(user) -%} {% if user.new_response_count %} {% trans username=user.username|escape %}responses for {{username}}{% endtrans %} {% endif %} {%- 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) -%} {{datetime_object.replace(microsecond=0)|add_tz_offset}} {%- 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 %}