Changeset 16392 for main/waeup.kofa/trunk/src
- Timestamp:
- 3 Feb 2021, 21:26:18 (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
r16391 r16392 5 5 from cStringIO import StringIO 6 6 from zope.app.testing.xmlrpc import ServerProxy 7 from zope.component import getUtility 7 from zope.component import getUtility, createObject 8 8 from waeup.kofa.interfaces import ( 9 9 IExtFileStore, IFileStoreNameChooser, IKofaUtils) … … 16 16 17 17 class XMLRPCTests(StudentsFullSetup): 18 # check XMLRPC services for university portal19 18 20 19 layer = FunctionalLayer … … 34 33 ticket.code = u'CRS1' 35 34 ticket.title = u'Course 1' 36 ticket.fcode = u' FAC1'37 ticket.dcode = u' DEP1'35 ticket.fcode = u'fac1' 36 ticket.dcode = u'dep1' 38 37 ticket.credits = 100 39 38 ticket.passmark = 100 … … 224 223 225 224 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']]) 225 self.course2 = createObject('waeup.Course') 226 self.course2.code = 'COURSE2' 227 self.app['faculties']['fac1']['dep1'].courses.addCourse( 228 self.course2) 229 self.setup_student(self.student) 230 ticket = CourseTicket() 231 ticket.code = u'COURSE2' 232 ticket.title = u'Course 2' 233 ticket.fcode = u'fac1' 234 ticket.dcode = u'fac1' 235 self.student['studycourse']['100'][ticket.code] = ticket 236 server = ServerProxy('http://mgr:mgrpw@localhost/app') 237 result = server.get_students_by_department('fac1','dep1', '2011') 238 self.assertEqual(result, {}) 239 result = server.get_students_by_department('fac1','dep1', '2012', '200') 240 self.assertEqual(result, {}) 241 result = server.get_students_by_department('fac1','dep1', '2012', '100') 242 self.assertEqual( 243 result, {'K1000000': ['234', 'Anna Tester', ['COURSE1', 'COURSE2']]}) 230 244 result = server.get_students_by_department('fac1','dep1') 231 self.assertEqual(result, [['COURSE1', 100, 2012, 'K1000000', '234', 'Anna Tester']]) 245 self.assertEqual( 246 result, {'K1000000': ['234', 'Anna Tester', ['COURSE1', 'COURSE2']]}) 232 247 result = server.get_students_by_department('fac1','dep2') 233 248 self.assertEqual(result, None) … … 248 263 <params> 249 264 <param> 265 <value><struct> 266 <member> 267 <name>K1000000</name> 250 268 <value><array><data> 269 <value><string>234</string></value> 270 <value><string>Anna Tester</string></value> 251 271 <value><array><data> 252 272 <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> 273 <value><string>COURSE2</string></value> 258 274 </data></array></value> 259 275 </data></array></value> 276 </member> 277 </struct></value> 260 278 </param> 261 279 </params> -
main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py
r16391 r16392 155 155 156 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. 157 def get_students_by_department(self, faccode=None, depcode=None, 158 session=None, level=None): 159 """A webservice to pull student's registered courses in a 160 department 159 161 """ 160 162 try: 161 163 session = int(session) 164 level = int(level) 162 165 except (TypeError, ValueError): 163 166 pass 164 sessionsearch = True165 167 if session in (None, ''): 166 sessionsearch = False 168 session= None 169 if level in (None, ''): 170 level= None 167 171 try: 168 172 department =self.context['faculties'][faccode][depcode] … … 171 175 courses = department.courses.keys() 172 176 cat = queryUtility(ICatalog, name='coursetickets_catalog') 173 hit list = []177 hitdict = {} 174 178 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)) 179 coursetickets = cat.searchResults( 180 session=(session, session), 181 level=(level, level), 182 code=(course, course)) 182 183 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 ))191 return list(set(hitlist))184 if not c_ticket.student.student_id in hitdict.keys(): 185 hitdict[c_ticket.student.student_id] = ( 186 c_ticket.student.matric_number, 187 c_ticket.student.display_fullname, 188 [c_ticket.code,]) 189 else: 190 hitdict[c_ticket.student.student_id][2].append( 191 c_ticket.code,) 192 return hitdict 192 193 193 194 @grok.require('waeup.xmlrpc')
Note: See TracChangeset for help on using the changeset viewer.