-class OriginalPicture < Pettanr::Content
+class OriginalPicture < Peta::Content
+ load_manifest
belongs_to :artist
belongs_to :original_picture_license_group
has_one :resource_picture
has_many :pictures
+ has_many :resource_picture_pictures
validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
validates :width, :presence => true, :numericality => true, :natural_number => true
validates :artist_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
- def self.owner_type
- :artist
- end
-
def supply_default
+ self.artist_id = nil
end
def overwrite operators
self.tmb_opt_img_tag
end
+ def filer_caption
+ self.revision
+ end
+
def revision
head = self.history.first
head ? head.revision : 'unpublished'
self.published_at != nil
end
- def self.list_order
- 'original_pictures.updated_at desc'
- end
-
- def self.list_opt
- {:resource_picture => {}, :pictures => {} }
- end
-
- def self.list_json_opt
- {:include => {:resource_picture => {}, :pictures => {}}}
- end
-
def history
Picture.find(:all, {:conditions => ['pictures.original_picture_id = ?', self.id], :order => 'pictures.revision desc'} )
end
{:include => {:resource_picture => {}, :pictures => {}}}
end
- def self.show_json_opt
- {:include => {:resource_picture => {}, :pictures => {}}}
- end
-
def store(imager)
unless imager
self.errors.add :base, I18n.t('errors.invalid_image')
self.pictures.each do |picture|
res = picture.unpublish
raise ActiveRecord::Rollback unless res
+ if picture.resource_picture_picture
+ picture.resource_picture_picture.original_picture_id = nil
+ picture.resource_picture_picture.resource_picture_id = nil
+ raise ActiveRecord::Rollback unless picture.resource_picture_picture.save
+ end
end
res = self.destroy
raise ActiveRecord::Rollback unless res
lg = l.license_group
attr[:license_id] = l.id
- ctl = lg.classname.pluralize + '::Attribute'
+ ctl = lg.module_name.pluralize + '::Attribute'
le = ctl.constantize.new attr
rp = ResourcePicture.new