debshots/app/models/screenshot.rb
2015-04-19 11:33:41 +02:00

56 lines
1.7 KiB
Ruby

class Screenshot < ActiveRecord::Base
belongs_to :package, :inverse_of=>:screenshots
default_scope {
order('uploaddatetime DESC')
}
has_attached_file :image,
styles: { :large => '800x600>', :thumb => '160x120>' },
default_url: '/images/dummy/no-screenshots-upload-one.svg',
#path: ':rails_root/public/system/:class/:attachment/:id_partition/:style/:filename',
path: ':rails_root/public/screenshots/:id_partition/:style.png',
url: '/screenshots/:id_partition/:style.png',
# TODO: Make hash_secret configurable in the main configuration.
# Do not check it into Git.
hash_secret: 'M4xGM9v6y17Y27sZ1liWrnQaXdX4YDdZCJ7fOqcAUg3cZJqK9x'
validates_attachment_content_type :image, :content_type => /\Aimage\/png\Z/
# Return caption for full-screen screenshots.
# Takes the description of a screenshot if available.
# Otherwise it falls back to the general description of its package.
def caption
if self.description != ''
self.description
else
self.package.description
end
end
def uploader
# TODO: Implement the ownership of images
'Anonymous'
end
# Return Debshots 1.x path to allow migration of images into Paperclip filesystem schema
def image_url(size)
'#{Rails.configuration.images_path_prefix}/#{self.package.name[0]}/#{self.package.name}/#{self.id}_#{size}.png'
end
def status
text = ''
# Completes the sentence: 'This image...'
if self.approved
text << 'is public'
else
text << 'has to be moderated before being publicly visible'
end
if self.markedfordelete
text << ' (and was requested to be removed)'
end
return text
end
end