def uploadSales(request,eventId): """ THIS FUNCTION IS DEPRECATED Format: [0] barcode ID [1] admitted (TRUE / FALSE) [2] special codes (int) """ event = get_object_or_404(Event,pk=eventId) form = ImportAdmitInfoForm() if request.method == 'POST': form = ImportAdmitInfoForm(request.POST,request.FILES) if not form.is_valid(): return render_to_response('scanner/manage/upload.html',{'form': form,'event': event}, context_instance=RequestContext(request)) csv_processor = StandardStudentCSVProcessor() student_dict = StandardStudentCSVProcessor.collectAsDict(csv_processor.studentRecords()) try: admit_csv = request.FILES['admits'] lines = [] errors = [] for chunk in admit_csv.chunks(): lines += chunk.splitlines() reader = csv.reader(lines) for line in reader: if line[0] not in student_dict: errors.append("Barcode ID %s not in the student list. Student was not added." % line[0]) continue attendance = EventAttendancePerson.objects.get_or_create(sunetid=student_dict[line[0]].sunetid,event=event) print "added attendee" return render_to_response('scanner/manage/upload_done.html',{'errors': errors, 'event': event}, context_instance=RequestContext(request)) except Exception as e: return render_to_response('scanner/manage/upload_done.html',{'errors': [e], 'event': event}, context_instance=RequestContext(request))
def exportFile(request,eventId): event = get_object_or_404(Event,pk=eventId) #try: csv_processor = StandardStudentCSVProcessor() attendance = AttendanceProcessor(event) admit_list = [attendance.processStudent(student) for student in csv_processor.studentRecords()] exporter = ScannerDATFile(event,csv_processor.data_date) exporter.writeStudents(admit_list) #except Exception as e: # return render_to_response('scanner/manage/exportError.html',{'event': event, 'error': e}, context_instance=RequestContext(request)) filename = exporter.getFilename() #response = HttpResponse() response = HttpResponse(mimetype='application/octet-stream') response['Content-Disposition'] = 'attachment; filename=%s' % filename response.write(exporter.getExport()) return response
def testStudents(request,eventId): """ Enormous hack, it's 1 AM :( """ event = get_object_or_404(Event,pk=eventId) errors = {} record_errors = [] invited_students = set([student.sunetid for student in event.eventattendanceperson_set.all()]) # from SUNetID to student record csv_processor = StandardStudentCSVProcessor() invited_records = [] for student in csv_processor.studentRecords(): if student.sunetid in invited_students: invited_records.append(student) invited_students.remove(student.sunetid) # Any students who didn't have records are a problem for sunetid in invited_students: record_errors.append(sunetid) # Check allowed access attendance = AttendanceProcessor(event) for record in invited_records: if not attendance.studentIsPermittedByRules(record): # if not permitted, and no record was permitted, deny errors[record.barcode_id] = (record,False) elif attendance.studentIsPermittedByRules(record): # if permitted, add the permitted record errors[record.barcode_id] = (record,True) else: pass return render_to_response('scanner/manage/check_list.html',{'errors': errors.values(), 'record_errors': record_errors, 'event': event}, context_instance=RequestContext(request))