From ab55043880ac1e19ecabbfd7c7acc49391e4c82a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Tue, 22 Jul 2014 09:42:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BD=93=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E5=88=97=E8=A1=A8=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E7=82=B9=E5=87=BB=E6=89=93=E5=8C=85=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E4=BC=9A=E6=8A=A5500=E9=94=99=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zipdown_controller.rb | 34 +++++++++++++++++--------- app/views/bids/_homework_list.html.erb | 5 +--- config/locales/zh.yml | 1 + 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 33a569f5d..777c0d8b7 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -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 diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 8b241030a..81c960781 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -8,10 +8,7 @@
<%= l(:label_task_plural)%>(<%= @homework_list.count%>) - <%#= 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) %> |
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index e75cf7b11..cd5dd630a 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -1867,6 +1867,7 @@ zh:
lable_close_mutual_evaluation: 关闭互评
label_has_been: 已经被
label_course_userd_by: 个课程引用
+ no_file_dowmload: 该作业没有任何的附件可以下载
role_of_course: 课程角色
label_student: 学生
|