1246
1255
averages.append(average)
1247
1256
return self.div(sum(averages), count)
1259
class IStudentReport(Interface):
1262
title=STMessage('Level'),
1263
vocabulary='schooltool.level.level.levelvocabulary')
1267
source='schooltool.peas.groups')
1270
title=_('Term / Exam'),
1271
source='schooltool.peas.term_exams')
1274
class StudentReportRequestView(RequestXLSReportDialog):
1276
report_builder = 'student_report.xls'
1278
fields = field.Fields(IStudentReport)
1280
def resetForm(self):
1281
RequestXLSReportDialog.resetForm(self)
1282
self.form_params['schoolyear'] = self.context
1284
def updateTaskParams(self, task):
1285
level = self.form_params.get('level')
1286
group= self.form_params.get('group')
1287
term = self.form_params.get('term')
1288
task.request_params['level'] = level.__name__
1289
if group is not u'':
1290
task.request_params['group'] = group.__name__
1291
preferences = IAssessmentPreferences(self.context)
1292
if term == MOCK_SHEET_ID:
1293
term = preferences.mock_term
1294
sheet = MOCK_SHEET_ID
1295
elif term == MOCK_OTHER_SHEET_ID:
1296
term = preferences.mock_other_term
1297
sheet = MOCK_OTHER_SHEET_ID
1298
elif term == UCE_SHEET_ID:
1299
term = default_deploy_term(self.context)
1300
sheet = UCE_SHEET_ID
1303
task.request_params['term'] = term.__name__
1304
task.request_params['sheet'] = sheet
1306
def updateWidgets(self):
1307
super(StudentReportRequestView, self).updateWidgets()
1308
self.widgets['level'].prompt = True
1309
self.widgets['term'].prompt = True
1312
class GroupsVocabulary(SimpleVocabulary):
1314
implements(IContextSourceBinder)
1316
def __init__(self, context):
1317
self.context = context
1318
terms = self.createTerms()
1319
SimpleVocabulary.__init__(self, terms)
1321
def createTerms(self):
1323
result.append(self.createTerm(
1328
schoolyear = self.context['schoolyear']
1329
groups = IGroupContainer(schoolyear)
1330
for group_id, group in sorted(groups.items(),
1331
key=lambda i: i[1].title):
1332
if group_id in defaultGroups:
1334
result.append(self.createTerm(group, group_id, group.title))
1338
def GroupsVocabularyFactory():
1339
return GroupsVocabulary
1342
class TermExamsVocabulary(SimpleVocabulary):
1344
implements(IContextSourceBinder)
1346
def __init__(self, context):
1347
self.context = context
1348
terms = self.createTerms()
1349
SimpleVocabulary.__init__(self, terms)
1351
def createTerms(self):
1353
schoolyear = self.context['schoolyear']
1354
for term in sorted(schoolyear.values(),
1355
key=lambda t: t.first):
1356
result.append(self.createTerm(term, term.__name__, term.title))
1357
mocks = [MOCK_SHEET_ID, MOCK_OTHER_SHEET_ID]
1358
preferences = IAssessmentPreferences(schoolyear)
1359
for sheet in mocks + [UCE_SHEET_ID]:
1361
# XXX: needed because of a typo in MOCK_OTHER_SHEET_ID
1362
preference = sheet.replace('-', '_')
1363
if not getattr(preferences, preference):
1365
title = ASSESSMENT_SHEETS[sheet]['title']
1366
result.append(self.createTerm(sheet, sheet, title))
1370
def TermExamsVocabularyFactory():
1371
return TermExamsVocabulary
1374
class StudentReportView(OverallReportBase):
1376
message_title = _('Student report')
1378
sheet_1_title = _('Assessment - Student attainment for all subjects '
1379
'and comparison to target ')
1380
sheet_1_label = _('Student report')
1383
def base_filename(self):
1384
return 'student_report_%s' % self.schoolyear.title
1386
def print_report_filters(self, ws, row):
1387
ws.write(row, 0, STMessage('Level'), xlwt.easyxf(
1388
'font: bold on, color black; '
1389
'pattern: pattern solid, fore_color white; '
1390
'borders: top no_line, right no_line, bottom no_line, left medium; '
1392
ws.write(row, 1, self.level.title, xlwt.easyxf(
1393
'font: bold on, color black; '
1394
'pattern: pattern solid, fore_color white; '
1395
'borders: top no_line, right medium, bottom no_line, left no_line; '
1398
ws.write(row, 0, _('Stream'), xlwt.easyxf(
1399
'font: bold on, color black; '
1400
'pattern: pattern solid, fore_color white; '
1401
'borders: top no_line, right no_line, bottom no_line, left medium; '
1403
ws.write(row, 1, self.group.title if self.group else 'All', xlwt.easyxf(
1404
'font: bold on, color black; '
1405
'pattern: pattern solid, fore_color white; '
1406
'borders: top no_line, right medium, bottom no_line, left no_line; '
1409
ws.write(row, 0, _('Term / Exam'), xlwt.easyxf(
1410
'font: bold on, color black; '
1411
'pattern: pattern solid, fore_color white; '
1412
'borders: top no_line, right no_line, bottom no_line, left medium; '
1415
title = self.term.title
1417
title = ASSESSMENT_SHEETS[self.sheet]['title']
1418
ws.write(row, 1, title, xlwt.easyxf(
1419
'font: bold on, color black; '
1420
'pattern: pattern solid, fore_color white; '
1421
'borders: top no_line, right medium, bottom no_line, left no_line; '
1424
ws.write(row, 0, _('Year selected'), xlwt.easyxf(
1425
'font: bold on, color black; '
1426
'pattern: pattern solid, fore_color white; '
1427
'borders: top no_line, right no_line, bottom medium, left medium; '
1429
ws.write(row, 1, self.schoolyear.title, xlwt.easyxf(
1430
'font: bold on, color black; '
1431
'pattern: pattern solid, fore_color white; '
1432
'borders: top no_line, right medium, bottom medium, left no_line; '
1437
app = ISchoolToolApplication(None)
1438
container = ILevelContainer(app)
1439
return container.get(self.request.get('level'))
1443
groups = IGroupContainer(self.schoolyear)
1444
return groups.get(self.request.get('group'))
1447
def schoolyear(self):
1452
for term in self.schoolyear.values():
1453
if term.__name__ == self.request.get('term'):
1458
return self.request.get('sheet') or None
1465
def export_report(self, wb):
1466
self.task_progress.force('sheet1', active=True)
1467
ws = wb.add_sheet(self.sheet_1_label)
1468
self.print_headers(ws, self.sheet_1_title)
1469
self.finish('sheet1')