student_works添加字段commit_time,记录学生作品实际的提交时间

This commit is contained in:
cxt 2016-08-10 16:50:27 +08:00
parent 71326c901d
commit 7edb30754b
7 changed files with 27 additions and 8 deletions

View File

@ -597,6 +597,7 @@ class StudentWorkController < ApplicationController
student_work.description = params[:student_work][:description]
student_work.homework_common_id = @homework.id
student_work.user_id = User.current.id
student_work.commit_time = Time.now
student_work.save_attachments(params[:attachments])
render_attachment_warning_if_needed(student_work)
if @homework.homework_type == 3 && @homework.homework_detail_group.base_on_project == 1
@ -791,7 +792,7 @@ class StudentWorkController < ApplicationController
end
end
elsif @homework.homework_type == 1
@work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0)
@work.update_attributes(:work_status => 0, :name => "#{@homework.name}的作品提交", :description => nil, :late_penalty => 0, :commit_time => nil)
end
@student_work = StudentWork.new
respond_to do |format|
@ -826,7 +827,7 @@ class StudentWorkController < ApplicationController
@new_score.user_id = User.current.id
@new_score.student_work_id = @work.id
if @is_teacher && @work.work_status == 0
@work.update_column('work_status', 1)
@work.update_attributes(:work_status => 1, :commit_time => Time.now)
end
if User.current.admin?
@new_score.reviewer_role = 1

View File

@ -1004,6 +1004,7 @@ class UsersController < ApplicationController
student_work.work_status = 1
end
student_work.commit_time = Time.now
student_work.save
send_message_to_teacher(student_work)
homework.update_column(:updated_at, Time.now)

View File

@ -1,6 +1,6 @@
#学生提交作品表
class StudentWork < ActiveRecord::Base
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test, :simi_id, :simi_value, :work_status
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test, :simi_id, :simi_value, :work_status, :commit_time
belongs_to :homework_common
belongs_to :user

View File

@ -135,9 +135,9 @@
</div>
<div class="cl"></div>
<% if activity.student_works.has_committed.count != 0 %>
<% sw = activity.student_works.has_committed.reorder("created_at desc").first %>
<% sw = activity.student_works.has_committed.reorder("commit_time desc").first %>
<div class="mt10 homepagePostDeadline mb10">
#&nbsp;<%=time_from_now sw.created_at %><%= link_to sw.user.show_name, user_activities_path(sw.user_id), :class => "newsBlue ml5 mr5"%>提交了作品
#&nbsp;<%=time_from_now sw.commit_time %><%= link_to sw.user.show_name, user_activities_path(sw.user_id), :class => "newsBlue ml5 mr5"%>提交了作品
</div>
<% end %>
<div class="cl"></div>

View File

@ -146,9 +146,9 @@
</div>
<div class="cl"></div>
<% if homework_common.student_works.has_committed.count != 0 %>
<% sw = homework_common.student_works.has_committed.reorder("created_at desc").first %>
<% sw = homework_common.student_works.has_committed.reorder("commit_time desc").first %>
<div class="mt10 homepagePostDeadline mb10">
#&nbsp;<%=time_from_now sw.created_at %><%= link_to sw.user.show_name, user_activities_path(sw.user_id), :class => "newsBlue ml5 mr5"%>提交了作品
#&nbsp;<%=time_from_now sw.commit_time %><%= link_to sw.user.show_name, user_activities_path(sw.user_id), :class => "newsBlue ml5 mr5"%>提交了作品
</div>
<% end %>
<div class="cl"></div>

View File

@ -0,0 +1,16 @@
class AddCommitTimeToStudentWork < ActiveRecord::Migration
def change
add_column :student_works, :commit_time, :datetime
count = StudentWork.all.count / 30 + 2
transaction do
for i in 1 ... count do i
StudentWork.page(i).per(30).each do |work|
if work.work_status != 0
work.update_column("commit_time", work.created_at)
end
end
end
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160729124833) do
ActiveRecord::Schema.define(:version => 20160810080942) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -1840,6 +1840,7 @@ ActiveRecord::Schema.define(:version => 20160729124833) do
t.integer "simi_value"
t.float "work_score"
t.integer "work_status", :default => 0
t.datetime "commit_time"
end
add_index "student_works", ["homework_common_id", "user_id"], :name => "index_student_works_on_homework_common_id_and_user_id"