修复当作业附件列表为空时,点击打包下载会报500错的BUG
This commit is contained in:
parent
aebae800dd
commit
ab55043880
|
@ -37,9 +37,17 @@ class ZipdownController < ApplicationController
|
|||
#下载某一学生的作业的所有文件
|
||||
def download_user_homework
|
||||
homework = HomeworkAttach.find params[:homework]
|
||||
if homework != nil && (User.current.admin? || User.current.member_of_course?(homework.bid.courses.first))
|
||||
zipfile = zip_homework_by_user homework
|
||||
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if zipfile
|
||||
if User.current.admin? || User.current.member_of_course?(homework.bid.courses.first)
|
||||
if homework != nil
|
||||
if homework.attachments.count > 0
|
||||
zipfile = zip_homework_by_user homework
|
||||
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if zipfile
|
||||
else
|
||||
render_403 :message => :no_file_dowmload
|
||||
end
|
||||
else
|
||||
render_403 :message =>:notice_file_not_found
|
||||
end
|
||||
else
|
||||
render_403 :message => :notice_not_authorized
|
||||
end
|
||||
|
@ -81,15 +89,17 @@ class ZipdownController < ApplicationController
|
|||
end
|
||||
|
||||
def zip_homework_by_user(homeattach)
|
||||
homeworks_attach_path = []
|
||||
# 需要将所有homework.attachments遍历加入zip
|
||||
# 并且返回zip路径
|
||||
user_attaches_paths = homeattach.attachments.each do |attach|
|
||||
#length = attach.storage_path.length
|
||||
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
||||
end
|
||||
zipping "#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true
|
||||
#user_attaches_paths
|
||||
#if homeattach.attachments.count > 0
|
||||
homeworks_attach_path = []
|
||||
# 需要将所有homework.attachments遍历加入zip
|
||||
# 并且返回zip路径
|
||||
user_attaches_paths = homeattach.attachments.each do |attach|
|
||||
#length = attach.storage_path.length
|
||||
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
||||
end
|
||||
zipping("#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true)
|
||||
#user_attaches_paths
|
||||
#end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -8,10 +8,7 @@
|
|||
<table width="100%" valign="center">
|
||||
<tr>
|
||||
<td ><span style="margin-left:0px"><%= l(:label_task_plural)%>(<%= @homework_list.count%>)</span>
|
||||
<%#= link_to "作业打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), remote: false, class: "button_submit button_submit_font_white", style: "margin: 5px 10px;line-height: 20px;height: 20px;display: inline-block;" if(
|
||||
User.current.admin? ||
|
||||
!(User.current.roles_for_project(@bid.courses.first).map(&:id) & ([7,9])).empty? ) ||
|
||||
(Rails.env.development?) %>
|
||||
<%#= link_to "作业打包下载", zipdown_assort_path(obj_class: @bid.class, obj_id: @bid), remote: false, class: "button_submit button_submit_font_white", style: "margin: 5px 10px;line-height: 20px;height: 20px;display: inline-block;" if(is_teacher) %>
|
||||
</td>
|
||||
<td align="right">
|
||||
<div class="project-search">
|
||||
|
|
|
@ -1867,6 +1867,7 @@ zh:
|
|||
lable_close_mutual_evaluation: 关闭互评
|
||||
label_has_been: 已经被
|
||||
label_course_userd_by: 个课程引用
|
||||
no_file_dowmload: 该作业没有任何的附件可以下载
|
||||
|
||||
role_of_course: 课程角色
|
||||
label_student: 学生
|
||||
|
|
Loading…
Reference in New Issue