Ignore:
Timestamp:
24 Sep 2013, 12:39:44 (11 years ago)
Author:
Henrik Bettermann
Message:

Implement page to find students in faculties.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py

    r10541 r10646  
    2626from datetime import datetime, timedelta
    2727from urllib import urlencode
     28from hurry.query import Eq, Text
     29from hurry.query.query import Query
    2830from zope import schema
    2931from zope.i18n import translate
     
    7274
    7375from waeup.kofa.students.export import EXPORTER_NAMES as STUDENT_EXPORTERS
     76from waeup.kofa.students.catalog import StudentQueryResultItem
    7477
    7578FORBIDDEN_CHARACTERS = (160,)
     
    18501853        return del_local_roles(self,3,**data)
    18511854
     1855class FindStudentsPage(KofaPage):
     1856    """Search students in faculty.
     1857    """
     1858    grok.context(IFaculty)
     1859    grok.name('find_students')
     1860    grok.require('waeup.showStudents')
     1861    grok.template('findstudentspage')
     1862    label = _('Find students')
     1863    search_button = _('Find student')
     1864    pnav = 1
     1865
     1866    def _find_students(self,query=None, searchtype=None, view=None):
     1867        hitlist = []
     1868        if searchtype in ('fullname',):
     1869            results = Query().searchResults(
     1870                Text(('students_catalog', searchtype), query) &
     1871                Eq(('students_catalog', 'faccode'), self.context.code)
     1872                )
     1873        else:
     1874            results = Query().searchResults(
     1875                Eq(('students_catalog', searchtype), query) &
     1876                Eq(('students_catalog', 'faccode'), self.context.code)
     1877                )
     1878        for result in results:
     1879            hitlist.append(StudentQueryResultItem(result, view=view))
     1880        return hitlist
     1881
     1882    def update(self, *args, **kw):
     1883        datatable.need()
     1884        form = self.request.form
     1885        self.hitlist = []
     1886        if 'searchterm' in form and form['searchterm']:
     1887            self.searchterm = form['searchterm']
     1888            self.searchtype = form['searchtype']
     1889        elif 'old_searchterm' in form:
     1890            self.searchterm = form['old_searchterm']
     1891            self.searchtype = form['old_searchtype']
     1892        else:
     1893            if 'search' in form:
     1894                self.flash(_('Empty search string'))
     1895            return
     1896        self.hitlist = self._find_students(query=self.searchterm,
     1897            searchtype=self.searchtype, view=self)
     1898        if not self.hitlist:
     1899            self.flash(_('No student found.'))
     1900        return
     1901
    18521902class DepartmentAddFormPage(KofaAddFormPage):
    18531903    """Add a department to a faculty.
Note: See TracChangeset for help on using the changeset viewer.