{% extends 'base.html' %}

{% block content %}
    <h2>Search</h2>

    <form method="get" action=".">
        <table>
            {{ form.as_table }}
            <tr>
                <td>&nbsp;</td>
                <td>
                    <input type="submit" value="Search">
                </td>
            </tr>
        </table>

        {% if query %}
            <h3>Results</h3>

            {% for result in page.object_list %}
                {% with metadata=result.object.get_metadata %}
                <p>
                    <!-- <a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a> -->
                    <a href="{{ result.object.get_absolute_url }}">{{ result.object.PatChartNo }}</a> {{result.object.KeyCode}} 
                    {{ result.score }}
                    {{ metadata.手術日期}}
                    {{ metadata.手術主治醫師}}
                    {{ metadata.手術區域}}
                    {{ metadata.Operators}}
                    {{ metadata.Assistants}}
                </p>
                {% endwith %}
            {% empty %}
                <p>No results found.</p>
            {% endfor %}

            {% if page.has_previous or page.has_next %}
                <div>
                    {% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Previous{% if page.has_previous %}</a>{% endif %}
                    |
                    {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
                </div>
            {% endif %}
        {% else %}
            {# Show some example queries to run, maybe query syntax, something else? #}
        {% endif %}
    </form>
{% endblock %}
