X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=app%2Fmodels%2Foriginal_picture.rb;h=19c993d21f8c9e384b9ebdf1f47f9ab1ffbc9ce9;hp=96740f904b58f9a70598977a356dfaad948f9fe5;hb=d06c85598de5091129d22bfdcc650fae261a6219;hpb=7da6c008e9358396e0bc696e6ee47e4b5e8488f6 diff --git a/app/models/original_picture.rb b/app/models/original_picture.rb index 96740f90..19c993d2 100644 --- a/app/models/original_picture.rb +++ b/app/models/original_picture.rb @@ -1,6 +1,5 @@ class OriginalPicture < ActiveRecord::Base belongs_to :artist - belongs_to :license has_one :resource_picture validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']} @@ -8,12 +7,10 @@ class OriginalPicture < ActiveRecord::Base 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 :artist_id, :presence => true, :numericality => true, :existence => true - validates :license_id, :presence => true, :numericality => true, :existence => true before_destroy :destroy_with_file def supply_default art - self.license_id = art.default_license_id if self.license_id.blank? end def self.default_page_size @@ -46,11 +43,11 @@ class OriginalPicture < ActiveRecord::Base end def self.list_opt - {:include => [:license, :resource_picture]} + {:include => {:resource_picture => {}}} end def self.list_json_opt - {:include => [:license, :resource_picture]} + {:include => {:resource_picture => {}}} end def self.show cid, artist, opt = {} @@ -66,13 +63,13 @@ class OriginalPicture < ActiveRecord::Base end def self.show_include_opt opt = {} - res = [:license, :resource_picture] - res.push(opt[:include]) if opt[:include] + res = {:resource_picture => {}} + res.merge!(opt[:include]) if opt[:include] res end def self.show_json_include_opt - {:include => [:license, :resource_picture]} + {:include => {:resource_picture => {}}} end def destroy_with_file @@ -106,24 +103,16 @@ class OriginalPicture < ActiveRecord::Base mgk end - def store(picture_data, art, lid = nil) + def store(picture_data, art) mgk = data_to_mgk picture_data return false unless mgk res = false self.attributes = {:ext => mgk.format.downcase, :width => mgk.columns, :height => mgk.rows, - :filesize => mgk.filesize, :artist_id => art.id, - :license_id => lid.blank? ? art.default_license_id : lid.to_i + :filesize => mgk.filesize, :artist_id => art.id } OriginalPicture.transaction do if res = self.save if res = PictureIO.original_picture_io.put(picture_data, self.filename) - rp = ResourcePicture.update_picture(self) - unless rp.store(mgk) - res = false - PictureIO.original_picture_io.delete(self.filename) - self.errors.add :base, 'resource picture copying error' - raise ActiveRecord::Rollback - end res = true else self.errors.add :base, 'original picture io does not work'