竞赛提交附件的下载

This commit is contained in:
cxt 2017-01-13 11:17:21 +08:00
parent 2aa99f57ac
commit 8ce1c5a171
4 changed files with 18 additions and 17 deletions

View File

@ -43,10 +43,10 @@ class ZipdownController < ApplicationController
zip_homework_common homework
}
elsif params[:obj_class] == "Work"
homework = Work.find params[:obj_id]
render_403 if User.current.admin_of_contest?(homework.contest)
zipfile = checkfileSize(homework.contestant_works) {
zip_homework_common homework
contest_work = Work.find params[:obj_id]
render_403 if User.current.admin_of_contest?(contest_work.contest)
zipfile = checkfileSize(contest_work.contestant_works) {
zip_contest_work contest_work
}
else
logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"

View File

@ -72,7 +72,7 @@ module ZipService
digests = []
homework_common.contestant_works.each do |work|
unless work.attachments.empty?
out_file = zip_student_work_by_user(work)
out_file = zip_contestant_work_by_user(work)
bid_homework_path << out_file.file_path
digests << out_file.file_digest
@ -151,7 +151,7 @@ module ZipService
end
def zip_student_work_by_user(work)
def zip_contestant_work_by_user(work)
homeworks_attach_path = []
not_exist_file = []
# 需要将所有homework.attachments遍历加入zip
@ -169,13 +169,13 @@ module ZipService
#单个文件的话,不需要压缩,只改名
out_file = nil
if homeworks_attach_path.size == 1
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
out_file = find_or_pack(work.work_id, work.user_id, digests.sort){
des_path = "#{OUTPUT_FOLDER}/#{make_zip_name(work)}_#{File.basename(homeworks_attach_path.first)}"
FileUtils.cp homeworks_attach_path.first, des_path
des_path
}
else
out_file = find_or_pack(work.homework_common_id, work.user_id, digests.sort){
out_file = find_or_pack(work.work_id, work.user_id, digests.sort){
zipping("#{make_zip_name(work)}.zip",
homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file)
}

View File

@ -80,14 +80,15 @@
<li>
<%= link_to "导出提交成绩", contestant_works_path(:work => @contestwork.id,:order => @order, :sort => @b_sort, :name => @name, :group => @group, :format => 'xls'),:class=>'hworkExport postTypeGrey', :id => "export_student_work"%>
</li>
<!--<li>-->
<!--<%# if @homework.student_works.empty?%>-->
<!--<%#= link_to "导出作业附件", "javascript:void(0)", class: "hworkExport resourcesGrey", :onclick => "alert('没有学生提交作业,无法下载附件')" %>-->
<!--<%# else%>-->
<!--<%#= link_to "导出作业附件", zipdown_assort_path(obj_class: @homework.class, obj_id: @homework, format: :json),-->
<!--remote: true, class: "hworkExport resourcesGrey", :id => "download_homework_attachments" %>-->
<!--<%# end%>-->
<!--</li> -->
<li>
<% if @contestwork.contestant_works.has_committed.empty?%>
<a href="javascript:void(0)" class="hworkExport resourcesGrey" onclick="notice_box('没有学生提交作业,无法下载附件')">导出作业附件</a>
<%#= link_to "导出作业附件", "javascript:void(0)", class: "hworkExport resourcesGrey", :onclick => "alert('没有学生提交作业,无法下载附件')" %>
<% else%>
<%= link_to "导出作业附件", zipdown_assort_path(obj_class: @contestwork.class, obj_id: @contestwork, format: :json),
remote: true, class: "hworkExport resourcesGrey", :id => "download_homework_attachments" %>
<% end%>
</li>
</ul>
</li>
</ul>

View File

@ -126,7 +126,7 @@
<%= link_to "导出作业成绩", student_work_index_path(:homework => @homework.id,:order => @order, :sort => @b_sort, :name => @name, :group => @group, :format => 'xls'),:class=>'hworkExport postTypeGrey', :id => "export_student_work"%>
</li>
<li>
<% if @homework.student_works.empty?%>
<% if @homework.student_works.has_committed.empty?%>
<%= link_to "导出作业附件", "javascript:void(0)", class: "hworkExport resourcesGrey", :onclick => "alert('没有学生提交作业,无法下载附件')" %>
<% else%>
<%= link_to "导出作业附件", zipdown_assort_path(obj_class: @homework.class, obj_id: @homework, format: :json),