示例#1
0
    def generatestickers(self, request, tl, one, two, module, extra, prog):
        timeslots = prog.getTimeSlots()
        students = prog.students()['confirmed']
        context = {'timeslots': timeslots, 'students': students}
        if request.GET.has_key("format"):
            format = request.GET["format"]
        else:
            format = "pdf"

        zipped_list = []

        students = list(students)

        while students != []:
            zipped_list.append(students[:3])
            students = students[3:]

        context['zipped_list'] = zipped_list

        return render_to_latex(self.baseDir() + 'stickers.tex', context,
                               format)
示例#2
0
def display_survey(user, prog, surveys, request, tl, format):
    """ Wrapper doing the necessary work for the survey output. """
    from esp.program.models import ClassSubject, ClassSection

    perclass_data = []

    def getByIdOrNone(model, key):
        q = model.objects.filter(id=request.REQUEST.get(key, None))[:1]
        if q:
            return q[0]
        return None

    sec = getByIdOrNone(ClassSection, 'classsection_id')
    cls = getByIdOrNone(ClassSubject, 'classsubject_id')

    if tl == 'manage' and not request.REQUEST.has_key(
            'teacher_id') and sec is None and cls is None:
        #   In the manage category, pack the data in as extra attributes to the surveys
        surveys = list(surveys)
        for s in surveys:
            questions = s.questions.filter(per_class=False).order_by('seq')
            s.display_data = {
                'questions': [{
                    'question': y,
                    'answers': y.answer_set.all()
                } for y in questions]
            }
            questions2 = s.questions.filter(
                per_class=True, question_type__is_numeric=True).order_by('seq')
            s.display_data['questions'].extend([{
                'question':
                y,
                'answers':
                Answer.objects.filter(question=y)
            } for y in questions2])
    else:
        perclass_questions = surveys[0].questions.filter(
            per_class=True).order_by('seq')
        surveys = []
        classes = []
        if sec is not None:
            classes = [sec]
        elif cls is not None:
            classes = cls.get_sections()
        elif tl == 'teach' or tl == 'manage':
            #   In the teach category, show only class-specific questions
            classes = user.getTaughtSections(prog).order_by(
                'parent_class', 'id')
        subject_ct = ContentType.objects.get(app_label="program",
                                             model="classsubject")
        section_ct = ContentType.objects.get(app_label="program",
                                             model="classsection")
        perclass_data = [{
            'class':
            x,
            'questions': [{
                'question':
                y,
                'answers':
                y.answer_set.filter(
                    Q(content_type=section_ct, object_id=x.id)
                    | Q(content_type=subject_ct, object_id=x.parent_class.id))
            } for y in perclass_questions]
        } for x in classes]

    context = {
        'user': user,
        'surveys': surveys,
        'program': prog,
        'perclass_data': perclass_data
    }

    #   Choose+use appropriate output format
    if format == 'html':
        return render_to_response('survey/review.html', request, context)
    elif format == 'tex':
        return render_to_latex('survey/review.tex', context, 'pdf')