{#
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#}
{% extends "mediagoblin/base.html" %}

{% block title -%}
  {% trans %}User panel{% endtrans %} &mdash; {{ super() }}
{%- endblock %}

{% block mediagoblin_content %}

<h1>{% trans %}User panel{% endtrans %}</h1>

<p>
  {% trans %}
    Here you can look up users in order to take punitive actions on them.
  {% endtrans %}
</p>

<h2>{% trans %}Active Users{% endtrans %}</h2>

{% if user_list.count() %}
  {% if not last_page == 1 %}
  {% if 'p='~current_page in request.query_string.decode() %}
    {% set query_string = request.query_string.decode() %}{% else %}
    {% set query_string =
'p='~current_page~"&"+request.query_string.decode() %}
  {% endif %}
  <div class="right_align">
    {% set first_vis = current_page-3  %}
    {% set last_vis = current_page+3 %}
    {% if 1 == current_page %}<b>1</b>{% else %}
    <a href ="?{{ query_string.replace(
                    'p='~current_page,
                    'p='~1) }}">
        1</a>{% endif %}
    {% if first_vis > 1 %}...{% endif %}
    {% for p in range(first_vis,last_vis+1) %}
      {% if p > 1 and p < last_page and
current_page !=p %}
        <a href="?{{ query_string.replace(
                    'p='~current_page,
                    'p='~p) }}">
          {{ p }}</a>
      {% elif p > 1 and p < last_page %}
        <b>{{ p }}</b>
      {% endif  %}
    {% endfor %}
    {% if last_vis < last_page %}...{% endif %}
    {% if last_page != current_page %}
    <a href ="?{{ query_string.replace(
                    'p='~current_page,
                    'p='~last_page) }}">
      {{ last_page }}</a>
    {% else %}<b>{{ last_page }}</b>
    {% endif %}
  </div>
  {% endif %}
  <table class="admin_panel processing">
    <tr>
      <th>{% trans %}ID{% endtrans %}</th>
      <th>{% trans %}Username{% endtrans %}</th>
      <th>{% trans %}When Joined{% endtrans %}</th>
      <th>{% trans %}# of Comments Posted{% endtrans %}</th>
    </tr>
    {% for user in user_list %}
      <tr>
        <td>{{ user.id }}</td>
        <td>
          <a href="{{ request.urlgen('mediagoblin.moderation.users_detail',
                                         user= user.username) }}">
            {{ user.username }}
          </a>
        </td>
        <td>{{ user.created.strftime("%F %R") }}</td>
        <td>{{ user.posted_comments.count() }}</td>
      </tr>
    {% endfor %}
  </table>
{% else %}
  <p><em>{% trans %}No users found.{% endtrans %}</em></p>
{% endif %}
{% endblock %}
