X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Fpicture.rb;h=24bf392bccd39f8d20b5808a8be4e2aff5d9d87f;hb=467daaf74bbf62a7ad43d7af7fd6326bfacd9010;hp=c408bab686206e8647243aacfe3228d502022567;hpb=aa75d8fb5985a21652c5c9d191dc915a6ce784e4;p=pettanr%2Fpettanr.git diff --git a/app/models/picture.rb b/app/models/picture.rb index c408bab6..24bf392b 100644 --- a/app/models/picture.rb +++ b/app/models/picture.rb @@ -3,6 +3,7 @@ class Picture < Peta::Content load_manifest belongs_to :original_picture belongs_to :license + belongs_to :system_picture belongs_to :artist has_one :resource_picture @@ -14,17 +15,22 @@ class Picture < Peta::Content 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 :license_id, :presence => true, :numericality => true, :existence => {:both => false} + validates :system_picture_id, :presence => true, :numericality => true, :existence => {:both => false} validates :artist_id, :presence => true, :numericality => true, :existence => {:both => false} - validates :artist_name, :presence => true - validates :classname, :presence => true, :length => {:maximum => 50} + validates :license_group_module_name, :presence => true, :length => {:maximum => 50} def supply_default end def overwrite rp attr = {:width => rp.width, :height => rp.height, :ext => rp.ext, :filesize => rp.filesize, - :original_picture_id => rp.original_picture_id, :license_id => rp.license_id, :artist_id => rp.artist_id, - :md5 => rp.md5, :artist_name => rp.artist_name, :classname => rp.classname, :credit => rp.credit, :settings => rp.settings + :original_picture_id => rp.original_picture_id, :license_id => rp.license_id, + :system_picture_id => rp.system_picture_id, :artist_id => rp.artist_id, + :md5 => rp.md5, + :license_group_module_name => rp.license_group_module_name, + :license_group_settings => rp.license_group_settings, + :credit_picture_settings => rp.credit_picture_settings, + :license_settings => rp.license_settings } self.attributes = attr self.revision = self.new_revision #Do not move to attr. new_revision reffernces self.original_picture_id @@ -74,6 +80,10 @@ class Picture < Peta::Content {:src => img, :width => tw, :height => th} end + def alt_name + self.license.license_group.caption.to_s + '[' + self.license.caption.to_s + ']' + end + def symbol_option self.tmb_opt_img_tag end @@ -100,11 +110,11 @@ class Picture < Peta::Content end def to_gif? - self.ext == 'png' and self.flag_gif_convert >= 0 + self.ext == 'png' and self.license_extend.gif_convert >= 0 end def subdirs - flag_reverse < 0 ? [''] : ['', 'v', 'h', 'vh'] + self.license_extend.reverse < 0 ? [''] : ['', 'v', 'h', 'vh'] end def self.find_by_md5 md5 @@ -201,88 +211,11 @@ class Picture < Peta::Content end def credit_template - "#{self.classname.tableize}/attributes/credit" + "#{self.license_group_module_name.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 - rescue - end - @credit_data - end - - def flags - return @flags if @flags - begin - @flags = JSON.parse(self.settings) - rescue - end - @flags = {} unless @flags - @flags - end - - def flags=(s) - @flags = s - end - - def flag_open - @flag_open = (flags["open"] || -1) unless @flag_open - @flag_open - end - - def flag_commercial - @flag_commercial = (flags["commercial"] || -1) unless @flag_commercial - @flag_commercial - end - - def flag_official - @flag_official = (flags["official"] || -1) unless @flag_official - @flag_official - end - - def flag_attribution - @flag_attribution = (flags["attribution"] || -1) unless @flag_attribution - @flag_attribution - end - - def flag_derive - @flag_derive = (flags["derive"] || -1) unless @flag_derive - @flag_derive - end - - def flag_thumbnail - @flag_thumbnail = (flags["thumbnail"] || -1) unless @flag_thumbnail - @flag_thumbnail - end - - def flag_gif_convert - @flag_gif_convert = (flags["gif_convert"] || -1) unless @flag_gif_convert - @flag_gif_convert - end - - def flag_reverse - @flag_reverse = (flags["reverse"] || -1) unless @flag_reverse - @flag_reverse - end - - def flag_resize - @flag_resize = (flags["resize"] || -1) unless @flag_resize - @flag_resize - end - - def flag_sync_vh - @flag_sync_vh = (flags["sync_vh"] || -1) unless @flag_sync_vh - @flag_sync_vh - end - - def flag_overlap - @flag_overlap = (flags["overlap"] || -1) unless @flag_overlap - @flag_overlap + "#{self.license_group_module_name.tableize}/attributes/full_credit" end end