gpx import now fully works

This commit is contained in:
Steve Coast 2007-04-07 14:06:26 +00:00
parent f1189ae115
commit 4434bac3b4
5 changed files with 13 additions and 12 deletions

View file

@ -99,23 +99,22 @@ class TraceController < ApplicationController
File.open(filename, "w") { |f| f.write(@params['trace']['gpx_file'].read) } File.open(filename, "w") { |f| f.write(@params['trace']['gpx_file'].read) }
@params['trace']['name'] = @params['trace']['gpx_file'].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane @params['trace']['name'] = @params['trace']['gpx_file'].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane
@params['trace'].delete('gpx_file') # let's remove the field from the hash, because there's no such field in the DB anyway. @params['trace'].delete('gpx_file') # remove the field from the hash, because there's no such field in the DB
@trace = Trace.new(@params['trace']) @trace = Trace.new(@params['trace'])
@trace.inserted = false @trace.inserted = false
@trace.user_id = @user.id @trace.user = @user
@trace.timestamp = Time.now @trace.timestamp = Time.now
saved_filename = "/tmp/#{@trace.id}.gpx"
# *nix - specific `mv #{filename} /tmp/#{@trace.id}.gpx`
File.rename(filename, saved_filename)
@trace.tmpname = saved_filename
if @trace.save if @trace.save
saved_filename = "/tmp/#{@trace.id}.gpx"
File.rename(filename, saved_filename)
logger.info("id is #{@trace.id}") logger.info("id is #{@trace.id}")
flash[:notice] = "Your GPX file has been uploaded and is awaiting insertion in to the database. This will usually happen within half an hour, and an email will be sent to you on completion." flash[:notice] = "Your GPX file has been uploaded and is awaiting insertion in to the database. This will usually happen within half an hour, and an email will be sent to you on completion."
redirect_to :action => 'mine'
else else
#TODO upload failure # render :action => 'mine'
end end
redirect_to :action => 'mine'
end end
def georss def georss

View file

@ -1,8 +1,8 @@
class Trace < ActiveRecord::Base class Trace < ActiveRecord::Base
set_table_name 'gpx_files' set_table_name 'gpx_files'
validates_presence_of :user_id, :name, :public, :description, :tmpname, :timestamp validates_presence_of :user_id, :name, :public, :description, :timestamp
validates_numericality_of :latitude, :longitude # validates_numericality_of :latitude, :longitude
validates_inclusion_of :inserted, :in => [ true, false] validates_inclusion_of :inserted, :in => [ true, false]
belongs_to :user belongs_to :user

View file

@ -10,7 +10,7 @@
<td class="<%= cl %>"><%= link_to trace.name, {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %> <td class="<%= cl %>"><%= link_to trace.name, {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %>
<span class="gpxsummary" title="<%= trace.timestamp %>"> ... <span class="gpxsummary" title="<%= trace.timestamp %>"> ...
<% if trace.inserted %> <% if trace.inserted %>
(<%= trace.size %> points) (<%= trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %> points)
<% end %> <% end %>
... <%= time_ago_in_words( trace.timestamp ) %> ago</span> ... <%= time_ago_in_words( trace.timestamp ) %> ago</span>
<%= link_to 'more', {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %> / <%= link_to 'more', {:controller => 'trace', :action => 'view', :display_name => trace.user.display_name, :id => trace.id} %> /

View file

@ -13,6 +13,7 @@
<br /> <br />
<% if @user %> <% if @user %>
<%= start_form_tag({:action => 'create'}, :multipart => true) %> <%= start_form_tag({:action => 'create'}, :multipart => true) %>
<table> <table>
<table> <table>

View file

@ -32,3 +32,4 @@ create index users_display_name_idx on users(display_name);
alter table users add data_public boolean default false; alter table users add data_public boolean default false;
alter table gpx_files drop column tmpname;