Changeset 6626
- Timestamp:
- 25 Aug 2011, 12:01:37 (13 years ago)
- 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 45 45 from waeup.sirp.browser.resources import datepicker, tabs, datatable 46 46 from waeup.sirp.browser.viewlets import ( 47 ManageActionButton, PrimaryNavTab, LeftSidebarLink 47 ManageActionButton, PrimaryNavTab, LeftSidebarLink, AddActionButton, 48 48 ) 49 49 from waeup.sirp.image.browser.widget import ( … … 67 67 Student, 68 68 ) 69 from waeup.sirp.students.catalog import search 69 70 70 71 class StudentsTab(PrimaryNavTab): … … 84 85 return self.view.application_url('students') 85 86 86 class StudentsContainerPage(WAeUP DisplayFormPage):87 """The standard view for regularstudent containers.87 class StudentsContainerPage(WAeUPPage): 88 """The standard view for student containers. 88 89 """ 89 90 grok.context(IStudentsContainer) … … 92 93 grok.template('studentscontainerpage') 93 94 94 form_fields = grok.AutoFields(IStudentsContainer)95 #form_fields['description'].custom_widget = ReSTDisplayWidget96 97 95 @property 98 96 def title(self): … … 103 101 return self.title 104 102 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 123 class StudentsContainerManageActionButton(ManageActionButton): 106 124 grok.order(1) 107 125 grok.context(IStudentsContainer) … … 110 128 text = 'Manage students' 111 129 112 class StudentsContainerManagePage(WAeUPDisplayFormPage): 113 """The standard view for regular student containers. 130 131 class StudentsContainerManagePage(WAeUPPage): 132 """The manage page for student containers. 114 133 """ 115 134 grok.context(IStudentsContainer) 116 135 grok.name('manage') 117 136 grok.require('waeup.manageStudents') 118 grok.template('studentscontainerpage') 119 120 form_fields = grok.AutoFields(IStudentsContainer) 137 grok.template('studentscontainermanagepage') 121 138 122 139 @property … … 128 145 return self.title 129 146 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)) 133 180 return 181 182 class 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' 134 189 135 190 class StudentAddFormPage(WAeUPAddFormPage): … … 155 210 self.flash('The student id chosen already exists.') 156 211 return 212 self.flash('Student record created.') 157 213 self.redirect(self.url(self.context[student_id], 'index')) 158 214 return -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser_templates/studentscontainerpage.pt
r6622 r6626 1 1 <h2 tal:content="view/label">Title</h2> 2 <form method="POST"> 2 3 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> </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> 27 37 </form> -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r6622 r6626 73 73 self.container_path = 'http://localhost/app/students' 74 74 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' 76 76 77 77 # Populate university … … 121 121 return 122 122 123 def test_add_s tudents(self):124 # Managers can add s tudents123 def test_add_search_delete_students(self): 124 # Managers can add search and remove students 125 125 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() 130 128 self.assertEqual(self.browser.headers['Status'], '200 Ok') 131 129 self.assertEqual(self.browser.url, self.add_student_path) … … 133 131 self.browser.getControl(name="form.name").value = 'Bob Tester' 134 132 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.