=====================
Student Interventions
=====================

These are the functional tests for the intervention package.

First we need to set up the school.

    >>> from schooltool.intervention.browser.ftests import ftests
    >>> from schooltool.app.browser.ftests import setup
    >>> setup.setUpBasicSchool()
    >>> manager = setup.logIn('manager', 'schooltool')

We need to define a method that takes a browser instance and a username (plus
optional parent index for parents of the student) and returns the corresponding
checkbox control.

    >>> def choiceControl(browser, username, index=0):
    ...     resp = (browser.queryHTML("//input[@class='person_list']/@name") +
    ...            browser.queryHTML("//input[@class='changed_list']/@name"))
    ...     notif = browser.queryHTML("//input[@class='notified_list']/@name")
    ...     if index > 0:
    ...         return browser.getControl(name=notif[index])
    ...     for choice in resp + notif:
    ...         if choice.startswith('persons.' + username):
    ...             return browser.getControl(name=choice)
    ...     return None

Interventions
-------------

Now we come to the main intervention center that gives us access to all of the
intervention data associated with a given student for a given school year.
We'll create some teachers and students and put them in some sections.
We will also create a principal and guidance counselor and put them in the
adminstators group.  These users will show up as part of the list of persons
responsible for any student and will also have permission to work with the
intervention of any student.

    >>> from schooltool.intervention.browser.ftests.ftests import (
    ...     addPerson, addCourseSectionMembers, fillInContactInfo)

    >>> manager.getLink('Home').click()
    >>> fillInContactInfo('manager', email='manager@example.com')

    >>> addPerson('Teacher1', 'Teacher1', 'teacher1', 'pwd', groups=['teachers'])
    >>> addPerson('Teacher2', 'Teacher2', 'teacher2', 'pwd', groups=['teachers'])
    >>> addPerson('Student1', 'Student1', 'student1', 'pwd', groups=['students'])
    >>> addPerson('Student2', 'Student2', 'student2', 'pwd', groups=['students'])
    >>> addPerson('Student3', 'Student3', 'student3', 'pwd', groups=['students'])
    >>> addCourseSectionMembers('course1', 'section1', ['Teacher1'],
    ...     ['Student1', 'Student3'])
    >>> addCourseSectionMembers('course2', 'section2', ['Teacher2'],
    ...     ['Student2'])
    >>> addPerson('Counselor', 'Counselor', 'counselor', 'pwd', groups=['administrators'])
    >>> addPerson('Principal', 'Principal', 'principal', 'pwd', groups=['administrators'])
    >>> addPerson('Search Person', 'Person Search', 'sperson', 'pwd')

Let's add a parent contact and an advisor which will show up when adding goals
and messages.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('Student1').click()
    >>> manager.getLink('Contacts').click()
    >>> manager.getLink('Manage Contacts').click()
    >>> manager.getLink('Create new contact').click()
    >>> manager.getControl('First name').value = 'Parent1'
    >>> manager.getControl('Last name').value = 'Parent1'
    >>> manager.getControl('Email').value = 'parent@somewhere.com'
    >>> manager.getControl('Relationship').value = ['parent']
    >>> manager.getControl('Add').click()

    >>> manager.getLink('Advisors').click()
    >>> manager.getControl(name='add_item.teacher2').value = 'checked'
    >>> manager.getControl('Add').click()

To navigate to a student's intervention, a manager can navigate to the student
and click on the 'Intervention Center' action link.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('Student1').click()
    >>> manager.getLink('Intervention Center').click()
    >>> manager.printQuery("id('content-body')//table/tr/td[3]/a/text()")
    Student1 Student1
    >>> manager.printQuery("id('content-body')//legend/b")
    <b>Messages and Observations</b>
    <b>Goals and Interventions</b>
    <b>Report Sheets</b>
    <b>Change of Status Messages</b>
    >>> manager.printQuery("id('content-body')//fieldset//a/text()")
    New Message
    View All Messages
    New Goal
    View All Goals
    New Status Message
    View All Status Messages
    >>> manager.printQuery("id('content-body')//fieldset//li/text()")
    There are none.
    There are none.
    There are none.


Intervention Messages
---------------------

The first thing we'll add is a new message.  Calling up the add view, we'll
note that the list of possible recipients will include, in order, the student's
advisors, the school administrators, the student's teachers, the student,
and the student's parents.  Advisors and parents will have descriptors
after their names to make it easier for the user to pick them out.  Also,
the advisors will be pre-checked.

    >>> manager.getLink('New Message').click()
    >>> manager.printQuery("id('content-body')//input[@type='checkbox']")
    <input type="checkbox" class="person_list" checked="checked" name="persons.teacher2-..." />
    <input type="checkbox" class="person_list" name="persons.counselor-..." />
    <input type="checkbox" class="person_list" name="persons.principal-..." />
    <input type="checkbox" class="person_list" name="persons.teacher1-..." />
    <input type="checkbox" class="notified_list" name="persons.student1-..." />
    <input type="checkbox" class="notified_list" name="contacts.Contact-..." />
    >>> manager.printQuery("id('content-body')//span/b")
    <b>Teacher2 Teacher2 (advisor)</b>
    <b>Counselor Counselor</b>
    <b>Principal Principal</b>
    <b>Teacher1 Teacher1</b>
    <b>Student1 Student1</b>
    <b>Parent1 Parent1 (parent)</b>

We'll test how the add view handles missing input.  We'll need to uncheck the
advisor to make the recipients input cause the error.

    >>> choiceControl(manager, 'teacher2').value = False
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> manager.printQuery("id('content-body')//fieldset/p[2]")
    <p> There are <strong>2</strong> input errors. </p>
    >>> manager.printQuery("id('content-body')//div[@class='error']")
    <div class="error">Required data was not supplied.</div>
    <div class="error">
      <span class="error">Required input is missing.</span>
    </div>

We'll fill in the required fields and hit the Add button.  Note that upon
successfully adding the message, an email will appear in the output.  This
is the result of the dummy mail sender that we use during testing that prints
emails that would otherwise be sent to the smtp mail server that a live
environment would have configured.  Also note that the parent's email address
will be picked up from the student's demos.

    >>> choiceControl(manager, 'teacher1').value = True
    >>> choiceControl(manager, 'student1', index=1).value = True
    >>> manager.getControl(name='field.body').value = 'hi\nthere'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: parent@somewhere.com, teacher1@example.com
    Subject: INTERVENTION MESSAGE: Student1 Student1
    SchoolTool Administrator writes:
    <BLANKLINE>
    hi
    there

Note that the successfully added message appears in the Intervention Center
with the username of the sender, in this case, manager.

    >>> manager.printQuery("id('content-body')//fieldset[1]//li/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/messages/1">Message from SchoolTool Administrator sent ...</a>

Let's make sure we can view the message that we just added.  Note that the
message body will be broken into <p> tags, one for each line.

    >>> manager.getLink('Message from SchoolTool Administrator').click()
    >>> manager.printQuery("id('content-body')//div//span")
    <span>Parent1 Parent1, Teacher1 Teacher1</span>
    >>> manager.printQuery("id('content-body')//p")
    <p>hi</p>
    <p>there</p>

We should be able to return to the Intervention Center with a link.

    >>> manager.getLink('Intervention Center').click()
    >>> manager.printQuery("id('content-body')//fieldset[1]//li/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/messages/1">Message from SchoolTool Administrator sent ...</a>

We'll add a second message to test the system's handling of multiple
messages.  Messages are sorted by date.

    >>> manager.getLink('New Message').click()
    >>> choiceControl(manager, 'teacher1').value = True
    >>> manager.getControl(name='field.body').value = 'hello again'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com, teacher2@example.com
    Subject: INTERVENTION MESSAGE: Student1 Student1
    SchoolTool Administrator writes:
    <BLANKLINE>
    hello again
    >>> manager.printQuery("id('content-body')//fieldset[1]//li/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/messages/2">Message from SchoolTool Administrator sent ...</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/messages/1">Message from SchoolTool Administrator sent ...</a>

There is a button that allows us to call up the report that presents all of
the messages together.  The messages are sorted by creation date.

    >>> manager.getLink('View All Messages').click()
    >>> manager.printQuery("id('content-body')//span")
    <span>Message sent by SchoolTool Administrator on ...</span>
    <span>Teacher1 Teacher1, Teacher2 Teacher2</span>
    <span>Message sent by SchoolTool Administrator on ...</span>
    <span>Parent1 Parent1, Teacher1 Teacher1</span>
    >>> manager.printQuery("id('content-body')//p")
    <p>hello again</p>
    <p>hi</p>
    <p>there</p>

We'll return the the Intervention Center.

    >>> manager.getLink('Intervention Center').click()
    >>> manager.printQuery("id('content-body')//legend/b")
    <b>Messages and Observations</b>
    <b>Goals and Interventions</b>
    <b>Report Sheets</b>
    <b>Change of Status Messages</b>

We need a test for canceling out of the add message view.  It should return
us back to the Intervention Center.

    >>> manager.getLink('New Message').click()
    >>> manager.getControl(name='CANCEL').click()
    >>> manager.printQuery("id('content-body')//legend/b")
    <b>Messages and Observations</b>
    <b>Goals and Interventions</b>
    <b>Report Sheets</b>
    <b>Change of Status Messages</b>


Intervention Goals
------------------

The next thing to start adding is Goals.  We'll test how the add view
handles missing input while we're at it.  To make the persons responsible
field have missing data, we'll need to uncheck the advisor that comes
pre-checked.

    >>> manager.getLink('New Goal').click()
    >>> manager.printQuery("id('content-body')//input[@type='checkbox']")
    <input type="checkbox" class="person_list" checked="checked" name="persons.teacher2-..." />
    <input type="checkbox" class="person_list" name="persons.counselor-..." />
    <input type="checkbox" class="person_list" name="persons.principal-..." />
    <input type="checkbox" class="person_list" name="persons.teacher1-..." />
    <input type="checkbox" class="notified_list" name="persons.student1-..." />
    <input type="checkbox" class="notified_list" name="contacts.Contact-..." />
    >>> manager.printQuery("id('content-body')//input[@type='radio']")
    <input type="radio" name="goal_met" value="No" checked="checked" />
    <input type="radio" name="goal_met" value="Yes" />

    >>> choiceControl(manager, 'teacher2').value = False
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> manager.printQuery("id('content-body')//form/p[2]")
    <p> There are <strong>7</strong> input errors. </p>
    >>> manager.printQuery("id('content-body')//div[@class='error']")
    <div class="error">Required data was not supplied.</div>
    <div class="error">
      <span class="error">Required input is missing.</span>
    </div>
    <div class="error">
      <span class="error">Required input is missing.</span>
    </div>
    <div class="error">
      <span class="error">Required input is missing.</span>
    </div>
    <div class="error">
      <span class="error">Required input is missing.</span>
    </div>
    <div class="error">
      <span class="error">Required input is missing.</span>
    </div>
    <div class="error">
      <span class="error">Required input is missing.</span>
    </div>

Now we'll fill in the required fields.  We'll include the student and the
parent in the persons responsible list to demostrate how adding the goal
will split the email by staff and students/parents.  Students and parents
will not get a link back to the intervention center in their email.

    >>> from datetime import date
    >>> manager.getControl('Presenting concerns').value = 'Poor attendence'
    >>> manager.getControl(name='field.goal').value = 'Get student to come in more often'
    >>> manager.getControl('Strengths').value = 'Attentive when there'
    >>> manager.getControl('Indicators').value = 'Student appears at least 4 time a week'
    >>> manager.getControl('Intervention').value = 'Call parents to arrange better attendence'
    >>> manager.getControl('Timeline').value = str(date.today())
    >>> choiceControl(manager, 'teacher1').value = True
    >>> choiceControl(manager, 'student1').value = True
    >>> choiceControl(manager, 'student1', index=1).value = True
    >>> manager.getControl(name='goal_met').value = ['Yes']
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION GOAL ADDED: Student1 Student1
    The following goal was added for Student1 Student1:
    <BLANKLINE>
    Presenting concerns
    -------------------
    <BLANKLINE>
    Poor attendence
    <BLANKLINE>
    Goal
    ----
    <BLANKLINE>
    Get student to come in more often
    <BLANKLINE>
    Strengths
    ---------
    <BLANKLINE>
    Attentive when there
    <BLANKLINE>
    Indicators
    ----------
    <BLANKLINE>
    Student appears at least 4 time a week
    <BLANKLINE>
    Intervention
    ------------
    <BLANKLINE>
    Call parents to arrange better attendence
    <BLANKLINE>
    Timeline
    --------
    <BLANKLINE>
    ...
    <BLANKLINE>
    Persons responsible
    -------------------
    <BLANKLINE>
    Parent1 Parent1
    Student1 Student1
    Teacher1 Teacher1
    <BLANKLINE>
    Intervention Center
    -------------------
    <BLANKLINE>
    http://localhost/schooltool.interventions/2005-2006/student1
    <BLANKLINE>
    From: manager@example.com
    To: parent@somewhere.com, student1@example.com
    Subject: INTERVENTION GOAL ADDED: Student1 Student1
    The following goal was added for Student1 Student1:
    <BLANKLINE>
    Presenting concerns
    -------------------
    <BLANKLINE>
    Poor attendence
    <BLANKLINE>
    Goal
    ----
    <BLANKLINE>
    Get student to come in more often
    <BLANKLINE>
    Strengths
    ---------
    <BLANKLINE>
    Attentive when there
    <BLANKLINE>
    Indicators
    ----------
    <BLANKLINE>
    Student appears at least 4 time a week
    <BLANKLINE>
    Intervention
    ------------
    <BLANKLINE>
    Call parents to arrange better attendence
    <BLANKLINE>
    Timeline
    --------
    <BLANKLINE>
    ...
    <BLANKLINE>
    Persons responsible
    -------------------
    <BLANKLINE>
    Parent1 Parent1
    Student1 Student1
    Teacher1 Teacher1

Note that the successfully added goal appears in the Intervention Center as
'Goal 1'.

    >>> manager.printQuery("id('content-body')//fieldset[2]//li/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/goals/1">Goal 1 - Added ... - Due ... - CLOSED</a>

We need a test for canceling out of the add goal view.  It should return
us back to the Intervention Center.

    >>> manager.getLink('New Goal').click()
    >>> manager.getControl(name='CANCEL').click()
    >>> manager.printQuery("id('content-body')//fieldset[2]//li/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/goals/1">Goal 1 - Added ... - Due ... - CLOSED</a>

Let's make sure we can view the goal that we just added.

    >>> manager.getLink('Goal 1').click()
    >>> manager.printQuery("id('content-body')/div//p")
    <p>Parent1 Parent1, Student1 Student1, Teacher1 Teacher1</p>
    <p>Poor attendence</p>
    <p>Get student to come in more often</p>
    <p>Attentive when there</p>
    <p>Student appears at least 4 time a week</p>
    <p>Call parents to arrange better attendence</p>
    <p>...</p>
    <p>Yes</p>
    <p></p>

Now that we've added a goal, let's edit it's strengths attribute and see that
the change is reflected in the goal's view.

    >>> manager.getLink('Edit').click()
    >>> manager.printQuery("id('content-body')//input[@type='checkbox']")
    <input type="checkbox" class="person_list" name="persons.teacher2-..." />
    <input type="checkbox" class="person_list" name="persons.counselor-..." />
    <input type="checkbox" class="person_list" name="persons.principal-..." />
    <input type="checkbox" class="person_list" checked="checked" name="persons.teacher1-..." />
    <input type="checkbox" class="notified_list" checked="checked" name="persons.student1-..." />
    <input type="checkbox" class="notified_list" checked="checked" name="contacts.Contact-..." />
    >>> manager.printQuery("id('content-body')//input[@type='radio']")
    <input type="radio" name="goal_met" value="No" />
    <input type="radio" name="goal_met" value="Yes" checked="checked" />
    >>> manager.printQuery("id('content-body')//textarea/text()")
    Poor attendence
    Get student to come in more often
    Attentive when there
    Student appears at least 4 time a week
    Call parents to arrange better attendence

    >>> manager.getControl('Strengths').value = 'Good listener'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    >>> manager.printQuery("id('content-body')//p")
    <p>Parent1 Parent1, Student1 Student1, Teacher1 Teacher1</p>
    <p>Poor attendence</p>
    <p>Get student to come in more often</p>
    <p>Good listener</p>
    <p>Student appears at least 4 time a week</p>
    <p>Call parents to arrange better attendence</p>
    <p>...</p>
    <p>Yes</p>
    <p></p>

We should be able to return to the Intervention Center with a link.

    >>> manager.getLink('Intervention Center').click()
    >>> manager.printQuery("id('content-body')//fieldset[2]//li/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/goals/1">Goal 1 - Added ... - Due ... - CLOSED</a>

We can also cancel out of editing a goal which should return us back to the
goal's view.

    >>> manager.getLink('Goal 1').click()
    >>> manager.getLink('Edit').click()
    >>> manager.getControl(name='CANCEL').click()
    >>> manager.printQuery("id('content-body')/div//p")
    <p>Parent1 Parent1, Student1 Student1, Teacher1 Teacher1</p>
    <p>Poor attendence</p>
    <p>Get student to come in more often</p>
    <p>Good listener</p>
    <p>Student appears at least 4 time a week</p>
    <p>Call parents to arrange better attendence</p>
    <p>...</p>
    <p>Yes</p>
    <p></p>

Let's add a second goal to test our handling of multiple goals both in the
notification view and the goals report.

    >>> manager.getLink('Intervention Center').click()
    >>> manager.getLink('New Goal').click()
    >>> manager.getControl('Presenting concerns').value = 'Rude behavior'
    >>> manager.getControl(name='field.goal').value = 'Get student to be more polite'
    >>> manager.getControl('Strengths').value = 'Good grades'
    >>> manager.getControl('Indicators').value = 'Student no longer offends classmates'
    >>> manager.getControl('Intervention').value = 'Call parents to alert them to bad manners'
    >>> manager.getControl('Timeline').value = str(date.today())
    >>> choiceControl(manager, 'teacher2').value = False
    >>> choiceControl(manager, 'teacher1').value = True
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION GOAL ADDED: Student1 Student1
    The following goal was added for Student1 Student1:
    <BLANKLINE>
    Presenting concerns
    -------------------
    <BLANKLINE>
    Rude behavior
    <BLANKLINE>
    Goal
    ----
    <BLANKLINE>
    Get student to be more polite
    <BLANKLINE>
    Strengths
    ---------
    <BLANKLINE>
    Good grades
    <BLANKLINE>
    Indicators
    ----------
    <BLANKLINE>
    Student no longer offends classmates
    <BLANKLINE>
    Intervention
    ------------
    <BLANKLINE>
    Call parents to alert them to bad manners
    <BLANKLINE>
    Timeline
    --------
    <BLANKLINE>
    ...
    <BLANKLINE>
    Persons responsible
    -------------------
    <BLANKLINE>
    Teacher1 Teacher1
    <BLANKLINE>
    Intervention Center
    -------------------
    <BLANKLINE>
    http://localhost/schooltool.interventions/2005-2006/student1
    >>> manager.printQuery("id('content-body')//fieldset[2]//li/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/goals/1">Goal 1 - Added ... - Due ... - CLOSED</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/goals/2">Goal 2 - Added ... - Due ... - OPEN</a>

There is a button that allows us to call up the report that presents all of
the goals together.  Its output is a concatonation of what the view of goal 1
and the view of goal 2 would present.

    >>> manager.getLink('View All Goals').click()
    >>> manager.printQuery("id('content-body')//h3")
    <h3>Presenting concerns</h3>
    <h3>Goal</h3>
    <h3>Strengths</h3>
    <h3>Indicators</h3>
    <h3>Intervention</h3>
    <h3>Timeline</h3>
    <h3> Persons responsible: </h3>
    <h3>Goal met</h3>
    <h3>Follow up notes</h3>
    <h3>Presenting concerns</h3>
    <h3>Goal</h3>
    <h3>Strengths</h3>
    <h3>Indicators</h3>
    <h3>Intervention</h3>
    <h3>Timeline</h3>
    <h3> Persons responsible: </h3>
    <h3>Goal met</h3>
    <h3>Follow up notes</h3>
    >>> manager.printQuery("id('content-body')//span")
    <span>Parent1 Parent1</span>
    <span>Student1 Student1</span>
    <span>Teacher1 Teacher1</span>
    <span>Teacher1 Teacher1</span>
    >>> manager.printQuery("id('content-body')//p")
    <p>Poor attendence</p>
    <p>Get student to come in more often</p>
    <p>Good listener</p>
    <p>Student appears at least 4 time a week</p>
    <p>Call parents to arrange better attendence</p>
    <p>...</p>
    <p>Yes</p>
    <p></p>
    <p>Rude behavior</p>
    <p>Get student to be more polite</p>
    <p>Good grades</p>
    <p>Student no longer offends classmates</p>
    <p>Call parents to alert them to bad manners</p>
    <p>...</p>
    <p>No</p>
    <p></p>

We have a view that can be called up at any time that will send emails for
goals that have come due today (we set up our goals to be due today).  This
view will best be called automatically from a cron job making it a completely
automated system.  Note that student and parent entered in the first goal will
not receive this email.

    >>> manager.open('http://localhost/schooltool.interventions/notifyGoals.html')
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION GOAL DUE: Student1 Student1
    Please follow the link below to update the follow up notes and, if
    appropriate, the goal met status of the intervention goal for Student1 Student1.
    <BLANKLINE>
    http://localhost/schooltool.interventions/2005-2006/student1/goals/1/@@editGoal.html
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION GOAL DUE: Student1 Student1
    Please follow the link below to update the follow up notes and, if
    appropriate, the goal met status of the intervention goal for Student1 Student1.
    <BLANKLINE>
    http://localhost/schooltool.interventions/2005-2006/student1/goals/2/@@editGoal.html

    >>> manager.printQuery("id('content-body')//p")
    <p>The following goals had notifications sent to the persons responsible:</p>
    >>> manager.printQuery("id('content-body')//li/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/goals/1">Student1 Student1 goal 1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/goals/2">Student1 Student1 goal 2</a>

Now that the goals have been marked as notified, calling up the view again will
yield nothing.

    >>> manager.open('http://localhost/schooltool.interventions/notifyGoals.html')
    >>> manager.printQuery("id('content-body')//li")
    <li>There are no goals that need notification.</li>

Also, the notification flag will be reflected in the goal's view as well as
the view for all goals.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('Student1').click()
    >>> manager.getLink('Intervention Center').click()

    >>> manager.getLink('Goal 1').click()
    >>> manager.printQuery("id('content-body')//table/tr[1]/td[1]/h1")
    <h1> Persons responsible: notification sent </h1>

    >>> manager.getLink('Intervention Center').click()
    >>> manager.getLink('View All Goals').click()
    >>> manager.printQuery("id('content-body')//h3")
    <h3>Presenting concerns</h3>
    <h3>Goal</h3>
    <h3>Strengths</h3>
    <h3>Indicators</h3>
    <h3>Intervention</h3>
    <h3>Timeline</h3>
    <h3> Persons responsible: notification sent </h3>
    <h3>Goal met</h3>
    <h3>Follow up notes</h3>
    <h3>Presenting concerns</h3>
    <h3>Goal</h3>
    <h3>Strengths</h3>
    <h3>Indicators</h3>
    <h3>Intervention</h3>
    <h3>Timeline</h3>
    <h3> Persons responsible: notification sent </h3>
    <h3>Goal met</h3>
    <h3>Follow up notes</h3>

Change of Status Messages
-------------------------

There is a need for special change of status messages that would rarely be
sent and should be organized at the bottom part of the Intervention Center.
The most extreme example of changing a student's status would be to expel
the student from school.  Messages of that nature and less extreme can be
added using the separate 'Change of Status Messages' section of the student's
Intervention Center.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('Student1').click()
    >>> manager.getLink('Intervention Center').click()

    >>> manager.getLink('New Status Message').click()
    >>> choiceControl(manager, 'teacher2').value = False
    >>> choiceControl(manager, 'teacher1').value = True
    >>> manager.getControl(name='field.body').value = 'hello'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION STATUS CHANGE: Student1 Student1
    SchoolTool Administrator writes:
    <BLANKLINE>
    hello

We see that it shows up in the intervention center.

    >>> manager.printQuery("id('content-body')//fieldset[4]//li/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/messages/3">Change of Status Message from SchoolTool Administrator sent ...</a>

Let's make sure we can view the message that we just added.

    >>> manager.getLink('Change of Status Message from SchoolTool Administrator').click()
    >>> manager.printQuery("id('content-body')//h3")
    <h3>Change of Status Message from: SchoolTool Administrator sent ...</h3>
    >>> manager.printQuery("id('content-body')//span")
    <span>Teacher1 Teacher1</span>
    >>> manager.printQuery("id('content-body')//p")
    <p>hello</p>

There is a view for viewing all change of status messages together as there
is with normal messages.

    >>> manager.getLink('Intervention Center').click()
    >>> manager.getLink('View All Status Messages').click()
    >>> manager.printQuery("id('content-body')//h3")
    <h3>Change of Status Messages regarding Student1 Student1</h3>
    >>> manager.printQuery("id('content-body')//span")
    <span>Message sent by SchoolTool Administrator on ...</span>
    <span>Teacher1 Teacher1</span>
    >>> manager.printQuery("id('content-body')//p")
    <p>hello</p>


SchoolYear Change
-----------------

For convenience we have a dropdown in the student intervention center to
change the schoolyear to a previous year.  Since we don't have a previous
year, we need to add one.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('School Years').click()
    >>> manager.getLink('New School Year').click()
    >>> manager.getControl('Title').value = '2004-2005'
    >>> manager.getControl('First day').value = '2004-09-01'
    >>> manager.getControl('Last day').value = '2005-07-15'
    >>> manager.getControl('Add').click()

Now when we change the dropdown, we will see that we are at the intervention
center for the same student, but for the previous year.  Also, there are no
messages or goals because we never added any for that year.  Finally, there are
no buttons for adding messages or goals becuase adding them to an obsolete year
would not make sense.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('Persons').click()
    >>> manager.getLink('Student1').click()
    >>> manager.getLink('Intervention Center').click()
    >>> manager.getControl(name="schoolyear").value = ['2004-2005']
    >>> manager.getForm().submit()

    >>> manager.printQuery("id('content-body')//table/tr[1]/td[3]/a")
    <a href="http://localhost/persons/student1">Student1 Student1</a>
    >>> manager.printQuery("id('content-body')//form//select")
    <select name="schoolyear" onchange="this.form.submit()">
      <option value="2004-2005" selected="selected">2004-2005</option>
      <option value="2005-2006">2005-2006</option>
    </select>
    >>> manager.printQuery("id('content-body')//legend/b")
    <b>Messages and Observations</b>
    <b>Goals and Interventions</b>
    <b>Report Sheets</b>
    <b>Change of Status Messages</b>
    >>> manager.queryHTML("id('content-body')//fieldset[1]//li/a")
    []
    >>> manager.queryHTML("id('content-body')//fieldset[2]//li/a")
    []
    >>> manager.queryHTML("id('content-body')//fieldset[4]//li/a")
    []
    >>> manager.printQuery("id('content-body')//fieldset//a/text()")
    View All Messages
    View All Goals
    View All Status Messages


Section intervention view
-------------------------

The section intervention view gives quick access to various
intervention views for students in the section.

    >>> manager.getLink('Manage').click()
    >>> manager.getLink('School Years').click()
    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Spring').click()
    >>> manager.getLink('Sections').click()
    >>> manager.getLink('section1').click()
    >>> manager.getLink('Interventions').click()

The Messages tab is the default.  The provided links allow the teacher to
preview existing and compose new messages.  Note that status messages are
ignored when displaying message count for the student.

    >>> manager.printQuery("id('content-body')//div[@class='student_nav_link']/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/messages/allMessages.html">View Messages (2)</a>
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/1/messages/student1/+/addMessage.html">Write New</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3/messages/allMessages.html">View Messages (0)</a>
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/1/messages/student3/+/addMessage.html">Write New</a>
    >>> manager.printQuery("id('content-body')//div[@class='tabmenu']/a")
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/1/interventions.html?TAB=goals">Goals</a>
    >>> manager.printQuery("id('content-body')//td/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1 Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3 Student3</a>

We can add a new message from here by clicking on the 'Write New' link.  We'll
do this for Student3 to help set up dashboard tests.

    >>> manager.getLink('Write New', index=1).click()
    >>> choiceControl(manager, 'teacher1').value = True
    >>> manager.getControl(name='field.body').value = 'Message for Student3'
    >>> manager.getControl(name='UPDATE_SUBMIT').click()
    From: manager@example.com
    To: teacher1@example.com
    Subject: INTERVENTION MESSAGE: Student3 Student3
    SchoolTool Administrator writes:
    <BLANKLINE>
    Message for Student3

The Goals tab provides shortcuts to viewing student goals.

    >>> manager.getLink('Goals').click()
    >>> manager.printQuery("id('content-body')//div[@class='student_nav_link']/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1/goals/allGoals.html">View Goals (2)</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3/goals/allGoals.html">View Goals (0)</a>
    >>> manager.printQuery("id('content-body')//div[@class='tabmenu']/a")
    <a href="http://localhost/schoolyears/2005-2006/spring/sections/1/interventions.html?TAB=messages">Messages</a>
    >>> manager.printQuery("id('content-body')//td/a")
    <a href="http://localhost/schooltool.interventions/2005-2006/student1">Student1 Student1</a>
    <a href="http://localhost/schooltool.interventions/2005-2006/student3">Student3 Student3</a>


At One Time Responsible
-----------------------

We have a special case in the user interface for editing goals where one of
the persons_responsible is no longer either a teacher, advisor or administrator
of the student.  The security issues regarding this scenario are tested in
security.txt, but here we need to test the way it is handled in the UI.

First of all, we already have created a goal where teacher1 is responsible.
When we call up the edit view for the goal, we note that teacher1 appears
in the staff section of the person list, not the student section.  We also
note that he is checked.

    >>> manager.open('http://localhost/schooltool.interventions/2005-2006/student1/goals/2/editGoal.html')
    >>> manager.printQuery('//table//tr[2]//td[1]//span')
    <span>
      <b>Teacher2 Teacher2 (advisor)</b>
    </span>
    <span>
      <b>Counselor Counselor</b>
    </span>
    <span>
      <b>Principal Principal</b>
    </span>
    <span>
      <b>Teacher1 Teacher1</b>
    </span>
    >>> manager.printQuery('//table//tr[2]//td[1]//b')
    <b>Teacher2 Teacher2 (advisor)</b>
    <b>Counselor Counselor</b>
    <b>Principal Principal</b>
    <b>Teacher1 Teacher1</b>
    >>> manager.printQuery('//table//tr[2]//td[2]//b')
    <b>Student1 Student1</b>
    <b>Parent1 Parent1 (parent)</b>
    >>> manager.printQuery('//table//tr[2]//td[2]//b')
    <b>Student1 Student1</b>
    <b>Parent1 Parent1 (parent)</b>

We want to remove him from the section that gave him access to the student.

    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Spring').click()
    >>> manager.getLink('Sections').click()
    >>> manager.getLink('section1').click()
    >>> manager.getLink('edit instructors').click()
    >>> manager.getControl(name='remove_item.teacher1').value = 'checked'
    >>> manager.getControl('Remove').click()

Now, let's edit the goal and note that there is a new section in the person
list labeled 'Changed Status' and that teacher1 is listed there and is still
checked.

    >>> manager.open('http://localhost/schooltool.interventions/2005-2006/student1/goals/2/editGoal.html')
    >>> manager.printQuery('//table//tr[2]//td[1]//b')
    <b>Teacher2 Teacher2 (advisor)</b>
    <b>Counselor Counselor</b>
    <b>Principal Principal</b>
    >>> manager.printQuery('//table//tr[2]//td[1]//b')
    <b>Teacher2 Teacher2 (advisor)</b>
    <b>Counselor Counselor</b>
    <b>Principal Principal</b>
    >>> manager.printQuery('//table//tr[2]//td[2]//span')
    <span>
      <b>Student1 Student1</b>
    </span>
    <span>
      <b>Parent1 Parent1 (parent)</b>
    </span>
    <span>Changed Status</span>
    <span>
      <b>Teacher1 Teacher1</b>
    </span>
    >>> manager.printQuery('//table//tr[2]//td[2]//input[@class="changed_list"]/@checked')
    checked

We'll go ahead and uncheck him, or course, checking another person in order
to successfully submit.

    >>> choiceControl(manager, 'teacher1').value = False
    >>> choiceControl(manager, 'teacher2').value = True
    >>> manager.getControl('Apply').click()

Now we see that the teacher is still in the 'Changed Status' section but not
checked.  This represents the scenario where the teacher no longer can
add goals for the student, nor can he even view this goal anymore.  However,
we keep him around in the goal.at_one_time_responsible list, and thus, he
will continue to appear in the person list in the special section.  Maybe we'll
want to put him back in the persons_responsible list at a later date.

    >>> manager.open('http://localhost/schooltool.interventions/2005-2006/student1/goals/2/editGoal.html')
    >>> manager.printQuery('//table//tr[2]//td[1]//b')
    <b>Teacher2 Teacher2 (advisor)</b>
    <b>Counselor Counselor</b>
    <b>Principal Principal</b>
    >>> manager.printQuery('//table//tr[2]//td[2]//span')
    <span>
      <b>Student1 Student1</b>
    </span>
    <span>
      <b>Parent1 Parent1 (parent)</b>
    </span>
    <span>Changed Status</span>
    <span>
      <b>Teacher1 Teacher1</b>
    </span>
    >>> manager.printQuery('//table//tr[2]//td[2]//input[@class="changed_list"]/@checked')

Finally, we'd like to make sure that when we make teacher1 again the teacher
of one of student1's sections, he will appear back in the original section
of the person list.

    >>> manager.getLink('2005-2006').click()
    >>> manager.getLink('Spring').click()
    >>> manager.getLink('Sections').click()
    >>> manager.getLink('section1').click()
    >>> manager.getLink('edit instructors').click()
    >>> manager.getControl(name='add_item.teacher1').value = 'checked'
    >>> manager.getControl('Add').click()

So now when we go back to edit the goal, teacher1 appears back in the original
section, unchecked.  Also, the 'Changed Status' section disappears.  It's like
he was never gone.

    >>> manager.open('http://localhost/schooltool.interventions/2005-2006/student1/goals/2/editGoal.html')
    >>> manager.printQuery('//table//tr[2]//td[1]//b')
    <b>Teacher2 Teacher2 (advisor)</b>
    <b>Counselor Counselor</b>
    <b>Principal Principal</b>
    <b>Teacher1 Teacher1</b>
    >>> manager.printQuery('//table//tr[2]//td[2]//span')
    <span>
      <b>Student1 Student1</b>
    </span>
    <span>
      <b>Parent1 Parent1 (parent)</b>
    </span>


Intervention CSV views
----------------------

We supply CSV views for extracting the messages and goals from a schooltool
instance.

    >>> manager.open('http://localhost/messages.csv')
    >>> print manager.contents
    "year","student","date","sender","recipients","body"
    "2005-2006","student1","...","manager","parent@somewhere.com, teacher1@example.com","hi\nthere"
    "2005-2006","student1","...","manager","teacher1@example.com, teacher2@example.com","hello again"
    "2005-2006","student1","...","manager","teacher1@example.com","hello"
    "2005-2006","student3","...","manager","teacher1@example.com","Message for Student3"

    >>> manager.open('http://localhost/goals.csv')
    >>> print manager.contents
    "year","student","created","creator","presenting_concerns","goal","strengths","indicators","intervention","timeline","persons_responsible","goal_met","follow_up_notes","notified"
    "2005-2006","student1","...","manager","Poor attendence","Get student to come in more often","Good listener","Student appears at least 4 time a week","Call parents to arrange better attendence","...","parent@somewhere.com, student1@example.com, teacher1@example.com","True","","True"
    "2005-2006","student1","...","manager","Rude behavior","Get student to be more polite","Good grades","Student no longer offends classmates","Call parents to alert them to bad manners","...","teacher2@example.com","False","","True"

