Changeset 16391
- Timestamp:
- 1 Feb 2021, 13:02:45 (4 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py
r16268 r16391 213 213 <value><string>my adviser</string></value> 214 214 <value><double>12.12</double></value> 215 </data></array></value> 216 </data></array></value> 217 </param> 218 </params> 219 </methodResponse> 220 """ 221 xmlout = self.XMLRPC_post(REQUEST_XML) 222 self.assertEqual(xmlout, RESPONSE_XML) 223 return 224 225 def test_get_students_by_department(self): 226 self.setup_student(self.student) 227 server = ServerProxy('http://mgr:mgrpw@localhost/app') 228 result = server.get_students_by_department('fac1','dep1', '2012') 229 self.assertEqual(result, [['COURSE1', 100, 2012, 'K1000000', '234', 'Anna Tester']]) 230 result = server.get_students_by_department('fac1','dep1') 231 self.assertEqual(result, [['COURSE1', 100, 2012, 'K1000000', '234', 'Anna Tester']]) 232 result = server.get_students_by_department('fac1','dep2') 233 self.assertEqual(result, None) 234 REQUEST_XML = """\ 235 <?xml version="1.0"?> 236 <methodCall> 237 <methodName>get_students_by_department</methodName> 238 <params> 239 <param> 240 <value><string>fac1</string></value> 241 <value><string>dep1</string></value> 242 </param> 243 </params> 244 </methodCall>""" 245 RESPONSE_XML = """\ 246 <?xml version='1.0'?> 247 <methodResponse> 248 <params> 249 <param> 250 <value><array><data> 251 <value><array><data> 252 <value><string>COURSE1</string></value> 253 <value><int>100</int></value> 254 <value><int>2012</int></value> 255 <value><string>K1000000</string></value> 256 <value><string>234</string></value> 257 <value><string>Anna Tester</string></value> 215 258 </data></array></value> 216 259 </data></array></value> -
main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py
r16269 r16391 152 152 amount 153 153 )) 154 return list(set(hitlist)) 155 156 @grok.require('waeup.xmlrpc') 157 def get_students_by_department(self, faccode=None, depcode=None, session=None): 158 """A webservice to pull student's registered courses in a department. 159 """ 160 try: 161 session = int(session) 162 except (TypeError, ValueError): 163 pass 164 sessionsearch = True 165 if session in (None, ''): 166 sessionsearch = False 167 try: 168 department =self.context['faculties'][faccode][depcode] 169 except KeyError: 170 return None 171 courses = department.courses.keys() 172 cat = queryUtility(ICatalog, name='coursetickets_catalog') 173 hitlist = [] 174 for course in courses: 175 if sessionsearch: 176 coursetickets = cat.searchResults( 177 session=(session, session), 178 code=(course, course)) 179 else: 180 coursetickets = cat.searchResults( 181 code=(course, course)) 182 for c_ticket in coursetickets: 183 hitlist.append(( 184 c_ticket.code, 185 c_ticket.level, 186 c_ticket.level_session, 187 c_ticket.student.student_id, 188 c_ticket.student.matric_number, 189 c_ticket.student.display_fullname, 190 )) 154 191 return list(set(hitlist)) 155 192
Note: See TracChangeset for help on using the changeset viewer.