Ignore:
Timestamp:
25 Aug 2011, 12:01:37 (13 years ago)
Author:
Henrik Bettermann
Message:

Add students_catalog and search facilities.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r6622 r6626  
    4545from waeup.sirp.browser.resources import datepicker, tabs, datatable
    4646from waeup.sirp.browser.viewlets import (
    47     ManageActionButton, PrimaryNavTab, LeftSidebarLink
     47    ManageActionButton, PrimaryNavTab, LeftSidebarLink, AddActionButton,
    4848    )
    4949from waeup.sirp.image.browser.widget import (
     
    6767    Student,
    6868    )
     69from waeup.sirp.students.catalog import search
    6970
    7071class StudentsTab(PrimaryNavTab):
     
    8485        return self.view.application_url('students')
    8586
    86 class StudentsContainerPage(WAeUPDisplayFormPage):
    87     """The standard view for regular student containers.
     87class StudentsContainerPage(WAeUPPage):
     88    """The standard view for student containers.
    8889    """
    8990    grok.context(IStudentsContainer)
     
    9293    grok.template('studentscontainerpage')
    9394
    94     form_fields = grok.AutoFields(IStudentsContainer)
    95     #form_fields['description'].custom_widget = ReSTDisplayWidget
    96 
    9795    @property
    9896    def title(self):
     
    103101        return self.title
    104102
    105 class StudentssContainerManageActionButton(ManageActionButton):
     103    def update(self, *args, **kw):
     104        datatable.need()
     105        form = self.request.form
     106        self.hitlist = []
     107        if 'searchterm' in form and form['searchterm']:
     108            self.searchterm = form['searchterm']
     109            self.searchtype = form['searchtype']
     110        elif 'old_searchterm' in form:
     111            self.searchterm = form['old_searchterm']
     112            self.searchtype = form['old_searchtype']
     113        else:
     114            if 'search' in form:
     115                self.flash('Empty search string.')
     116            return
     117        self.hitlist = search(query=self.searchterm,
     118            searchtype=self.searchtype, view=self)
     119        if not self.hitlist:
     120            self.flash('No student found.')
     121        return
     122
     123class StudentsContainerManageActionButton(ManageActionButton):
    106124    grok.order(1)
    107125    grok.context(IStudentsContainer)
     
    110128    text = 'Manage students'
    111129
    112 class StudentsContainerManagePage(WAeUPDisplayFormPage):
    113     """The standard view for regular student containers.
     130
     131class StudentsContainerManagePage(WAeUPPage):
     132    """The manage page for student containers.
    114133    """
    115134    grok.context(IStudentsContainer)
    116135    grok.name('manage')
    117136    grok.require('waeup.manageStudents')
    118     grok.template('studentscontainerpage')
    119 
    120     form_fields = grok.AutoFields(IStudentsContainer)
     137    grok.template('studentscontainermanagepage')
    121138
    122139    @property
     
    128145        return self.title
    129146
    130     @grok.action('Add student', validator=NullValidator)
    131     def addStudent(self, **data):
    132         self.redirect(self.url(self.context, 'addstudent'))
     147    def update(self, *args, **kw):
     148        datatable.need()
     149        form = self.request.form
     150        self.hitlist = []
     151        if 'searchterm' in form and form['searchterm']:
     152            self.searchterm = form['searchterm']
     153            self.searchtype = form['searchtype']
     154        elif 'old_searchterm' in form:
     155            self.searchterm = form['old_searchterm']
     156            self.searchtype = form['old_searchtype']
     157        else:
     158            if 'search' in form:
     159                self.flash('Empty search string.')
     160            return
     161        #import pdb; pdb.set_trace()
     162        if not 'entries' in form:
     163            self.hitlist = search(query=self.searchterm,
     164                searchtype=self.searchtype, view=self)
     165            if not self.hitlist:
     166                self.flash('No student found.')
     167            return
     168        entries = form['entries']
     169        if isinstance(entries, basestring):
     170            entries = [entries]
     171        deleted = []
     172        for entry in entries:
     173            if 'remove' in form:
     174                del self.context[entry]
     175                deleted.append(entry)
     176        self.hitlist = search(query=self.searchterm,
     177            searchtype=self.searchtype, view=self)
     178        if len(deleted):
     179            self.flash('Successfully removed: %s' % ', '.join(deleted))
    133180        return
     181
     182class StudentsContainerAddActionButton(AddActionButton):
     183    grok.order(1)
     184    grok.context(IStudentsContainer)
     185    grok.view(StudentsContainerManagePage)
     186    grok.require('waeup.manageStudents')
     187    text = 'Add student'
     188    target = 'addstudent'
    134189
    135190class StudentAddFormPage(WAeUPAddFormPage):
     
    155210            self.flash('The student id chosen already exists.')
    156211            return
     212        self.flash('Student record created.')
    157213        self.redirect(self.url(self.context[student_id], 'index'))
    158214        return
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/studentscontainerpage.pt

    r6622 r6626  
    11<h2 tal:content="view/label">Title</h2>
     2<form method="POST">
    23
    3 <form method="POST">
    4 <table class="zebra" tal:condition="layout/isAuthenticated">
    5   <tbody>
    6     <tal:block repeat="widget view/widgets">
    7       <tr>
    8         <td class="fieldname">
    9           <tal:block replace="python:widget.label"/>:
    10         </td>
    11         <td class="field">
    12           <tal:block tal:replace="structure widget" />
    13         </td>
    14       </tr>
    15     </tal:block>
    16       <tr>
    17         <td>
    18             <div class="actionButtons" tal:condition="view/availableActions">
    19                 <span tal:repeat="action view/actions" tal:omit-tag="">
    20                     <input tal:replace="structure action/render"/>
    21                 </span>
    22             </div>
    23         </td>
    24       </tr>
    25   </tbody>
    26 </table>
     4<br />
     5
     6  <input type="submit" name="search" value="Search" />
     7  for students
     8
     9  <select name="searchtype">
     10    <option value="student_id">with id</option>
     11    <option value="name">with name</option>
     12  </select>
     13
     14  <input type="text" name="searchterm" />
     15
     16  <p>&nbsp;</p>
     17  <div tal:condition="view/hitlist">
     18    <h3>Search Results</h3>
     19    <input type="hidden" name="old_searchterm"
     20         tal:attributes="value view/searchterm" />
     21    <input type="hidden" name="old_searchtype"
     22         tal:attributes="value view/searchtype" />
     23    <table class="display dataTableManage">
     24      <thead>
     25        <tr>
     26          <th>Student Id</th><th>Name</th>
     27        </tr>
     28      </thead>
     29      <tbody>
     30        <tr tal:repeat="item view/hitlist">
     31          <td tal:content="item/student_id">A123456</td>
     32          <td tal:content="item/name">Bob</td>
     33        </tr>
     34      </tbody>
     35    </table>
     36  </div>
    2737</form>
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r6622 r6626  
    7373        self.container_path = 'http://localhost/app/students'
    7474        self.manage_container_path = self.container_path + '/@@manage'
    75         self.add_student_path = self.container_path + '/@@add'
     75        self.add_student_path = self.container_path + '/addstudent'
    7676
    7777        # Populate university
     
    121121        return
    122122
    123     def test_add_students(self):
    124         # Managers can add students
     123    def test_add_search_delete_students(self):
     124        # Managers can add search and remove students
    125125        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    126         self.add_student_path = self.container_path + '/addstudent'
    127         self.container_manage_path = self.container_path + '/@@manage'
    128         self.browser.open(self.container_manage_path)
    129         self.browser.getControl("Add student").click()
     126        self.browser.open(self.manage_container_path)
     127        self.browser.getLink("Add student").click()
    130128        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    131129        self.assertEqual(self.browser.url, self.add_student_path)
     
    133131        self.browser.getControl(name="form.name").value = 'Bob Tester'
    134132        self.browser.getControl("Create student record").click()
     133        self.assertTrue('Student record created' in self.browser.contents)
     134
     135        self.browser.open(self.container_path)
     136        self.browser.getControl("Search").click()
     137        self.assertTrue('Empty search string' in self.browser.contents)
     138        self.browser.getControl(name="searchtype").value = ['student_id']
     139        self.browser.getControl(name="searchterm").value = 'A123456'
     140        self.browser.getControl("Search").click()
     141        self.assertTrue('Bob Tester' in self.browser.contents)
     142        # The old searchterm will be used again
     143        self.browser.getControl("Search").click()
     144        self.assertTrue('Bob Tester' in self.browser.contents)
     145
     146        self.browser.open(self.manage_container_path)
     147        self.browser.getControl("Search").click()
     148        self.assertTrue('Empty search string' in self.browser.contents)
     149        self.browser.getControl(name="searchtype").value = ['name']
     150        self.browser.getControl(name="searchterm").value = 'Bob Tester'
     151        self.browser.getControl("Search").click()
     152        self.assertTrue('A123456' in self.browser.contents)
     153        ctrl = self.browser.getControl(name='entries')
     154        ctrl.getControl(value='A123456').selected = True
     155        self.browser.getControl("Remove selected", index=0).click()
     156        self.assertTrue('Successfully removed' in self.browser.contents)
     157        self.browser.getControl(name="searchtype").value = ['student_id']
     158        self.browser.getControl(name="searchterm").value = 'A123456'
     159        self.browser.getControl("Search").click()
     160        self.assertTrue('No student found' in self.browser.contents)
     161
     162        self.browser.open(self.container_path)
     163        self.browser.getControl(name="searchtype").value = ['student_id']
     164        self.browser.getControl(name="searchterm").value = 'A123456'
     165        self.browser.getControl("Search").click()
     166        self.assertTrue('No student found' in self.browser.contents)
     167
Note: See TracChangeset for help on using the changeset viewer.