{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}

{% block title %}
  {% trans %}News admin{% endtrans %}
{% endblock %}

{% block content %}
  <h3>{% trans %}News{% endtrans %}</h3>

  <p><a href="{{ url('com:news_new') }}">{% trans %}Create news{% endtrans %}</a></p>

  <hr />
  <h4>{% trans %}Weeklies{% endtrans %}</h4>
  {% set weeklies = object_list.filter(dates__end_date__gte=timezone.now()).distinct().order_by('id') %}
  <h5>{% trans %}Displayed weeklies{% endtrans %}</h5>
  <table>
    <thead>
      <tr>
        <td>{% trans %}Title{% endtrans %}</td>
        <td>{% trans %}Summary{% endtrans %}</td>
        <td>{% trans %}Club{% endtrans %}</td>
        <td>{% trans %}Author{% endtrans %}</td>
        <td>{% trans %}Moderator{% endtrans %}</td>
        <td>{% trans %}Dates{% endtrans %}</td>
        <td>{% trans %}Actions{% endtrans %}</td>
      </tr>
    </thead>
    <tbody>
      {% for news in weeklies.filter(is_published=True) %}
        <tr>
          <td>{{ news.title }}</td>
          <td>{{ news.summary|markdown }}</td>
          <td><a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a></td>
          <td>{{ user_profile_link(news.author) }}</td>
          <td>{{ user_profile_link(news.moderator) }}</td>
          <td>
            <ul>
              {% for d in news.dates.all() %}
                <li>{{ d.start_date|localtime|date(DATETIME_FORMAT) }}
                  {{ d.start_date|localtime|time(DATETIME_FORMAT) }} -
                  {{ d.end_date|localtime|date(DATETIME_FORMAT) }}
                  {{ d.end_date|localtime|time(DATETIME_FORMAT) }}
                </li>
              {% endfor %}
            </ul>
          </td>
          <td><a href="{{ url('com:news_detail', news_id=news.id) }}">{% trans %}View{% endtrans %}</a>
            <a href="{{ url('com:news_edit', news_id=news.id) }}">{% trans %}Edit{% endtrans %}</a>
            <a href="{{ url('com:news_moderate', news_id=news.id) }}?remove">{% trans %}Unpublish{% endtrans %}</a>
            <a href="{{ url('com:news_delete', news_id=news.id) }}">{% trans %}Delete{% endtrans %}</a>
          </td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
  <h5>{% trans %}Weeklies to moderate{% endtrans %}</h5>
  <table>
    <thead>
      <tr>
        <td>{% trans %}Title{% endtrans %}</td>
        <td>{% trans %}Summary{% endtrans %}</td>
        <td>{% trans %}Club{% endtrans %}</td>
        <td>{% trans %}Author{% endtrans %}</td>
        <td>{% trans %}Dates{% endtrans %}</td>
        <td>{% trans %}Actions{% endtrans %}</td>
      </tr>
    </thead>
    <tbody>
      {% for news in weeklies.filter(is_published=False) %}
        <tr>
          <td>{{ news.title }}</td>
          <td>{{ news.summary|markdown }}</td>
          <td><a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a></td>
          <td>{{ user_profile_link(news.author) }}</td>
          <td>
            <ul>
              {% for d in news.dates.all() %}
                <li>{{ d.start_date|localtime|date(DATETIME_FORMAT) }}
                  {{ d.start_date|localtime|time(DATETIME_FORMAT) }} -
                  {{ d.end_date|localtime|date(DATETIME_FORMAT) }}
                  {{ d.end_date|localtime|time(DATETIME_FORMAT) }}
                </li>
              {% endfor %}
            </ul>
          </td>
          <td><a href="{{ url('com:news_detail', news_id=news.id) }}">{% trans %}View{% endtrans %}</a>
            <a href="{{ url('com:news_edit', news_id=news.id) }}">{% trans %}Edit{% endtrans %}</a>
            <a href="{{ url('com:news_moderate', news_id=news.id) }}">{% trans %}Publish{% endtrans %}</a>
            <a href="{{ url('com:news_delete', news_id=news.id) }}">{% trans %}Delete{% endtrans %}</a>
          </td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
  <hr />
  <h4>{% trans %}Events{% endtrans %}</h4>
  {% set events = object_list.filter(dates__end_date__gte=timezone.now()).order_by('id') %}
  <h5>{% trans %}Displayed events{% endtrans %}</h5>
  <table>
    <thead>
      <tr>
        <td>{% trans %}Title{% endtrans %}</td>
        <td>{% trans %}Summary{% endtrans %}</td>
        <td>{% trans %}Club{% endtrans %}</td>
        <td>{% trans %}Author{% endtrans %}</td>
        <td>{% trans %}Moderator{% endtrans %}</td>
        <td>{% trans %}Start{% endtrans %}</td>
        <td>{% trans %}End{% endtrans %}</td>
        <td>{% trans %}Actions{% endtrans %}</td>
      </tr>
    </thead>
    <tbody>
      {% for news in events.filter(is_published=True) %}
        <tr>
          <td>{{ news.title }}</td>
          <td>{{ news.summary|markdown }}</td>
          <td><a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a></td>
          <td>{{ user_profile_link(news.author) }}</td>
          <td>{{ user_profile_link(news.moderator) }}</td>
          <td>{{ news.dates.all()[0].start_date|localtime|date(DATETIME_FORMAT) }}
            {{ news.dates.all()[0].start_date|localtime|time(DATETIME_FORMAT) }}</td>
          <td>{{ news.dates.all()[0].end_date|localtime|date(DATETIME_FORMAT) }}
            {{ news.dates.all()[0].end_date|localtime|time(DATETIME_FORMAT) }}</td>
          <td><a href="{{ url('com:news_detail', news_id=news.id) }}">{% trans %}View{% endtrans %}</a>
            <a href="{{ url('com:news_edit', news_id=news.id) }}">{% trans %}Edit{% endtrans %}</a>
            <a href="{{ url('com:news_moderate', news_id=news.id) }}?remove">{% trans %}Unpublish{% endtrans %}</a>
            <a href="{{ url('com:news_delete', news_id=news.id) }}">{% trans %}Delete{% endtrans %}</a>
          </td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
  <h5 id="moderation">{% trans %}Events to moderate{% endtrans %}</h5>
  <table>
    <thead>
      <tr>
        <td>{% trans %}Title{% endtrans %}</td>
        <td>{% trans %}Summary{% endtrans %}</td>
        <td>{% trans %}Club{% endtrans %}</td>
        <td>{% trans %}Author{% endtrans %}</td>
        <td>{% trans %}Start{% endtrans %}</td>
        <td>{% trans %}End{% endtrans %}</td>
        <td>{% trans %}Actions{% endtrans %}</td>
      </tr>
    </thead>
    <tbody>
      {% for news in events.filter(is_published=False) %}
        <tr>
          <td>{{ news.title }}</td>
          <td>{{ news.summary|markdown }}</td>
          <td><a href="{{ news.club.get_absolute_url() }}">{{ news.club }}</a></td>
          <td>{{ user_profile_link(news.author) }}</td>
          <td>{{ news.dates.all()[0].start_date|localtime|date(DATETIME_FORMAT) }}
            {{ news.dates.all()[0].start_date|localtime|time(DATETIME_FORMAT) }}</td>
          <td>{{ news.dates.all()[0].end_date|localtime|date(DATETIME_FORMAT) }}
            {{ news.dates.all()[0].end_date|localtime|time(DATETIME_FORMAT) }}</td>
          <td><a href="{{ url('com:news_detail', news_id=news.id) }}">{% trans %}View{% endtrans %}</a>
            <a href="{{ url('com:news_edit', news_id=news.id) }}">{% trans %}Edit{% endtrans %}</a>
            <a href="{{ url('com:news_moderate', news_id=news.id) }}">{% trans %}Publish{% endtrans %}</a>
            <a href="{{ url('com:news_delete', news_id=news.id) }}">{% trans %}Delete{% endtrans %}</a>
          </td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
{% endblock %}
