Example #1
0
def teacher_grade_download(request, id, type=None):
    """ Download grading spreadsheet of requested class 
    id: course id
    type: filetype (ods or xls)"""
    if not type:
        profile = UserPreference.objects.get_or_create(user=request.user)[0]
        type = profile.get_format(type="spreadsheet")
    course = Course.objects.get(id=id)
    template, created = Template.objects.get_or_create(name="grade spreadsheet")
    filename = unicode(course) + "_grade"
    data={}
    data['$students'] = []
    data['$username'] = []
    
    for student in course.get_enrolled_students(show_deleted=True):
        data['$students'].append(unicode(student))
        data['$username'].append(unicode(student.username))
    
    if True:
        # Libreoffice crashes sometimes, maybe 5% of the time. So try it some more!
        for x in range(0,3):
            try:
                template_path = template.get_template_path(request)
                if not template_path:
                    return HttpResponseRedirect(reverse('admin:index'))
                return replace_spreadsheet(template_path, filename, data, type)
            except:
                logging.warning('LibreOffice crashed?', exc_info=True, extra={
                    'request': request,
                })
                time.sleep(3)
        return replace_spreadsheet(template_path, filename, data, type)
Example #2
0
def teacher_grade_download(request, id, type=None):
    """ Download grading spreadsheet of requested class 
    id: course id
    type: filetype (ods or xls)"""
    if not type:
        profile = UserPreference.objects.get_or_create(user=request.user)[0]
        type = profile.get_format(type="spreadsheet")
    course = Course.objects.get(id=id)
    template, created = Template.objects.get_or_create(
        name="grade spreadsheet")
    filename = unicode(course) + "_grade"
    data = {}
    data['$students'] = []
    data['$username'] = []

    for student in Student.objects.filter(courseenrollment__course=course):
        data['$students'].append(unicode(student))
        data['$username'].append(unicode(student.username))

    if True:
        # Libreoffice crashes sometimes, maybe 5% of the time. So try it some more!
        for x in range(0, 3):
            try:
                template_path = template.get_template_path(request)
                if not template_path:
                    return HttpResponseRedirect(reverse('admin:index'))
                return replace_spreadsheet(template_path, filename, data, type)
            except:
                logging.warning('LibreOffice crashed?',
                                exc_info=True,
                                extra={
                                    'request': request,
                                })
                time.sleep(3)
        return replace_spreadsheet(template_path, filename, data, type)