Merge branch 'master' into crawler

This commit is contained in:
Andreas Stephanides
2015-04-17 11:07:30 +02:00
41 changed files with 479 additions and 130 deletions

View File

@@ -12,11 +12,13 @@
class Attachment < ActiveRecord::Base
has_paper_trail
attr_accessible :name, :datei, :datei_cache,:flag_titlepic
attr_accessible :name, :datei, :datei_cache,:flag_titlepic,:parent_id, :parent_type
belongs_to :thema
mount_uploader :datei, AttachmentUploader
validates :thema, :presence => true
# validates :thema, :presence => true
validates :name, :presence => true
scope :titlepic, ->{where(flag_titlepic: true)}
default_scope order("LOWER(name)")
belongs_to :parent, :polymorphic=>true
def image?
@@ -24,6 +26,9 @@ class Attachment < ActiveRecord::Base
# %w(jpg png jpeg).include?(data_ext)
datei.image?(datei.file)
end
def self.parent_attachment_list_id(parent)
"attachments_for_"+parent.class.to_s+"_"+parent.id.to_s
end
def to_jq_upload
{

View File

@@ -9,6 +9,7 @@ class Document < ActiveRecord::Base
validate :parent, :presence=>true
has_paper_trail
TYPS = { 1=>"fet_docs", 10=>"protocol", 11=> "agenda"}
has_many :attachments, :as=>:parent
def long_name
if self.parent.class=="Meeting"
"<b>"+self.parent.text+ "</b>"+ self.name

View File

@@ -15,6 +15,7 @@ class Foto < ActiveRecord::Base
attr_accessible :datei, :desc, :gallery_id, :title
belongs_to :gallery
mount_uploader :datei, FotoUploader
before_save :parse_exif
resourcify
def to_jq_upload
{
@@ -28,4 +29,11 @@ class Foto < ActiveRecord::Base
"delete_type" => "DELETE"
}
end
def parse_exif
unless self.exif.nil? || self.exif.empty?
j=JSON.parse(self.exif)
datetime = j.select {|i| i.first == "DateTime"}.try(:first).try(:last)
self.taken_at=Time.new(datetime) unless datetime.nil?
end
end
end

View File

@@ -31,7 +31,7 @@ class Meeting < ActiveRecord::Base
end
t= t+ self.name.to_s
# t = t + " " + I18n.l(self.calentry.start) unless self.calentry.nil?
t = t +" am "+ self.calentry.text unless self.calentry.nil?
t = t +" "+ I18n.t("date.am")+" "+ self.calentry.text unless self.calentry.nil?
t
end
def create_announcement(user)

View File

@@ -20,6 +20,9 @@ class Neuigkeit < ActiveRecord::Base
has_many :calentries, as: :object
has_many :nlinks
has_one :meeting
has_many :attachments, :as=>:parent
validates :rubrik, :presence=>true
validates :author, :presence=>true
@@ -46,7 +49,11 @@ class Neuigkeit < ActiveRecord::Base
if self.has_meeting?
return self.meeting.meetingtyp.picture
else
return self.picture
unless self.attachments.where(flag_titlepic: true).first.nil?
return self.attachments.where(flag_titlepic: true).first.datei
else
return self.picture
end
end
end
end
@@ -108,16 +115,16 @@ class Neuigkeit < ActiveRecord::Base
self.has_calentries?
end
def relevant_calentry
self.calentries.min_by{|c| c.days_to_today * 2 * ((c.is_past?)? 2:1)}
self.calentries.min_by{|c| c.days_to_today * 1.3 * ((c.is_past?)? 2:1)}
end
def update_cache
if self.has_meeting? && !self.meeting.calentry.nil?
self.update_column(:cache_order, (self.meeting.calentry.start.to_date - Date.today).to_i.abs * 2)
self.update_column(:cache_order, (self.meeting.calentry.start.to_date - Date.today).to_i.abs * 1.3)
self.update_column(:cache_relevant_date, self.meeting.calentry.start.to_date)
else
if self.is_event?
c = self.calentries.min_by{|c| c.days_to_today * 2 * ((c.is_past?)? 2:1)}
self.update_column(:cache_order, c.days_to_today * 2 * ((c.is_past?)? 2:1))
c = self.calentries.min_by{|c| c.days_to_today * 1.3 * ((c.is_past?)? 2:1)}
self.update_column(:cache_order, c.days_to_today * 1.3 * ((c.is_past?)? 2:1))
self.update_column(:cache_relevant_date, (c.is_past?) ? c.ende.to_date : c.start.to_date)
else
unless self.datum.nil?

View File

@@ -33,7 +33,7 @@ class Studium < ActiveRecord::Base
has_many :moduls, :through=>:modulgruppen
has_many :lvas, :through=>:moduls
has_many :semester, :dependent => :destroy
has_many :attachments, :as=>:parent
validates :abkuerzung, :length=>{:maximum=>5}, :format=>{:with=>/^[a-zA-z]{0,5}$/}
validates :typ, :inclusion => {:in => ["Bachelor","Master"] }
validates :name, :uniqueness => true, :presence=>true

View File

@@ -22,7 +22,7 @@ class Thema < ActiveRecord::Base
# Each topic has multiple questions, that are also referenced in the FAQ.
has_many :fragen
# Attachments can be all data formats
has_many :attachments
has_many :attachments, :as=>:parent
# attached pics can be used as title pictures
has_many :titlepics, :as=>:parent, :class_name=>'Attachment', :conditions=>{:flag_titlepic=>true}
# each topic has to belong to one group