]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/trace.rb
Tell users if the reason they can't login is because they haven't activated
[rails.git] / app / models / trace.rb
index 0307b5f653eac11a6563c7b21b5fa7ceae23a36a..97dcf963518327c516f8b607d733d7819a2c798a 100644 (file)
@@ -1,13 +1,25 @@
 class Trace < ActiveRecord::Base
   set_table_name 'gpx_files'
 
-  validates_presence_of :user_id, :name, :public, :description, :timestamp
+  validates_presence_of :user_id, :name, :timestamp
+  validates_presence_of :description, :on => :create
 #  validates_numericality_of :latitude, :longitude
-  validates_inclusion_of :inserted, :in => [ true, false]
+  validates_inclusion_of :public, :inserted, :in => [ true, false]
   
   belongs_to :user
-  has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :destroy
-  has_many :points, :class_name => 'Tracepoint', :foreign_key => 'gpx_id', :dependent => :destroy
+  has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :delete_all
+  has_many :points, :class_name => 'Tracepoint', :foreign_key => 'gpx_id', :dependent => :delete_all
+
+  def destroy
+    super
+    FileUtils.rm_f(trace_name)
+    FileUtils.rm_f(icon_picture_name)
+    FileUtils.rm_f(large_picture_name)
+  end
+
+  def tagstring
+    return tags.collect {|tt| tt.tag}.join(" ")
+  end
 
   def tagstring=(s)
     self.tags = s.split().collect {|tag|
@@ -110,6 +122,7 @@ class Trace < ActiveRecord::Base
         tp.lat = point['latitude'].to_f
         tp.lng = point['longitude'].to_f
         tp.altitude = point['altitude'].to_f
+        tp.timestamp = point['timestamp']
         tp.user_id = user.id
         tp.gpx_id = id
         tp.trackid = point['segment'].to_i
@@ -134,21 +147,11 @@ class Trace < ActiveRecord::Base
         self.size = gpx.actual_points
         self.inserted = true
         self.save
-
-        Notifier::deliver_gpx_success(self, gpx.possible_points)
-      else
-        FileUtils.rm_f("/home/osm/gpx/#{id}.gpx")
-        self.destroy
-        Notifier::deliver_gpx_failure(self, '0 points parsed ok. Do they all have lat,lng,alt,timestamp?')
       end
 
       logger.info "done trace #{id}"
-    rescue Exception => ex
-      logger.info ex
-      ex.backtrace.each {|l| logger.info l }
-      FileUtils.rm_f("/home/osm/gpx/#{id}.gpx")
-      self.destroy
-      Notifier::deliver_gpx_failure(self, ex.to_s + ex.backtrace.join("\n") )
+
+      return gpx
     ensure
       FileUtils.rm_f(tempfile) if tempfile
     end