{% 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 follow_toggle(follow, name, alias, id) -%} {# follow - boolean; name - object type name; alias - e.g. users name; id - object id #}
{% if follow %}
{% trans %}follow {{alias}}{% endtrans %}
{% else %}
{% trans %}unfollow {{alias}}{% endtrans %}
{% trans %}following {{alias}}{% endtrans %}
{% endif %}
{%- endmacro -%} {%- macro post_vote_buttons(post = None, visitor_vote = None) -%} {%- endmacro -%} {%- macro post_contributor_avatar_and_credentials(post, user) -%} {% if post.is_anonymous %}

{{ user.get_anonymous_name() }}

{% else %}
{{ user.get_profile_link()}} {{ user_score_and_badge_summary(user) }} {{ user_website_link(user) }}
{% 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 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.post_type == 'question' -%} {%- trans %}Asked{% endtrans %} {% elif post.post_type == '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 %}
{% 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' %} {{post.revised_at|diff_date}} by {% else %} {{post.added_at|diff_date}} by {% endif %}
{{ post_contributor_avatar_and_credentials(post, post.author) }} {% endif %}
{% 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 %}
{% trans %}Updated{% endtrans %} {{ last_edited_at|diff_date }} {% if original_author != update_author or is_wiki %} {{ post_contributor_avatar_and_credentials(post, update_author) }} {% endif %}
{% endif %} {% 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) -%} {% for tag in tags %} {{ tag.name }} {% 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' ) -%} {%- 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 = '' ) -%} {% 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() }}" title="{% trans %}see questions tagged '{{ tag }}'{% endtrans %}" {% endif %} rel="tag" >{{ tag|replace('*', '✽')|truncate(20,True)}} {% if deletable %}
{% 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) -%} {%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, can_post = None, max_comments = None, widget_id = None) -%} {% if post.comment_count > max_comments %} {% set remaining_comments = post.comment_count - max_comments %} {% if can_post %} {% trans %}add comment{% endtrans %} / {% 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 %} {% elif can_post %} {% trans %}add comment{% endtrans %} {% endif %} {%- endmacro -%} {%- macro post_comments_widget( post=None, show_post = None, show_comment = None, show_comment_position = None, user=None, max_comments=None ) -%} {% spaceless %} {% set widget_id = 'comments-for-' + post.post_type + '-' + post.id|string %}
{% if show_post == post and show_comment and show_comment_position > max_comments %} {% set comments = post._cached_comments[:show_comment_position] %} {% else %} {% set comments = post._cached_comments[:max_comments] %} {% endif %} {% 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.author.is_administrator() %}Staff comment{%endif%} {% if user|can_delete_comment(comment) %} {% endif %}
{{comment.html}}
{{comment.author.username}}  ({{comment.added_at|diff_date}})
{% endfor %}
{% set can_post = user.is_authenticated() and 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 %}
{% 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, 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 #}
{% 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, 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 %} {% 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 }}, {% 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 %} {% trans username=user.username %}{{username}} gravatar image{% endtrans %} {% endspaceless %} {%- endmacro -%} {%- macro user_website_link(user, max_display_length=25) -%} {% if user.website %} {{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 %}
{% 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 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 > 0 or user.seen_response_count > 0 %} {% trans username=user.username %}responses for {{username}}{% endtrans %} 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 %} /> {% 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 -%}