Пример #1
0
def submitted(request):

    school_summary_blurb = 'Thank you for using the UCT Mathematics Competition online Registration Portal. You have successfully registered:'
    
    try: #Try get the student list for the school assigned to the requesting user
        school_asmt = School.objects.get(assigned_to=request.user)
        student_list = SchoolStudent.objects.all().filter(school=school_asmt)
    except exceptions.ObjectDoesNotExist:
        return HttpResponseRedirect('../school_select/school_select.html')
    except Exception:
        school_summary_blurb = 'An error has occured.' #This could occur if a user has become associated with > 1 school.
    
    grade_summary = compadmin.gradeBucket(student_list) #Bin into categories (Pairing, grade)
    school_summary_info = [] #Entry for each grade
    count_individuals = 0
    count_pairs = 0
    
    for i in range(8,13):
        school_summary_info.append('Grade %d: %d individuals and %d pairs'%(i, len(grade_summary[i,False]),len(grade_summary[i,True])))
        count_pairs = count_pairs + len(grade_summary[i,True])
        count_individuals = count_individuals + len(grade_summary[i,False])
        
    school_summary_statistics = 'You have successfully registered %d students (%d individuals and %d pairs).'%(count_pairs*2+count_individuals, count_individuals, count_pairs)

    c = {
        'school_summary_blurb':school_summary_blurb,
        'school_summary_info':school_summary_info,
        'school_summary_statistics':school_summary_statistics,
        }

    c.update(csrf(request))
    return render_to_response('submitted.html', c)
Пример #2
0
def submitted(request):

    school_summary_blurb = 'Thank you for using the UCT Mathematics Competition online Registration Portal. You have successfully registered:'

    try:  #Try get the student list for the school assigned to the requesting user
        school_asmt = School.objects.get(assigned_to=request.user)
        student_list = SchoolStudent.objects.all().filter(school=school_asmt)
    except exceptions.ObjectDoesNotExist:
        return HttpResponseRedirect('../school_select/school_select.html')
    except Exception:
        school_summary_blurb = 'An error has occured.'  #This could occur if a user has become associated with > 1 school.

    grade_summary = compadmin.gradeBucket(
        student_list)  #Bin into categories (Pairing, grade)
    school_summary_info = []  #Entry for each grade
    count_individuals = 0
    count_pairs = 0

    for i in range(8, 13):
        grade_summary_text = 'Grade %d: %d individuals' % (
            i, len(grade_summary[i, False, 'ALL']))
        if compadmin.admin_number_of_pairs() > 0:
            grade_summary_text += " and %d pairs" % (len(grade_summary[i, True,
                                                                       'ALL']))
        school_summary_info.append(grade_summary_text)
        count_pairs = count_pairs + len(grade_summary[i, True, 'ALL'])
        count_individuals = count_individuals + len(grade_summary[i, False,
                                                                  'ALL'])

    school_summary_statistics = 'You have successfully registered %d students' % (
        count_pairs * 2 + count_individuals)

    if compadmin.admin_number_of_pairs() > 0:
        school_summary_statistics += '(%d individuals and %d pairs).' % (
            count_individuals, count_pairs)

    c = {
        'school_summary_blurb': school_summary_blurb,
        'school_summary_info': school_summary_info,
        'school_summary_statistics': school_summary_statistics,
    }

    c.update(csrf(request))
    return render_to_response('submitted.html', c)
Пример #3
0
def printer_entry_result(request, school_list=None):
    """ Generate the printer entry template for each school (in the optional queryset or the one bound to the user issuing the request)."""
#had to easy_install html5lib pisa
#Create the HttpResponse object with the appropriate PDF headers.
    temp_school_list = []
    if not school_list: #If not called by the admin
        try:
            #Attempt to find user's chosen school
            temp_school_list.append(School.objects.get(assigned_to=request.user))
        except exceptions.ObjectDoesNotExist:
            # No school is associated with this user! Redirect to the select_schools page
            return HttpResponseRedirect('../school_select/school_select.html')
    else:
        temp_school_list = [school for school in school_list]

    html = '' #Will hold rendered templates

    for assigned_school in temp_school_list:
        #Required that school form is pre-fetched to populate form
        student_list = SchoolStudent.objects.filter(school = assigned_school)
        individual_list, pair_list = compadmin.processGrade(student_list) #processGrade is defined below this method
            
        grade_summary = compadmin.gradeBucket(student_list) #Bin into categories (Pairing, grade)
        school_summary_info = [] #Entry for each grade
        count_individuals = 0
        count_pairs = 0
        
        for i in range(8,13):
            count_pairs = count_pairs + len(grade_summary[i,True])
            count_individuals = count_individuals + len(grade_summary[i,False])
        
        invigilator_list = Invigilator.objects.filter(school = assigned_school)
        responsible_teacher = ResponsibleTeacher.objects.filter(school = assigned_school)
        timestamp = str(datetime.now().strftime('%d %B %Y at %H:%M (local time)'))
        
        #If someone managed to get to this page without having made an entry
        if not responsible_teacher and not school_list:
            return HttpResponseRedirect('../students/newstudents.html')
        #If the school has an entry
        elif responsible_teacher:
            c = {'type':'Students',
                'timestamp':timestamp,
                'schooln':assigned_school,
                'responsible_teacher':responsible_teacher[0],
                'student_list':individual_list,
                'pair_list':pair_list,
                'entries_open':compadmin.isOpen(),
                'invigilator_list': invigilator_list,
                'grades':range(8,13),
                'grade_left':range(8,11),
                'invigilator_range':range(10-len(invigilator_list)), 
                'igrades':range(8,13),
                'total_num':int(count_pairs*2+count_individuals)}
            #Render the template with the context (from above)
            template = get_template('printer_entry.html')
            c.update(csrf(request))
            context = Context(c)
            html += template.render(context) #Concatenate each rendered template to the html "string"
        else:
            c = {'type':'Students',
                'timestamp':timestamp,
                'schooln': assigned_school,
                'grades':range(8,13),
                'grade_left':range(8,11),
                'invigilator_range':range(10-len(invigilator_list)), 
                'igrades':range(8,13),
                'total_num':'No students entered for this school'}

        #Render the template with the context (from above)
            template = get_template('printer_entry.html')
            c.update(csrf(request))
            context = Context(c)
            html += template.render(context) #Concatenate each rendered template to the html "string"


    result = StringIO.StringIO()

    #Generate the pdf doc
    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), result, encoding='UTF-8')
    if not pdf.err:
        return result
    else:
        pass #Error handling?
Пример #4
0
def printer_entry_result(request, school_list=None):
    """ Generate the printer entry template for each school (in the optional queryset or the one bound to the user issuing the request)."""
    #had to easy_install html5lib pisa
    #Create the HttpResponse object with the appropriate PDF headers.
    temp_school_list = []
    if not school_list:  #If not called by the admin
        try:
            #Attempt to find user's chosen school
            temp_school_list.append(
                School.objects.get(assigned_to=request.user))
        except exceptions.ObjectDoesNotExist:
            # No school is associated with this user! Redirect to the select_schools page
            return HttpResponseRedirect('../school_select/school_select.html')
    else:
        temp_school_list = [school for school in school_list]

    html = ''  #Will hold rendered templates

    for assigned_school in temp_school_list:
        #Required that school form is pre-fetched to populate form
        student_list = SchoolStudent.objects.filter(school=assigned_school)
        individual_list, pair_list = compadmin.processGrade(
            student_list)  #processGrade is defined below this method

        grade_summary = compadmin.gradeBucket(
            student_list)  #Bin into categories (Grade, Is Paired, Location)
        count_individuals = 0
        count_pairs = 0

        for i in range(8, 13):
            count_pairs = count_pairs + len(grade_summary[i, True, 'ALL'])
            count_individuals = count_individuals + len(grade_summary[i, False,
                                                                      'ALL'])

        invigilator_list = Invigilator.objects.filter(school=assigned_school)
        responsible_teacher = ResponsibleTeacher.objects.filter(
            school=assigned_school)
        timestamp = str(
            datetime.now().strftime('%d %B %Y at %H:%M (local time)'))
        year = str(datetime.now().strftime('%Y'))

        #If someone managed to get to this page without having made an entry
        if not responsible_teacher and not school_list:
            return HttpResponseRedirect('../students/newstudents.html')
        #If the school has an entry
        elif responsible_teacher:
            c = {
                'type': 'Students',
                'timestamp': timestamp,
                'schooln': assigned_school,
                'responsible_teacher': responsible_teacher[0],
                'student_list': individual_list,
                'pair_list': pair_list,
                'entries_open': compadmin.isOpen() or request.user.is_staff,
                'invigilator_list': invigilator_list,
                'grades': range(8, 13),
                'grade_left': range(8, 11),
                'invigilator_range': range(10 - len(invigilator_list)),
                'igrades': range(8, 13),
                'total_num': int(count_pairs * 2 + count_individuals),
                'year': year
            }
            #Render the template with the context (from above)
            template = get_template('printer_entry.html')
            c.update(csrf(request))
            context = Context(c)
            html += template.render(
                context
            )  #Concatenate each rendered template to the html "string"
        else:
            c = {
                'type': 'Students',
                'timestamp': timestamp,
                'schooln': assigned_school,
                'grades': range(8, 13),
                'grade_left': range(8, 11),
                'invigilator_range': range(10 - len(invigilator_list)),
                'igrades': range(8, 13),
                'total_num': 'No students entered for this school'
            }

            #Render the template with the context (from above)
            template = get_template('printer_entry.html')
            c.update(csrf(request))
            context = Context(c)
            html += template.render(
                context
            )  #Concatenate each rendered template to the html "string"

    result = StringIO.StringIO()

    #Generate the pdf doc
    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")),
                            result,
                            encoding='UTF-8')
    if not pdf.err:
        return result
    else:
        pass  #Error handling?