Filtering of contacts in contact listing views
==============================================

    >>> browser = Browser('manager', 'schooltool')
    >>> browser.getLink('Manage').click()

Rename administrator.

    >>> browser.getLink('Persons').click()
    >>> browser.getLink('Administrator').click()
    >>> browser.getLink('Edit').click()
    >>> browser.getControl('First name').value = "Pedro"
    >>> browser.getControl('Middle name').value = "José Martínez"
    >>> browser.getControl('Last name').value = "Pérez"
    >>> browser.getControl('Gender').value = ['male']
    >>> browser.getControl('Apply').click()

Let's add a bunch of contacts:

    >>> from schooltool.contact.browser.ftests import addContact
    >>> for i in range(20):
    ...     addContact("Logan %s" % i, "Brown %s" % i, "Street %s" % i)

They should be visible in the contact list now:

    >>> browser.getLink('Manage').click()
    >>> browser.getLink('Contacts').click()
    >>> browser.printQuery("id('content-body')/form/table/tbody//tr/td[2]/a")
    <a href="http://localhost/contacts/Contact">Brown 0</a>
    <a href="http://localhost/contacts/Contact-2">Brown 1</a>
    <a href="http://localhost/contacts/Contact-11">Brown 10</a>
    <a href="http://localhost/contacts/Contact-12">Brown 11</a>
    <a href="http://localhost/contacts/Contact-13">Brown 12</a>
    <a href="http://localhost/contacts/Contact-14">Brown 13</a>
    <a href="http://localhost/contacts/Contact-15">Brown 14</a>
    <a href="http://localhost/contacts/Contact-16">Brown 15</a>
    <a href="http://localhost/contacts/Contact-17">Brown 16</a>
    <a href="http://localhost/contacts/Contact-18">Brown 17</a>
    <a href="http://localhost/contacts/Contact-19">Brown 18</a>
    <a href="http://localhost/contacts/Contact-20">Brown 19</a>
    <a href="http://localhost/contacts/Contact-3">Brown 2</a>
    <a href="http://localhost/contacts/Contact-4">Brown 3</a>
    <a href="http://localhost/contacts/Contact-5">Brown 4</a>
    <a href="http://localhost/contacts/Contact-6">Brown 5</a>
    <a href="http://localhost/contacts/Contact-7">Brown 6</a>
    <a href="http://localhost/contacts/Contact-8">Brown 7</a>
    <a href="http://localhost/contacts/Contact-9">Brown 8</a>
    <a href="http://localhost/contacts/Contact-10">Brown 9</a>
    <a href="http://localhost/persons/manager/contact">P&#195;&#169;rez</a>

Let's filter out all the contacts whose names contain "Logan 1":

    >>> browser.getControl(name='SEARCH_FIRST_NAME').value = "Logan 1"
    >>> browser.getControl('Find Now').click()

Only persons that match are in the list now:

    >>> browser.printQuery("id('content-body')/form/table/tbody//tr/td[2]/a")
    <a href="http://localhost/contacts/Contact-2">Brown 1</a>
    <a href="http://localhost/contacts/Contact-11">Brown 10</a>
    <a href="http://localhost/contacts/Contact-12">Brown 11</a>
    <a href="http://localhost/contacts/Contact-13">Brown 12</a>
    <a href="http://localhost/contacts/Contact-14">Brown 13</a>
    <a href="http://localhost/contacts/Contact-15">Brown 14</a>
    <a href="http://localhost/contacts/Contact-16">Brown 15</a>
    <a href="http://localhost/contacts/Contact-17">Brown 16</a>
    <a href="http://localhost/contacts/Contact-18">Brown 17</a>
    <a href="http://localhost/contacts/Contact-19">Brown 18</a>
    <a href="http://localhost/contacts/Contact-20">Brown 19</a>

We can filter by last name too:

    >>> browser.getControl(name='SEARCH_LAST_NAME').value = "Brown 19"
    >>> browser.getControl('Find Now').click()
    >>> browser.printQuery("id('content-body')/form/table/tbody//tr/td[2]/a")
    <a href="http://localhost/contacts/Contact-20">Brown 19</a>

The same search form has appeared in the contact management page, but
the LAST_NAME input field should contain the last name of the user in
it by default:

    >>> browser.getLink('Home').click()
    >>> browser.getLink('Contacts').click()

    >>> analyze.printQuery("//div[@class='content-nav']/a",
    ...                    browser.contents)
    <a href="http://localhost/persons/manager/contact/@@index.html">View</a>
    <a href="http://localhost/persons/manager/contact/@@edit.html">Edit</a>
    <a href="http://localhost/persons/manager">View Person</a>
    <a href="http://localhost/persons/manager/@@manage_contacts.html?SEARCH_LAST_NAME=P%C3%A9rez">Manage Contacts</a>

    >>> browser.getLink('Manage Contacts').click()
    >>> analyze.printQuery("id('filter_widget')",
    ...                    browser.contents)
    <div id="filter_widget">
        <div class="row">
          <div class="widget">
            <p class="hint"><label for="SEARCH_FIRST_NAME">First name</label></p>
            <input type="text" id="SEARCH_FIRST_NAME" name="SEARCH_FIRST_NAME" /></div>
          <div class="widget">
            <p class="hint"><label for="SEARCH_LAST_NAME">Last name</label></p>
            <input type="text" id="SEARCH_LAST_NAME" name="SEARCH_LAST_NAME" value="P&#195;&#169;rez" /></div>
        </div>
        <div class="controls" style="clear: both">
          <input class="button-ok" type="submit" name="SEARCH_BUTTON" value="Find Now"
        /><input class="button-cancel" type="submit" name="CLEAR_SEARCH" value="Clear" /></div>
      </div>

This is because most of the time contact person for a student is his relative.
