validates :height, :presence => true, :numericality => true, :natural_number => true
validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
- validates :artist_id, :presence => true, :numericality => true, :existence => true
- validates :license_id, :presence => true, :numericality => true, :existence => true
- validates :original_picture_id, :presence => true, :numericality => true, :existence => true
+ validates :artist_id, :presence => true, :numericality => true, :existence => {:both => false}
+ validates :license_id, :presence => true, :numericality => true, :existence => {:both => false}
+ validates :original_picture_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :artist_name, :presence => true
validates :classname, :presence => true, :length => {:maximum => 50}
- validates :picture_id, :presence => true, :numericality => true, :existence => true
-
- before_destroy :destroy_with_file
-
- def destroy_with_file
- PictureIO.resource_picture_io.delete self.filename
- PictureIO.resource_picture_io.class.subdirs.each do |d|
- next if d.empty?
- PictureIO.resource_picture_io.delete(self.filename, d) if PictureIO.resource_picture_io.exist?(self.filename, d)
- end
- end
+ validates :picture_id, :presence => true, :numericality => true, :existence => {:both => false}
def supply_default
end
self.attributes = attr
end
- def own? author
- return false
+ def own? ar
+ return false unless ar.is_a?(Artist)
+ ar.id == self.artist_id
end
- def visible? author
+ def visible? au
+ if au == nil
+ return false if MagicNumber['run_mode'] == 1
+ elsif au.is_a?(Author)
+ return true
+ else
+ return false
+ end
true
end
ResourcePicture.resize(rimg.to_blob, tw, th).to_blob
end
- def opt_img_tag
+ def tmb_opt_img_tag
tw, th = PettanImager.thumbnail_size(self.width, self.height)
{:src => self.url, :width => tw, :height => th}
end
+ def opt_img_tag
+ {:src => self.url('full'), :width => self.width, :height => self.height}
+ end
+
def self.default_page_size
25
end
{:include => {:license => {}, :artist => {}, :picture => {}} }
end
+ def self.edit rid, ar
+ opt = {}
+ opt.merge!(self.show_opt)
+ r = ResourcePicture.find(rid, opt)
+ raise ActiveRecord::Forbidden unless r.own?(ar)
+ r
+ end
+
def new_picture imager
pc = Picture.new
pc.supply_default
PictureIO.resource_picture_io.get self.filename, subdir
end
+ def unpublish
+ r = true
+ ResourcePicture.transaction do
+ self.destroy
+ PictureIO.resource_picture_io.delete(self.filename)
+ PictureIO.resource_picture_io.delete(self.filename, 'full')
+ end
+ r
+ end
+
def self.visible_count
ResourcePicture.count
end
"#{self.classname.tableize}/attributes/credit"
end
+ def full_credit_template
+ "#{self.classname.tableize}/attributes/full_credit"
+ end
+
def credit_data
begin
@credit_data = JSON.parse(self.credit) unless @credit_data