def barcodecheckin(self, request, tl, one, two, module, extra, prog): context = {} if request.method == 'POST': results = {'not_found': [], 'existing': [], 'new': [], 'not_student': []} form = OnsiteBarcodeCheckinForm(request.POST) if form.is_valid(): codes=form.cleaned_data['uids'].split() for code in codes: try: result=ESPUser.objects.filter(id=code) except ValueError: results['not_found'].append(code) if len(result) > 1: raise ESPError(False), "Something weird happened, there are two students with ID %s." % code elif len(result) == 0: results['not_found'].append(code) else: student=result[0] if student.isStudent(): existing = Record.user_completed(student, 'attended', prog) if existing: results['existing'].append(code) else: new = Record(user=student, program=prog, event='attended') new.save() results['new'].append(code) else: results['not_student'].append(code) else: results = {} form=OnsiteBarcodeCheckinForm() context['module'] = self context['form'] = form context['results'] = results return render_to_response(self.baseDir()+'barcodecheckin.html', request, context)
def barcodecheckin(self, request, tl, one, two, module, extra, prog): context = {} if request.method == 'POST': results = { 'not_found': [], 'existing': [], 'new': [], 'not_student': [] } form = OnsiteBarcodeCheckinForm(request.POST) if form.is_valid(): codes = form.cleaned_data['uids'].split() for code in codes: try: student = ESPUser.objects.get(id=code) except (ValueError, ESPUser.DoesNotExist): results['not_found'].append(code) continue if student.isStudent(): existing = Record.user_completed( student, 'attended', prog) if existing: results['existing'].append(code) else: new = Record(user=student, program=prog, event='attended') new.save() results['new'].append(code) else: results['not_student'].append(code) else: results = {} form = OnsiteBarcodeCheckinForm() context['module'] = self context['form'] = form context['results'] = results return render_to_response(self.baseDir() + 'barcodecheckin.html', request, context)
def survey_view(request, tl, program, instance): try: prog = Program.by_prog_inst(program, instance) except Program.DoesNotExist: raise Http404 user = ESPUser(request.user) if (tl == 'teach' and not user.isTeacher()) or (tl == 'learn' and not user.isStudent()): raise ESPError( False ), 'You need to be a program participant (i.e. student or teacher, not parent or educator) to participate in this survey. Please contact the directors directly if you have additional feedback.' if request.GET.has_key('done'): return render_to_response('survey/completed_survey.html', request, {'prog': prog}) if tl == 'learn': event = "student_survey" else: event = "teacher_survey" if Record.user_completed(user, event, prog): raise ESPError( False ), "You've already filled out the survey. Thanks for responding!" surveys = prog.getSurveys().filter(category=tl).select_related() if request.REQUEST.has_key('survey_id'): try: s_id = int(request.REQUEST['survey_id']) surveys = surveys.filter( id=s_id ) # We want to filter, not get: ID could point to a survey that doesn't exist for this program, or at all except ValueError: pass if len(surveys) < 1: raise ESPError(False), "Sorry, no such survey exists for this program!" if len(surveys) > 1: return render_to_response( 'survey/choose_survey.html', request, { 'surveys': surveys, 'error': request.POST } ) # if request.POST, then we shouldn't have more than one survey any more... survey = surveys[0] if request.POST: response = SurveyResponse() response.survey = survey response.save() r = Record(user=user, event=event, program=prog, time=datetime.datetime.now()) r.save() response.set_answers(request.POST, save=True) return HttpResponseRedirect(request.path + "?done") else: questions = survey.questions.filter(per_class=False).order_by('seq') perclass_questions = survey.questions.filter(per_class=True) classes = sections = timeslots = [] if tl == 'learn': classes = user.getEnrolledClasses(prog, request) timeslots = prog.getTimeSlots().order_by('start') for ts in timeslots: # The order by string really means "title" ts.classsections = prog.sections().filter( meeting_times=ts).exclude( meeting_times__start__lt=ts.start).order_by( 'parent_class__title').distinct() for sec in ts.classsections: if user in sec.students(): sec.selected = True elif tl == 'teach': classes = user.getTaughtClasses(prog) sections = user.getTaughtSections(prog).order_by( 'parent_class__title') context = { 'survey': survey, 'questions': questions, 'perclass_questions': perclass_questions, 'program': prog, 'classes': classes, 'sections': sections, 'timeslots': timeslots, } return render_to_response('survey/survey.html', request, context)
def survey_view(request, tl, program, instance): try: prog = Program.by_prog_inst(program, instance) except Program.DoesNotExist: raise Http404 user = request.user if (tl == 'teach' and not user.isTeacher()) or (tl == 'learn' and not user.isStudent()): raise ESPError('You need to be a program participant (i.e. student or teacher, not parent or educator) to participate in this survey. Please contact the directors directly if you have additional feedback.', log=False) if 'done' in request.GET: return render_to_response('survey/completed_survey.html', request, {'prog': prog}) if tl == 'learn': event = "student_survey" else: event = "teacher_survey" if Record.user_completed(user, event ,prog): raise ESPError("You've already filled out the survey. Thanks for responding!", log=False) surveys = prog.getSurveys().filter(category = tl).select_related() if 'survey_id' in request.GET: try: s_id = int( request.GET['survey_id'] ) surveys = surveys.filter(id=s_id) # We want to filter, not get: ID could point to a survey that doesn't exist for this program, or at all except ValueError: pass if len(surveys) < 1: raise ESPError("Sorry, no such survey exists for this program!", log=False) if len(surveys) > 1: return render_to_response('survey/choose_survey.html', request, { 'surveys': surveys, 'error': request.POST }) # if request.POST, then we shouldn't have more than one survey any more... survey = surveys[0] if request.POST: response = SurveyResponse() response.survey = survey response.save() r = Record(user=user, event=event, program=prog, time=datetime.datetime.now()) r.save() response.set_answers(request.POST, save=True) return HttpResponseRedirect(request.path + "?done") else: questions = survey.questions.filter(per_class = False).order_by('seq') perclass_questions = survey.questions.filter(per_class = True) classes = sections = timeslots = [] if tl == 'learn': classes = user.getEnrolledClasses(prog) enrolled_secs = user.getEnrolledSections(prog) timeslots = prog.getTimeSlots().order_by('start') for ts in timeslots: # The order by string really means "title" ts.classsections = prog.sections().filter(meeting_times=ts).exclude(meeting_times__start__lt=ts.start).order_by('parent_class__title').distinct() for sec in ts.classsections: if sec in enrolled_secs: sec.selected = True elif tl == 'teach': classes = user.getTaughtClasses(prog) sections = user.getTaughtSections(prog).order_by('parent_class__title') context = { 'survey': survey, 'questions': questions, 'perclass_questions': perclass_questions, 'program': prog, 'classes': classes, 'sections': sections, 'timeslots': timeslots, } return render_to_response('survey/survey.html', request, context)