{% extends "base.html" %}
{% load i18n %}

{% block subtitle %}
  {% trans 'Users import' %}
{% endblock %}

{% block actions %}
  {% if session %}
    <a class="btn btn-primary" href="{% url 'trainings:session-list' %}">{% trans 'Back' %}</a>
  {% else %}
    <a class="btn btn-primary" href="{% url 'accounts:user-list' %}">{% trans 'Back' %}</a>
  {% endif %}
{% endblock %}

{% block main %}
  {% if message %}
    <div class="alert alert-success">
      {{ message }}
    </div>
  {% endif %}
  <form action="" method="post" enctype="multipart/form-data">{% csrf_token %}
    {% if fileForm %}
      Select <strong>XLS</strong> file to import:
      <div {% if fileForm.file.errors %}class="error"{% endif %}>
        <div>{{fileForm.file.errors}}</div>
        {{ fileForm.file }}
        <hr>
        <div class="clearfix">
          <div class="pull-left">
            <input class="btn btn-primary" type="submit" value="{% trans 'Import' %}" />
            <a href="{{ STATIC_URL }}users_import.xls" class="btn btn-default">
              <i class="fa fa-file"></i>
              {% trans 'XLS example file' %}
            </a>
          </div>
        </div>
      </div>
    {% endif %}
    <div class="clearfix">
      <div class="pull-right">
        {% if userForm %}
          {{ userForm.filename }}
          <input class="btn btn-primary" type="submit" value="{% trans 'Import the following trainees' %}" />
          {% endif %}
      </div>
    </div>
  </form>
  {% if users %}
    <hr>
    <table class="table table-hover">
      <thead>
        <tr>
          <th>{% trans 'Username' %}</th>
          <th>{% trans 'First name' %}</th>
          <th>{% trans 'Last name' %}</th>
          <th>{% trans 'Email' %}</th>
          <th>{% trans 'Groupset' %}</th>
        </tr>
      </thead>
      <tbody>
        {% for user in users %}
          <tr>
            <td>{{user.username}}</td>
            <td>{{user.first_name}}</td>
            <td>{{user.last_name}}</td>
            <td>{{user.email}}</td>
            <td>{{user.groupset}}</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  {% endif %}
{% endblock %}
