]> git.openstreetmap.org Git - rails.git/blob - app/models/trace.rb
Update the postcode code to do a npemap lookup, rather than a FTP one
[rails.git] / app / models / trace.rb
1 class Trace < ActiveRecord::Base
2   set_table_name 'gpx_files'
3
4   validates_presence_of :user_id, :name, :public, :description, :timestamp
5 #  validates_numericality_of :latitude, :longitude
6   validates_inclusion_of :inserted, :in => [ true, false]
7   
8   belongs_to :user
9   has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id', :dependent => :destroy
10
11   def tagstring=(s)
12     self.tags = s.split().collect {|tag|
13       tt = Tracetag.new
14       tt.tag = tag
15       tt
16     }
17   end
18   
19   def large_picture= (data)
20     f = File.new(large_picture_name, "wb")
21     f.syswrite(data)
22     f.close
23   end
24   
25   def icon_picture= (data)
26     f = File.new(icon_picture_name, "wb")
27     f.syswrite(data)
28     f.close
29   end
30
31   def large_picture
32     f = File.new(large_picture_name, "rb")
33     logger.info "large picture file: '#{f.path}', bytes: #{File.size(f.path)}"
34     data = f.sysread(File.size(f.path))
35     logger.info "have read data, bytes: '#{data.length}'"
36     f.close
37     data
38   end
39   
40   def icon_picture
41     f = File.new(icon_picture_name, "rb")
42     logger.info "icon picture file: '#{f.path}'"
43     data = f.sysread(File.size(f.path))
44     f.close
45     data
46   end
47   
48   # FIXME change to permanent filestore area
49   def large_picture_name
50     "/tmp/#{id}.gif"
51   end
52
53   # FIXME change to permanent filestore area
54   def icon_picture_name
55     "/tmp/#{id}_icon.gif"
56   end
57
58   def to_xml_node
59     el1 = XML::Node.new 'gpx_file'
60     el1['id'] = self.id.to_s
61     el1['name'] = self.name.to_s
62     el1['lat'] = self.latitude.to_s
63     el1['lon'] = self.longitude.to_s
64     el1['user'] = self.user.display_name
65     el1['public'] = self.public.to_s
66     el1['pending'] = (!self.inserted).to_s
67     el1['timestamp'] = self.timestamp.xmlschema
68     return el1
69   end
70 end