def teacherhandout(self, request, tl, one, two, module, extra, prog, template_file='teacherschedules.html'): # Use the template defined in ProgramPrintables from esp.program.modules.handlers import ProgramPrintables context = {'module': self} pmos = ProgramModuleObj.objects.filter( program=prog, module__handler__icontains='printables') if pmos.count() == 1: pmo = ProgramPrintables(pmos[0]) teacher = ESPUser(request.user) scheditems = [] for cls in teacher.getTaughtClasses().filter( parent_program=self.program): if cls.isAccepted(): for section in cls.sections.all(): scheditems.append({ 'name': teacher.name(), 'teacher': teacher, 'cls': section }) scheditems.sort() context['scheditems'] = scheditems return render_to_response(pmo.baseDir() + template_file, request, context) else: raise ESPError( False ), 'No printables module resolved, so this document cannot be generated. Consult the webmasters.'
def survey_review_single(request, tl, program, instance): """ View a single survey response. """ try: prog = Program.by_prog_inst(program, instance) except Program.DoesNotExist: #raise Http404 raise ESPError(), "Can't find the program %s/%s" % (program, instance) user = ESPUser(request.user) survey_response = None ints = request.REQUEST.items() if len(ints) == 1: srs = SurveyResponse.objects.filter(id=ints[0][0]) if len(srs) == 1: survey_response = srs[0] if survey_response is None: raise ESPError( False ), 'Ideally this page should give you some way to pick an individual response. For now I guess you should go back to <a href="review">reviewing the whole survey</a>.' if tl == 'manage' and user.isAdmin(prog): answers = survey_response.answers.order_by('content_type', 'object_id', 'question') classes_only = False other_responses = None elif tl == 'teach': subject_ct = ContentType.objects.get(app_label="program", model="classsubject") section_ct = ContentType.objects.get(app_label="program", model="classsection") class_ids = [x["id"] for x in user.getTaughtClasses().values('id')] section_ids = [x["id"] for x in user.getTaughtSections().values('id')] answers = survey_response.answers.filter( content_type__in=[subject_ct, section_ct], object_id__in=(class_ids + section_ids)).order_by( 'content_type', 'object_id', 'question') classes_only = True other_responses = SurveyResponse.objects.filter( answers__content_type=subject_ct, answers__object_id__in=class_ids).order_by('id').distinct() else: raise ESPError( False ), 'You need to be a teacher or administrator of this program to review survey responses.' context = { 'user': user, 'program': prog, 'response': survey_response, 'answers': answers, 'classes_only': classes_only, 'other_responses': other_responses } return render_to_response('survey/review_single.html', request, context)
def survey_review_single(request, tl, program, instance): """ View a single survey response. """ try: prog = Program.by_prog_inst(program, instance) except Program.DoesNotExist: #raise Http404 raise ESPError(), "Can't find the program %s/%s" % (program, instance) user = ESPUser(request.user) survey_response = None ints = request.REQUEST.items() if len(ints) == 1: srs = SurveyResponse.objects.filter(id=ints[0][0]) if len(srs) == 1: survey_response = srs[0] if survey_response is None: raise ESPError( False ), 'Ideally this page should give you some way to pick an individual response. For now I guess you should go back to <a href="review">reviewing the whole survey</a>.' if tl == 'manage' and user.isAdmin(prog.anchor): answers = survey_response.answers.order_by('anchor', 'question') classes_only = False elif tl == 'teach': class_anchors = [ x['anchor'] for x in user.getTaughtClasses().values('anchor') ] answers = survey_response.answers.filter( anchor__in=class_anchors).order_by('anchor', 'question') classes_only = True else: raise ESPError( False ), 'You need to be a teacher or administrator of this program to review survey responses.' context = { 'user': user, 'program': prog, 'response': survey_response, 'answers': answers, 'classes_only': classes_only } return render_to_response('survey/review_single.html', request, prog.anchor, 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)