OSDN Git Service

t#30138:create original pictures status
[pettanr/pettanr.git] / app / models / original_picture.rb
index 2866687..33de4f2 100644 (file)
@@ -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