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

{% macro page_history(page) %}
  <p>{% trans page_name=page.name %}You're seeing the history of page "{{ page_name }}"{% endtrans %}</p>
  <ul>
    {% for r in (page.revisions.all()|sort(attribute='date', reverse=True)) %}
      {% if loop.index < 2 %}
        <li><a href="{{ url('core:page', page_name=page.get_full_name()) }}">{% trans %}last{% endtrans %}</a> -
          {{ user_profile_link(page.revisions.last().author) }} -
          {{ page.revisions.last().date|localtime|date(DATETIME_FORMAT) }} {{ page.revisions.last().date|localtime|time(DATETIME_FORMAT) }}</a></li>
      {% else %}
        <li><a href="{{ url('core:page_rev', page_name=page.get_full_name(), rev=r['id']) }}">{{ r.revision }}</a> -
          {{ user_profile_link(r.author) }} -
          {{ r.date|localtime|date(DATETIME_FORMAT) }} {{ r.date|localtime|time(DATETIME_FORMAT) }}</a></li>
      {% endif %}
    {% endfor %}
  </ul>
{% endmacro %}

{% macro page_edit_form(page, form, url, token) %}
  <h2>{% trans %}Edit page{% endtrans %}</h2>
  <form action="{{ url }}" method="post">
    <input type="hidden" name="csrfmiddlewaretoken" value="{{ token }}">
    {{ form.as_p() }}
    <p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
  </form>
{% endmacro %}
