{% 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_post_snippet(response, inbox_section) -%}
{{ gravatar(response.user, 48) }}
{{ response.user.username|escape }} {{ response.response_type }} ({{ timeago(response.timestamp) }}):
{% if inbox_section != 'flags' %} {{ response.response_snippet }} {% endif %}
{% if inbox_section == 'flags' %}
{{ response.response_content }}
{% endif %}
{%- endmacro -%} {%- macro post_vote_buttons(post = None) -%}
{{ post.score }}
{%- endmacro -%} {%- macro post_contributor_avatar_and_credentials(post, user, karma_mode = None, badges_mode = None) -%} {% if post.is_anonymous %} {% trans %}anonymous user{% endtrans %}

{{ user.get_anonymous_name() }}

{% else %} {{ user_card(user, karma_mode=karma_mode, badges_mode=badges_mode) }} {% endif %} {{ user_primary_group(user) }} {%- endmacro -%} {%- macro post_last_updater_and_creator_info( post, min_rep_to_edit_wiki, karma_mode = None, badges_mode = None ) -%} {{ post_contributor_info( post, "original_author", post.wiki, min_rep_to_edit_wiki, karma_mode = karma_mode, badges_mode = badges_mode ) }} {{ post_contributor_info( post, "last_updater", post.wiki, min_rep_to_edit_wiki, karma_mode = karma_mode, badges_mode = badges_mode ) }} {%- endmacro -%} {%- macro post_contributor_info( post, contributor_type, is_wiki, wiki_min_rep, karma_mode = None, badges_mode = None ) -%} {# 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 %} {{ timeago(post.added_at) }}

{% 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.post_type == 'question' %} {% trans %}asked{% endtrans %} {% elif post.post_type == 'answer' %} {% trans %}answered{% endtrans %} {% else %} {% trans %}posted{% endtrans %} {% endif %} {% if post.__class__.__name__ == 'PostRevision' %} {{ timeago(post.revised_at) }} {% else %} {{ timeago(post.added_at) }} {% endif %}

{{ post_contributor_avatar_and_credentials( post, post.author, karma_mode = karma_mode, badges_mode = badges_mode ) }} {% 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 %} {{ timeago(last_edited_at) }}

{% if original_author != update_author or is_wiki %} {{ post_contributor_avatar_and_credentials( post, update_author, karma_mode = karma_mode, badges_mode = badges_mode ) }} {% 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, 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() }}" title="{% trans tag=tag|escape %}see questions tagged '{{ tag }}'{% endtrans %}" {% 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 ) -%} {% spaceless %} {% if post.comment_count > 0 %}

Comments

{% endif %} {% 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.get_cached_comments()[:show_comment_position] %} {% else %} {% set comments = post.get_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.score > 0 %}
{{comment.score}}
{% else %}
{% endif %}
{{comment.html}} {{comment.author.username|escape}}  ({{ timeago(comment.added_at) }}) {% trans %}edit{% endtrans %}
{% csrf_token %}
{% 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, badges_mode = None) -%} {%- 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 }}, {% endif %} {{ user_country_name_and_flag(user) }} {%- endmacro -%} {% macro user_card(user, karma_mode=None, badges_mode=None) %} {% include "widgets/user_card.html" %} {% endmacro %} {%- macro user_list(users, karma_mode=None, badges_mode=None) -%} {% 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 %}
{% 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|escape %}responses for {{username}}{% endtrans %} 0 %} src="{{ "/images/mail-envelope-full.png"|media }}" title="{% trans response_count=user.new_response_count %}you have {{response_count}} 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 -%} {%- macro timeago(datetime_object) -%} {{datetime_object.replace(microsecond=0)|add_tz_offset}} {%- endmacro -%} {% macro one_shot_form_js(form=None, submit_button=None) %} {% endmacro %}