def image_stream(img_path, width, height): response = HttpResponse(content_type=IMAGE_FORMAT[IMAGE_FORMAT_DEFAULT][0]) pil, _ = image_process(img_path, width, height) pil.save(response, IMAGE_FORMAT[IMAGE_FORMAT_DEFAULT][1]) response['Content-Encoding'] = 'utf-8' response['Content-Disposition'] = 'attachment;filename=%s_w%s_h%s.%s' % (suuid(), width, height, IMAGE_FORMAT_DEFAULT) return response
def api_export_team(request, para): try: subjudge = SubJudge.objects.filter(id=int(para.subjudge_id)).first() if not subjudge: raise BusinessException(ERR_SUBJUDGE_NOT_EXIST) user, role = get_user(subjudge.activity, request.user) if not user: raise BusinessException(ERR_USER_AUTH) # 仅子级评审的维护者可使用 if not subjudge_services.is_subjudge_manager(subjudge, request.user): raise BusinessException(ERR_USER_AUTH) subjudge_team_id_list = [ int(each) for each in para.subjudge_team_list.strip().strip(',').split(',') if each ] # team_list = list(Team.objects.filter(id__in=team_id_list)) wb = subjudge_services.export_team(request.user, subjudge, user, role, subjudge_team_id_list) fname = u'%s.xlsx' % suuid() response = HttpResponse(content_type='application/vnd.ms-excel') response[ 'Content-Disposition'] = 'attachment; filename=' + fname.encode( 'utf-8') wb.save(response) return response # path = os.path.join(settings.BASE_DIR, 'media/%s.xlsx' % suuid()) # wb.save(path) # return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': path}) except Exception as ex: logger.exception(ex) return response_exception(ex)
def api_download_activity_role_template(request, para): try: activity = Activity.objects.filter(id=int(para.activity_id)).first() if not activity: raise BusinessException(ERR_ACTIVITY_NOT_EXIST) user, role = get_user(activity, request.user) if not user: raise BusinessException(ERR_USER_AUTH) wb = activity_s.download_activity_role_template( request.user, activity, user, role) fname = u'%s.xlsx' % suuid() response = HttpResponse(content_type='application/vnd.ms-excel') response[ 'Content-Disposition'] = 'attachment; filename=' + fname.encode( 'utf-8') wb.save(response) return response # path = os.path.join(settings.BASE_DIR, 'media/%s.xlsx' % suuid()) # wb.save(path) # return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': path}) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message)
def api_export_activity_expert(request, para): try: activity = Activity.objects.filter(id=int(para.activity_id)).first() if not activity: raise BusinessException(ERR_ACTIVITY_NOT_EXIST) user, role = get_user(activity, request.user) if not user: raise BusinessException(ERR_USER_AUTH) expert_id_list = [ int(r) for r in para.expert_id_list.strip().strip(',').split(',') ] expert_list = Expert.objects.filter(del_flag=FALSE_INT, id__in=expert_id_list) wb = activity_s.export_activity_expert(request.user, activity, user, role, expert_list) fname = u'%s.xlsx' % suuid() response = HttpResponse(content_type='application/vnd.ms-excel') response[ 'Content-Disposition'] = 'attachment; filename=' + fname.encode( 'utf-8') wb.save(response) return response # path = os.path.join(settings.BASE_DIR, 'media/%s.xlsx' % suuid()) # wb.save(path) # return response200({'c': SUCCESS[0], 'm': SUCCESS[1], 'd': path}) except Exception as ex: logger.exception(ex) return response_exception(ex, ex.message)
def dump_stream(self): fname = u'%s.xlsx' % suuid() response = HttpResponse(content_type='application/vnd.ms-excel') response[ 'Content-Disposition'] = 'attachment; filename=' + fname.encode( 'utf-8') self.wb.save(response) return response
def dump_file(self): path = os.path.join(settings.BASE_DIR, 'media/%s.xlsx' % suuid()) self.wb.save(path) return {'c': SUCCESS[0], 'm': SUCCESS[1], 'd': path}