- Timestamp:
- 13 Jun 2016, 01:19:01 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-scores-upload/src/waeup/kofa/students/browser.py
r13923 r13926 18 18 """UI components for students and related components. 19 19 """ 20 import csv 20 21 import sys 21 22 import grok 22 23 import pytz 24 from cStringIO import StringIO 23 25 from urllib import urlencode 24 26 from datetime import datetime … … 3104 3106 return list(coursetickets) 3105 3107 3108 def _extract_uploadfile(self, uploadfile): 3109 """Get a mapping of student-ids to scores. 3110 3111 The mapping is constructed by reading contents from `uploadfile`. 3112 """ 3113 data = StringIO(uploadfile.read()) # ensure we have something seekable 3114 reader = csv.DictReader(data) 3115 result = dict() 3116 for row in reader: 3117 if not 'student_id' in row or not 'score' in row: 3118 continue 3119 result[row['student_id']] = row['score'] 3120 return result 3121 3106 3122 def update(self, *args, **kw): 3107 3123 form = self.request.form … … 3129 3145 return 3130 3146 formvals = dict(zip(form['sids'], form['scores'])) 3147 if form['uploadfile']: 3148 formvals = self._extract_uploadfile(form['uploadfile']) 3131 3149 for ticket in editable_tickets: 3132 3150 score = ticket.score 3133 3151 sid = ticket.student.student_id 3152 if sid not in formvals: 3153 continue 3134 3154 if formvals[sid] == '': 3135 3155 score = None
Note: See TracChangeset for help on using the changeset viewer.