Changeset 10646
- Timestamp:
- 24 Sep 2013, 12:39:44 (11 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r10541 r10646 26 26 from datetime import datetime, timedelta 27 27 from urllib import urlencode 28 from hurry.query import Eq, Text 29 from hurry.query.query import Query 28 30 from zope import schema 29 31 from zope.i18n import translate … … 72 74 73 75 from waeup.kofa.students.export import EXPORTER_NAMES as STUDENT_EXPORTERS 76 from waeup.kofa.students.catalog import StudentQueryResultItem 74 77 75 78 FORBIDDEN_CHARACTERS = (160,) … … 1850 1853 return del_local_roles(self,3,**data) 1851 1854 1855 class 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 1852 1902 class DepartmentAddFormPage(KofaAddFormPage): 1853 1903 """Add a department to a faculty. -
main/waeup.kofa/trunk/src/waeup/kofa/browser/viewlets.py
r10633 r10646 446 446 text = _('Manage faculty') 447 447 448 class StudentSearchActionButton(ManageActionButton): 449 grok.order(2) 450 grok.context(IFaculty) 451 grok.view(FacultyPage) 452 grok.require('waeup.showStudents') 453 text = _('Find students') 454 icon = 'actionicon_search.png' 455 target = 'find_students' 456 448 457 class ManageDepartmentActionButton(ManageActionButton): 449 458 """ 'Manage settings' button for departments. -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r10637 r10646 1763 1763 self.assertTrue('Employer' in self.browser.contents) 1764 1764 1765 def test_find_students_in_faculties(self): 1766 # Create local students manager in faculty 1767 self.app['users'].addUser('mrmanager', 'mrmanagersecret') 1768 self.app['users']['mrmanager'].email = 'mrmanager@foo.ng' 1769 self.app['users']['mrmanager'].title = u'Volk Wagen' 1770 # Assign LocalStudentsManager role for faculty 1771 fac = self.app['faculties']['fac1'] 1772 prmlocal = IPrincipalRoleManager(fac) 1773 prmlocal.assignRoleToPrincipal( 1774 'waeup.local.LocalStudentsManager', 'mrmanager') 1775 notify(LocalRoleSetEvent( 1776 fac, 'waeup.local.LocalStudentsManager', 'mrmanager', 1777 granted=True)) 1778 # Login as manager 1779 self.browser.open(self.login_path) 1780 self.browser.getControl(name="form.login").value = 'mrmanager' 1781 self.browser.getControl(name="form.password").value = 'mrmanagersecret' 1782 self.browser.getControl("Login").click() 1783 self.assertMatches('...You logged in...', self.browser.contents) 1784 # Manager can see his roles 1785 self.browser.getLink("My Roles").click() 1786 self.assertMatches( 1787 '...<span>Students Manager</span>...', 1788 self.browser.contents) 1789 # The manager can go to his faculty 1790 self.browser.getLink( 1791 "http://localhost/app/faculties/fac1").click() 1792 # and find students 1793 self.browser.getLink("Find students").click() 1794 self.browser.getControl("Find student").click() 1795 self.assertTrue('Empty search string' in self.browser.contents) 1796 self.browser.getControl(name="searchtype").value = ['student_id'] 1797 self.browser.getControl(name="searchterm").value = self.student_id 1798 self.browser.getControl("Find student").click() 1799 self.assertTrue('Anna Tester' in self.browser.contents) 1800 1765 1801 def test_activate_deactivate_buttons(self): 1766 1802 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
Note: See TracChangeset for help on using the changeset viewer.