X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fmodels%2Foriginal_picture.rb;h=33de4f204e487f54e73d9cbb5dbcad0e9744906c;hb=942917e0411a283c3a6ffb151c91053731f7bff7;hp=2866687f444947040a1bbc9605135a5f80442565;hpb=99b1f1d1b08c214e954f1e6970bb5ec4800aaa19;p=pettanr%2Fpettanr.git diff --git a/app/models/original_picture.rb b/app/models/original_picture.rb index 2866687f..33de4f20 100644 --- a/app/models/original_picture.rb +++ b/app/models/original_picture.rb @@ -56,6 +56,22 @@ class OriginalPicture < ActiveRecord::Base {:src => self.url, :width => tw, :height => th} end + def unpublished? + self.pictures.empty? + end + + def stopped? + self.pictures.any? and self.resource_picture == nil + end + + def unlicensed? + self.pictures.any? and self.resource_picture and self.updated_at > self.pictures.first.head.updated_at + end + + def published? + self.pictures.any? and self.resource_picture and self.updated_at < self.pictures.first.head.updated_at + end + def self.default_page_size 25 end @@ -128,17 +144,18 @@ class OriginalPicture < ActiveRecord::Base def store(imager) unless imager - self.errors.add :base, 'illegal picture data' + self.errors.add :base, I18n.t('errors.invalid_image') return false end res = false self.attributes = {:ext => imager.ext, :width => imager.width, :height => imager.height, :filesize => imager.filesize, :md5 => imager.md5} OriginalPicture.transaction do if res = self.save - if res = PictureIO.original_picture_io.put(imager.binary, self.filename) - res = true - else - self.errors.add :base, 'original picture io does not work' + begin + res = PictureIO.original_picture_io.put(imager.binary, self.filename) + rescue PictureIO::Error + res = false + self.errors.add :base, I18n.t('picture_io.error') raise ActiveRecord::Rollback end end