1 class License < ActiveRecord::Base
2 belongs_to :license_group
3 belongs_to :system_picture
5 validates :license_group_id, :presence => true, :numericality => true, :existence => true
6 validates :name, :presence => true, :length => {:maximum => 50}
7 validates :caption, :presence => true, :length => {:maximum => 30}
8 validates :url, :presence => true, :length => {:maximum => 200}, :uniqueness => true, :url => true #{:allow_blank => true}
9 validates :system_picture_id, :presence => true, :numericality => true, :existence => true
11 def self.update_license cl
12 l = License.find_by_url cl.url
13 l = License.new unless l
15 :name => cl.name, :url => cl.url, :cc_by => cl.cc_by, :cc_sa => cl.cc_sa, :cc_nd => cl.cc_nd, :cc_nc => cl.cc_nc,
16 :no_resize => cl.no_resize, :no_flip => cl.no_flip, :no_convert => cl.no_convert, :keep_aspect_ratio => cl.keep_aspect_ratio
18 if cl.new_record? and l.new_record? == false
19 l.errors.add :base, 'dupulicate url'
24 def self.list lg_id, opt = {}
25 opt.merge!(self.list_opt) unless opt[:include]
26 opt.merge!({:conditions => ['licenses.license_group_id = ?', lg_id], :order => 'name'})
27 License.find(:all, opt)
31 {:include => {:license_group => {}}}
34 def self.list_json_opt
35 {:include => {:license_group => {}}}
38 def self.show rid, opt = {}
39 r = License.find(rid, :include => self.show_include_opt(opt))
40 # raise ActiveRecord::Forbidden unless c.visible?(au)
44 def self.show_include_opt opt = {}
45 res = [:license_group]
46 res.push(opt[:include]) if opt[:include]
50 def self.show_json_include_opt
51 {:include => {:license_group => {}}}