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
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')