macros.jinja 6.58 KB
Newer Older
Skia's avatar
Skia committed
1 2 3
{% macro user_profile_link(user) -%}
<a href="{{ url("core:user_profile", user_id=user.id) }}">{{ user.get_display_name() }}</a>
{%- endmacro %}
Skia's avatar
Skia committed
4

Skia's avatar
Skia committed
5 6 7 8
{% macro user_profile_link_short_name(user) -%}
<a href="{{ url("core:user_profile", user_id=user.id) }}">{{ user.get_short_name() }}</a>
{%- endmacro %}

Skia's avatar
Skia committed
9 10
{% macro user_link_with_pict(user) -%}
<a href="{{ url("core:user_profile", user_id=user.id) }}" class="mini_profile_link" >
11 12
    {{ user.get_mini_item()|safe }}
</a>
Skia's avatar
Skia committed
13
{%- endmacro %}
14

Krophil's avatar
Krophil committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
{% macro link_news_logo(news) -%}
    {% if news.club.logo -%}
        {{ news.club.logo.url }}
    {% else -%}
        {{ static("com/img/news.png") }}
    {% endif %}
{%- endmacro %}

{% macro gen_news_metatags(news) -%}
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="{{ settings.SITH_TWITTER }}" />
<meta name="twitter:creator" content= "{{ settings.SITH_TWITTER }}" />
<meta property="og:url"                content="{{ news.get_full_url() }}" />
<meta property="og:type"               content="article" />
<meta property="og:title"              content="{{ news.title }}" />
<meta property="og:description"        content="{{ news.summary }}" />
<meta property="og:image"              content="{{ "https://%s%s" % (settings.SITH_URL, link_news_logo(news)) }}" />
{%- endmacro %}

Krophil's avatar
Krophil committed
34
{% macro facebook_share(news) -%}
Krophil's avatar
Krophil committed
35
<a rel="nofollow" target="#" class="share_button facebook" href="https://www.facebook.com/sharer/sharer.php?u={{ news.get_full_url() }}">{% trans %}Share on Facebook{% endtrans %}</a>
Krophil's avatar
Krophil committed
36 37 38
{%- endmacro %}

{% macro tweet(news) -%}
Krophil's avatar
Krophil committed
39 40 41 42 43 44 45 46 47
<a rel="nofollow" target="#" class="share_button twitter" href="https://twitter.com/intent/tweet?text={{ news.get_full_url() }}">{% trans %}Tweet{% endtrans %}</a>
{%- endmacro %}

{% macro fb_quick(news) -%}
<a rel="nofollow" target="#" href="https://www.facebook.com/sharer/sharer.php?u={{ news.get_full_url() }}" class="fb fa fa-facebook-square fa-2x"></a>
{%- endmacro %}

{% macro tweet_quick(news) -%}
<a rel="nofollow" target="#" href="https://twitter.com/intent/tweet?text={{ news.get_full_url() }}" class="twitter fa fa-twitter-square fa-2x"></a>
Krophil's avatar
Krophil committed
48 49
{%- endmacro %}

50
{% macro user_mini_profile(user) %}
Skia's avatar
Skia committed
51 52 53 54 55 56 57 58 59 60 61
<div class="user_mini_profile">
    <div class="user_mini_profile_infos">
        <div class="user_mini_profile_infos_text">
            <div class="user_mini_profile_name">{{ user.get_full_name() }}</div>
            {% if user.nick_name %}
            <div class="user_mini_profile_nick">&laquo; {{ user.nick_name }} &raquo;</div>
            {% endif %}
            {% if user.date_of_birth %}
            <div class="user_mini_profile_dob">
                {{ user.date_of_birth|date("d/m/Y") }} ({{ user.get_age() }})
            </div>
Skia's avatar
Skia committed
62 63 64
            {% endif %}
        </div>
        {% if user.promo %}
Skia's avatar
Skia committed
65 66 67
        <div class="user_mini_profile_promo">
            <img src="{{ static('core/img/promo_%02d.png' % user.promo) }}" title="Promo {{ user.promo }}" alt="Promo {{ user.promo }}" class="promo_pict" />
        </div>
68 69
        {% endif %}
    </div>
Skia's avatar
Skia committed
70 71 72 73 74 75 76 77
    <div class="user_mini_profile_picture">
    {% if user.profile_pict %}
        <img src="{{ user.profile_pict.get_download_url() }}" alt="{% trans %}Profile{% endtrans %}" />
    {% else %}
        <img src="{{ static('core/img/unknown.jpg') }}" alt="{% trans %}Profile{% endtrans %}"
            title="{% trans %}Profile{% endtrans %}" />
    {% endif %}
    </div>
78 79
</div>
{%- endmacro %}
80

81
{% macro user_subscription(user) %}
Krophil's avatar
Krophil committed
82
        {% trans subscription_end=user.subscriptions.order_by('subscription_end').last().subscription_end %}Subscribed until {{ subscription_end }}{% endtrans %}<br/>
83 84 85
        {% trans %}Account number: {% endtrans %}{{ user.customer.account_id }}<br/>
{%- endmacro %}

86
{% macro show_slots(user) %}
Skia's avatar
Skia committed
87
    {% if user.slots.filter(start_date__gte=timezone.now()).exists() %}
88 89
        <h5>{% trans %}Slot{% endtrans %}</h5>
        <ul>
Skia's avatar
Skia committed
90
        {% for i in user.slots.filter(start_date__gte=timezone.now().replace(tzinfo=None)).all() %}
Skia's avatar
Skia committed
91 92 93
            <li>{{ i.get_type_display() }} - {{i.machine.launderette }}, {{ i.start_date|date("l j") }} :
            {{ i.start_date|time(DATETIME_FORMAT) }} |
            <a href="{{ url('launderette:delete_slot', slot_id=i.id) }}">{% trans %}Delete{% endtrans %}</a></li>
94 95 96 97 98 99
        {% endfor %}
        </ul>
    {% endif %}
{% endmacro %}

{% macro show_tokens(user) %}
Skia's avatar
Skia committed
100
    {% if user.tokens.exists() %}
101 102
        <h5>{% trans %}Tokens{% endtrans %}</h5>
        <ul>
Skia's avatar
Skia committed
103
        {% for i in user.tokens.all() %}
104 105 106 107
            <li>{{ i }}</li>
        {% endfor %}
        </ul>
    {% endif %}
Skia's avatar
Skia committed
108
{% endmacro %}
Sli's avatar
Sli committed
109 110 111 112 113

{% macro delete_godfather(user, profile, godfather, is_father) %}
    {% if user == profile or user.is_root or user.is_board_member %}
    <a href="{{ url("core:user_godfathers_delete", user_id=profile.id, godfather_id=godfather.id, is_father=is_father) }}">{% trans %}Delete{% endtrans %}</a>
    {% endif %}
Skia's avatar
Skia committed
114
{% endmacro %}
Sli's avatar
Sli committed
115

116 117
{% macro paginate(page_obj, paginator, js_action) %}
    {% set js = js_action|default('') %}
Sli's avatar
Sli committed
118
    {% if page_obj.has_previous() or page_obj.has_next() %}
Sli's avatar
Sli committed
119
        {% if page_obj.has_previous() %}
120
            <a {% if js %} type="submit" onclick="{{ js }}" {% endif %} href="?page={{ page_obj.previous_page_number() }}">{% trans %}Previous{% endtrans %}</a>
Sli's avatar
Sli committed
121 122 123
        {% else %}
            <span class="disabled">{% trans %}Previous{% endtrans %}</span>
        {% endif %}
Sli's avatar
Sli committed
124 125 126 127
        {% for i in paginator.page_range %}
            {% if page_obj.number == i %}
                <span class="active">{{ i }} <span class="sr-only">({% trans %}current{% endtrans %})</span></span>
            {% else %}
128
                <a {% if js %} type="submit" onclick="{{ js }}" {% endif %} href="?page={{ i }}">{{ i }}</a>
Sli's avatar
Sli committed
129 130 131
            {% endif %}
        {% endfor %}
        {% if page_obj.has_next() %}
132
            <a {% if js %} type="submit" onclick="{{ js }}" {% endif %} href="?page={{ page_obj.next_page_number() }}">{% trans %}Next{% endtrans %}</a>
Sli's avatar
Sli committed
133
        {% else %}
Sli's avatar
Sli committed
134
            <span class="disabled">{% trans %}Next{% endtrans %}</span>
Sli's avatar
Sli committed
135 136
        {% endif %}
    {% endif %}
137
{% endmacro %}
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

{% macro select_all_checkbox(form_id) %}
    <script type="text/javascript">
        function checkbox_{{form_id}}(value) {
            list = document.getElementById("{{ form_id }}").getElementsByTagName("input");
            for (let element of list){
              if (element.type == "checkbox"){
                element.checked = value;
              }
            }
        }
    </script>
    <button type="button" onclick="checkbox_{{form_id}}(true);">{% trans %}Select All{% endtrans %}</button>
    <button type="button" onclick="checkbox_{{form_id}}(false);">{% trans %}Unselect All{% endtrans %}</button>
{% endmacro %}