Merge branch 'Homework' into szzh
This commit is contained in:
commit
dbf08bc486
|
@ -19,17 +19,13 @@ class ZipdownController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def assort
|
def assort
|
||||||
obj_class = params[:obj_class]
|
if params[:obj_class] == "Bid"
|
||||||
obj_id = params[:obj_id]
|
bid = Bid.find params[:obj_id]
|
||||||
obj = obj_class.constantize.find(obj_id)
|
zipfile = zip_bid bid
|
||||||
zipfile = nil
|
|
||||||
case obj.class.to_s.to_sym
|
|
||||||
when :Bid
|
|
||||||
zipfile = zip_bid obj
|
|
||||||
else
|
else
|
||||||
logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!"
|
logger.error "[ZipDown#assort] ===> #{params[:obj_class]} unKown !!"
|
||||||
end
|
end
|
||||||
send_file zipfile, :filename => obj.name+".zip", :type => detect_content_type(zipfile) if zipfile
|
send_file zipfile, :filename => bid.name + ".zip", :type => detect_content_type(zipfile) if zipfile
|
||||||
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
render file: 'public/no_file_found.html'
|
render file: 'public/no_file_found.html'
|
||||||
|
@ -40,61 +36,43 @@ class ZipdownController < ApplicationController
|
||||||
homework = HomeworkAttach.find params[:homework]
|
homework = HomeworkAttach.find params[:homework]
|
||||||
if User.current.admin? || User.current.member_of_course?(homework.bid.courses.first)
|
if User.current.admin? || User.current.member_of_course?(homework.bid.courses.first)
|
||||||
if homework != nil
|
if homework != nil
|
||||||
if homework.attachments.count > 0
|
unless homework.attachments.empty?
|
||||||
zipfile = zip_homework_by_user homework
|
zipfile = zip_homework_by_user homework
|
||||||
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if(zipfile)
|
send_file zipfile, :filename => homework.name+".zip", :type => detect_content_type(zipfile) if(zipfile)
|
||||||
else
|
else
|
||||||
render file: 'public/no_file_found.html' , :layout => 'course_base'
|
render file: 'public/no_file_found.html'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render file: 'public/file_not_found.html' , :layout => 'course_base'
|
render file: 'public/file_not_found.html'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render_403 :message => :notice_not_authorized ,:layout => "course_base"
|
render_403
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
render file: 'public/file_not_found.html' , :layout => 'course_base'
|
render file: 'public/file_not_found.html'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def zip_user_bid(bid,user_id)
|
|
||||||
# Todo: User Access Controll
|
|
||||||
|
|
||||||
homeattaches = bid.homeworks.where("user_id = ?",user_id)
|
|
||||||
# 得到每一个人所有文件打包的zip文件
|
|
||||||
# 并将每一个人的zip打包为一个并返回路径
|
|
||||||
user_zip_paths = homeattaches.map do |homeattach|
|
|
||||||
zip_homework_by_user homeattach
|
|
||||||
end
|
|
||||||
user_zip_paths
|
|
||||||
end
|
|
||||||
|
|
||||||
def zip_bid(bid)
|
def zip_bid(bid)
|
||||||
# Todo: User Access Controll
|
# Todo: User Access Controll
|
||||||
|
bid_homework_path = []
|
||||||
homeattaches = bid.homeworks
|
bid.homeworks.each do |homeattach|
|
||||||
#记录所有作业是不是有附件,有一个附件就改为true
|
unless homeattach.attachments.empty?
|
||||||
#has_file = false
|
bid_homework_path << zip_homework_by_user(homeattach)
|
||||||
# 得到每一个人所有文件打包的zip文件
|
|
||||||
# 并将每一个人的zip打包为一个并返回路径
|
|
||||||
user_zip_paths = homeattaches.map do |homeattach|
|
|
||||||
if homeattach.attachments.count > 0
|
|
||||||
zip_homework_by_user homeattach
|
|
||||||
#has_file = true unless has_file
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER
|
zipping "#{Time.now.to_i}_#{bid.name}.zip", bid_homework_path, OUTPUT_FOLDER
|
||||||
end
|
end
|
||||||
|
|
||||||
def zip_homework_by_user(homeattach)
|
def zip_homework_by_user(homeattach)
|
||||||
homeworks_attach_path = []
|
homeworks_attach_path = []
|
||||||
# 需要将所有homework.attachments遍历加入zip
|
# 需要将所有homework.attachments遍历加入zip
|
||||||
# 并且返回zip路径
|
# 并且返回zip路径
|
||||||
user_attaches_paths = homeattach.attachments.each do |attach|
|
homeattach.attachments.each do |attach|
|
||||||
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1)
|
||||||
end
|
end
|
||||||
zipping("#{homeattach.user.name.to_s}_#{Time.now.to_i}.zip", homeworks_attach_path, OUTPUT_FOLDER, true)
|
zipping("#{Time.now.to_i.to_s}_#{homeattach.user.name}_#{homeattach.user.user_extensions.student_id}.zip", homeworks_attach_path, OUTPUT_FOLDER, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,14 +81,14 @@ class ZipdownController < ApplicationController
|
||||||
ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
|
ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
|
||||||
input_filename = files_paths
|
input_filename = files_paths
|
||||||
|
|
||||||
rename_zipfile = zip_name_refer ||= "archive_#{Time.now.to_i}.zip"
|
rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip"
|
||||||
zipfile_name = "#{output_path}/#{rename_zipfile}"
|
zipfile_name = "#{output_path}/#{rename_zipfile}"
|
||||||
|
|
||||||
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
|
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
|
||||||
|
|
||||||
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
||||||
input_filename.each do |filename|
|
input_filename.each do |filename|
|
||||||
rename_file = Time.now.to_i.to_s+ ic.iconv( (File.basename(filename)) ).to_s
|
rename_file = ic.iconv( (File.basename(filename)) ).to_s
|
||||||
rename_file = ic.iconv( filename_to_real( File.basename(filename))).to_s if is_attachment
|
rename_file = ic.iconv( filename_to_real( File.basename(filename))).to_s if is_attachment
|
||||||
|
|
||||||
zipfile.add(rename_file, filename)
|
zipfile.add(rename_file, filename)
|
||||||
|
|
|
@ -12,5 +12,5 @@
|
||||||
|
|
||||||
<% elsif @is_comprehensive_evaluation == 1%>
|
<% elsif @is_comprehensive_evaluation == 1%>
|
||||||
<%= l(:label_work_rating) %>:
|
<%= l(:label_work_rating) %>:
|
||||||
<%= rating_for homework, dimension: :quality,start_score: 0, class: 'rateable div_inline' %>
|
<%= rating_for homework, dimension: :quality,start_score: @m_score, class: 'rateable div_inline' %>
|
||||||
<% end %>
|
<% end %>
|
|
@ -65,8 +65,8 @@
|
||||||
<span id="homework_attach_name_span"></span>
|
<span id="homework_attach_name_span"></span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label style="float:left;">
|
<label style="float:left;padding-left:10px;">
|
||||||
<span class="c_red">*</span>
|
<span class="c_red"></span>
|
||||||
作业描述 :
|
作业描述 :
|
||||||
</label>
|
</label>
|
||||||
<%= f.text_area :description, :rows => 8, :name => "homework_description", :class => "w620",
|
<%= f.text_area :description, :rows => 8, :name => "homework_description", :class => "w620",
|
||||||
|
|
|
@ -55,13 +55,13 @@
|
||||||
<span id="homework_attach_name_span"></span>
|
<span id="homework_attach_name_span"></span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label style="float:left;">
|
<label style="float:left;padding-left:10px;">
|
||||||
<span class="c_red">
|
<span class="c_red">
|
||||||
*
|
|
||||||
</span>
|
</span>
|
||||||
作业描述 :
|
作业描述 :
|
||||||
</label>
|
</label>
|
||||||
<%= f.text_area "description", :class => "w620", :maxlength => 3000, :placeholder => "最多3000个汉字" %>
|
<%= f.text_area "description", :class => "w620", :maxlength => 3000, :placeholder => "最多3000个汉字"%>
|
||||||
</p>
|
</p>
|
||||||
<div class="cl"></div>
|
<div class="cl"></div>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -604,7 +604,7 @@ zh:
|
||||||
#by young
|
#by young
|
||||||
label_requirement: 需求
|
label_requirement: 需求
|
||||||
label_new_course: 课程列表
|
label_new_course: 课程列表
|
||||||
label_course_practice: 课程作业
|
label_course_practice: 课程实践
|
||||||
label_course_all: 课程列表
|
label_course_all: 课程列表
|
||||||
label_teacher_all: 所有教师
|
label_teacher_all: 所有教师
|
||||||
label_project_deposit: 项目托管
|
label_project_deposit: 项目托管
|
||||||
|
|
Loading…
Reference in New Issue