{% extends "core/base.jinja" %}

{% block title -%}
  {% trans %}Club list{% endtrans %}
{%- endblock %}

{% block description -%}
  {% trans %}The list of all clubs existing at UTBM.{% endtrans %}
{%- endblock %}

{% macro display_club(club) -%}

  {% if club.is_active or user.is_root %}

    <li><a href="{{ url('club:club_view', club_id=club.id) }}">{{ club.name }}</a>

      {% if not club.is_active %}
        ({% trans %}inactive{% endtrans %})
      {% endif %}

      {% if club.president %} - <a href="{{ url('core:user_profile', user_id=club.president.user.id) }}">{{ club.president.user }}</a>{% endif %}
      {% if club.short_description %}<p>{{ club.short_description|markdown }}</p>{% endif %}

  {% endif %}

  {%- if club.children.all()|length != 0 %}
    <ul>
      {%- for c in club.children.order_by('name').prefetch_related("children") %}
        {{ display_club(c) }}
      {%- endfor %}
    </ul>
  {%- endif -%}
  </li>
{%- endmacro %}

{% block content %}
  {% if user.is_root %}
    <p><a href="{{ url('club:club_new') }}">{% trans %}New club{% endtrans %}</a></p>
  {% endif %}
  {% if club_list %}
    <h3>{% trans %}Club list{% endtrans %}</h3>
    <ul>
      {%- for club in club_list %}
        {{ display_club(club) }}
      {%- endfor %}
    </ul>
  {% else %}
    {% trans %}There is no club in this website.{% endtrans %}
  {% endif %}
{% endblock %}



