From c743f5810443a915c82d01ac099e76be17912148 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 29 Aug 2014 15:07:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E2=80=9C=E6=88=91=E7=9A=84=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E2=80=9D=20=E8=AE=A8=E8=AE=BA=E5=8C=BA=E4=B8=AD=20?= =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=86=85=E5=AE=B9=E6=A1=86=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=90=8D=E5=AD=97=EF=BC=8C=E4=B8=94=E6=98=AF=E5=90=A6=E4=B8=BA?= =?UTF-8?q?=E5=BF=85=E9=A1=BB=E6=B2=A1=E6=9C=89=E6=8F=90=E7=A4=BA=20#1524?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/messages/_form.html.erb | 11 ++++++----- config/locales/zh.yml | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/views/messages/_form.html.erb b/app/views/messages/_form.html.erb index 55aa829c8..047f7d660 100644 --- a/app/views/messages/_form.html.erb +++ b/app/views/messages/_form.html.erb @@ -27,14 +27,15 @@


<%# modify by nwb%> <% if @message.project %> - <%= f.select :board_id, boards_options_for_select(@message.project.boards) %>

+ <%= f.select :board_id, boards_options_for_select(@message.project.boards) %> <% elsif @message.course %> - <%= f.select :board_id, boards_options_for_select(@message.course.boards) %>

+ <%= f.select :board_id, boards_options_for_select(@message.course.boards) %> <% end %> +

<% end %> -
- - <%= text_area :quote,:quote,:style => 'display:none' %> +

+ <%= text_area :quote,:quote,:style => 'display:none' %> +

<%= label_tag "message_content", l(:description_message_content), :class => "hidden-for-sighted" %> <%= f.text_area :content, :cols => 80, :rows => 13, :class => 'wiki-edit', :id => 'message_content' %>

diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 224190060..54585e314 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -276,6 +276,7 @@ zh: field_is_default: 默认值 field_tracker: 跟踪 field_subject: 主题 + field_quote: 描述 field_due_date: 计划完成日期 field_assigned_to: 指派给 field_priority: 优先级 From c8e895ec748d26ccf5e108ed5c2b4928d26dd13a Mon Sep 17 00:00:00 2001 From: nwb Date: Fri, 29 Aug 2014 15:28:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/avatar_controller.rb | 18 ++++++++++++- app/controllers/my_controller.rb | 38 ++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/app/controllers/avatar_controller.rb b/app/controllers/avatar_controller.rb index b7dec5453..771a14fe8 100644 --- a/app/controllers/avatar_controller.rb +++ b/app/controllers/avatar_controller.rb @@ -28,6 +28,13 @@ class AvatarController < ApplicationController if @temp_file && (@temp_file.size > 0) diskfile=disk_filename(@source_type,@source_id) @urlfile='/' << File.join("images","avatars",avatar_directory(@source_type),avatar_filename(@source_id,@image_file)) + + # 用户头像上传时进行特别处理 + if @source_type == 'User' + diskfile += "temp" + @urlfile += "temp" + end + logger.info("Saving avatar '#{diskfile}' (#{@temp_file.size} bytes)") path = File.dirname(diskfile) unless File.directory?(path) @@ -96,7 +103,16 @@ class AvatarController < ApplicationController unless diskfile.nil? || diskfile == "" path = File.dirname(diskfile) if File.directory?(path) && File.exist?(diskfile) - File.delete(diskfile) + # 用户头像进行特别处理 + if @source_type == 'User' + diskfile1 = diskfile + 'temp' + File.open(diskfile1, "wb") do |f| + buffer = "DELETE" + f.write(buffer) + end + else + File.delete(diskfile) + end end end rescue e do diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 0559d1a4a..32ae2efc2 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -76,6 +76,8 @@ class MyController < ApplicationController def account @user = User.current @pref = @user.pref + diskfile = disk_filename('User', @user.id) + diskfile1 = diskfile + 'temp' if request.post? @user.safe_attributes = params[:user] @user.pref.attributes = params[:pref] @@ -97,6 +99,33 @@ class MyController < ApplicationController @se.student_id = params[:no] if params[:no] if @user.save && @se.save + # 头像保存 + if File.exist?(diskfile1) + if File.exist?(diskfile) + File.delete(diskfile) + end + File.open(diskfile1, "rb") do |f| + buffer = f.read(10) + if buffer != "DELETE" + File.open(diskfile1, "rb") do |f1| + File.open(diskfile, "wb") do |f| + buffer = "" + while (buffer = f1.read(8192)) + f.write(buffer) + end + end + end + + # File.rename(diskfile + 'temp',diskfile); + end + end + end + + # 确保文件被删除 + if File.exist?(diskfile1) + File.delete(diskfile1) + end + @user.pref.save @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) set_language_if_valid @user.language @@ -104,8 +133,17 @@ class MyController < ApplicationController redirect_to user_path(@user) return else + # 确保文件被删除 + if File.exist?(diskfile1) + File.delete(diskfile1) + end @user end + else + # 确保文件被删除 + if File.exist?(diskfile1) + File.delete(diskfile1) + end end end