Пример #1
0
def index_course(request, course_id):
    course = Course.get_by_id(int(course_id))
    if course is None:
        raise Http404

    logging.info('course: %s'%course)
    backup_list = CourseBackup.list_for_course(str(course.key()))
    
    return render_to_response('admin/backup_list.html', RequestContext(request, { 'backup_list': backup_list, 'course':course}))
Пример #2
0
def get_backup(request, course_id, course_backup_id):
    course = Course.get_by_id(int(course_id))
    if course is None:
        raise Http404

    course_backup = CourseBackup.get_by_id(int(course_backup_id))
    if course_backup is None:
        raise Http404


    r =  HttpResponse(course_backup.data,mimetype='application/vnd.ms-excel')
    file_name = urllib.quote(course_backup.filename)
    logging.info(file_name)
    r['Content-Disposition'] = "attachment; filename*=UTF-8''%s"%file_name
    return r
Пример #3
0
def course_backup(request):
    logging.info(request.POST)
    course_id = request.POST['course_id']
    course = Course.get_by_id(int(course_id))
    if course is None:
        raise Http404 

    logging.info('course=%s'%course)


    student_list_to_enroll=Student.list_for_course_to_enroll(course.key())
    student_list_enrolled=Student.list_for_course_enrolled(course.key())


    if course.group_mode == 'Single':
        student_list_to_enroll = sort_students_spare_single(student_list_to_enroll)
        student_list_enrolled = sort_students_single(student_list_enrolled)
    elif course.group_mode == 'School':
        student_list_to_enroll = sort_students_spare_school(student_list_to_enroll)
        student_list_enrolled = sort_students_school(student_list_enrolled)
    elif course.group_mode == 'Pair':
        student_list_to_enroll = sort_students_spare_pair(student_list_to_enroll)
        student_list_enrolled = sort_students_pair(student_list_enrolled)

    students = []
    students.extend(student_list_enrolled)
    students.extend(student_list_to_enroll)

    data = [ ['#zaloha kurz',course.code,course.folder_name(),course.season_name()]]
    for s in students:
        if not s.x_pair_empty_slot:
            data.append(s.as_csv_row())
    
    out = cStringIO.StringIO()
    dump_to_csv(data,out)
#    logging.info(out)
    cb = CourseBackup()
    cb.init(out.getvalue(),course=course)
    cb.save()
    course.mark_as_backup()
    course.save()


    if cfg.getConfigBool('BACKUP_EMAIL_ON',False):
        taskqueue.add(url='/task/send_backup/', params={'coursebackup_id':cb.key().id()})
        logging.info('send task plan ok, cbid=%s'%(cb.key().id()))
    else:
        logging.info('BACKUP_EMAIL_ON is OFF!')
    return HttpResponse('ok')
Пример #4
0
def send_backup(request):

    logging.info(request.POST)


    if not cfg.getConfigBool('BACKUP_EMAIL_ON',False):
        logging.info('BACKUP_EMAIL_ON is OFF!')
        return HttpResponse('ok')

    cb_id = request.POST['coursebackup_id']
    cb = CourseBackup.get_by_id(int(cb_id))
    if cb is None:
        raise Http404 

    logging.info('cb=%s'%cb)


    sender = cfg.getConfigString('BACKUP_EMAIL_SENDER',None)
    to = cfg.getConfigString('BACKUP_EMAIL_TO',None)

    if sender is None:
        logging.info('no sender')
        return HttpResponse('ok')

    if to is None:
        logging.info('no to')
        return HttpResponse('ok')

    subject = "Zaloha %s"%(cb.info)
    body = "Zaloha %s, porizeno %s"%(cb.info,cb.create_datetime)
    
    gmail.send_mail(sender=sender, to=to,subject=subject,body=body,attachments=[(cb.filename,cb.data)])
    logging.info('send ok')


    return HttpResponse('ok')