fix error
This commit is contained in:
parent
3381ce7190
commit
5e7df7753a
|
@ -85,7 +85,8 @@ class Bulletin
|
|||
before_destroy :destroy_email
|
||||
|
||||
scope :open_in_future, ->{where(:is_hidden.ne=>true,:is_preview.ne => true,:postdate.gt=>Time.now).order(postdate: :asc)}
|
||||
scope :can_display_and_sorted, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil},{:postdate=>nil,:deadline.gte=>Time.now},{:postdate=>nil,:deadline=>nil}).order(is_top: :desc,postdate: :desc,id: :desc)}
|
||||
scope :can_display_and_sorted, ->{where(:approved => true,:is_hidden.ne=>true,:is_preview.ne => true).valid_time_range}
|
||||
scope :valid_time_range, ->{any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil},{:postdate=>nil,:deadline.gte=>Time.now},{:postdate=>nil,:deadline=>nil}).order(is_top: :desc,postdate: :desc,id: :desc)}
|
||||
scope :is_approved, ->{where(:approved => true)}
|
||||
scope :is_approved_and_show, ->{where(:approved => true,:is_hidden.ne=>true,:is_preview.ne => true)}
|
||||
scope :filter_cats_and_tags, ->(cats,tags) {filter_by_widget_categories(cats,false).filter_by_tags(tags)}
|
||||
|
@ -93,7 +94,7 @@ class Bulletin
|
|||
before_save :check_limit
|
||||
index({postdate: 1}, { unique: false, background: true })
|
||||
index({is_top: -1,postdate: -1, _id: -1}, { unique: false, background: true })
|
||||
index({is_hidden: 1,is_preview: 1, is_top: -1,postdate: -1,_id: -1,deadline: -1}, { unique: false, background: true })
|
||||
index({approved: -1,is_hidden: 1,is_preview: 1, is_top: -1,postdate: -1,_id: -1,deadline: -1}, { unique: false, background: true })
|
||||
def get_org_model
|
||||
if self.is_preview
|
||||
org_model = nil
|
||||
|
|
|
@ -59,7 +59,8 @@ class BulletinFeed
|
|||
tags = bf.tag_ids
|
||||
categories = bf.category_ids
|
||||
if !(categories.empty? && tags.empty?)
|
||||
anns_before_filter = Bulletin.any_of(I18n.available_locales.map{|v| {"title.#{v}"=>{"$nin"=>["", nil]}}}).is_approved_and_show
|
||||
anns_before_filter = Bulletin.is_approved_and_show
|
||||
can_display_and_sorted_flag = false
|
||||
if !dt.nil?
|
||||
dt = DateTime.parse(dt)
|
||||
dtt = dt + 1.day
|
||||
|
@ -72,15 +73,20 @@ class BulletinFeed
|
|||
startdt = DateTime.parse(startdt)
|
||||
enddt = DateTime.parse(enddt) + 1.day
|
||||
anns_before_filter = anns_before_filter.where(:postdate.gt => startdt, :postdate.lt => enddt)
|
||||
else
|
||||
can_display_and_sorted_flag = true
|
||||
end
|
||||
anns_before_filter = anns_before_filter.can_display_and_sorted
|
||||
|
||||
if !tags.empty?
|
||||
anns_before_filter = anns_before_filter.filter_by_tags(tags)
|
||||
end
|
||||
if !categories.empty?
|
||||
anns_before_filter = anns_before_filter.filter_by_categories(categories)
|
||||
end
|
||||
announcements = anns_before_filter.can_display_and_sorted
|
||||
anns_before_filter.selector = {"$and"=>[anns_before_filter.selector,{"$or"=>(I18n.available_locales.map{|v| {"title.#{v}"=>{"$nin"=>["", nil]}}})}]}
|
||||
if can_display_and_sorted_flag
|
||||
announcements = anns_before_filter.valid_time_range
|
||||
end
|
||||
else
|
||||
announcements = []
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ class BulletinFeedCache
|
|||
et = self.end
|
||||
dt = self.date
|
||||
uid = self.uid
|
||||
BulletinFeed.where(uid: uid).first.generate_one_cache(startdt: st,enddt: et,dt: dt) rescue nil
|
||||
BulletinFeed.where(uid: uid).each{|v| v.generate_one_cache(startdt: st,enddt: et,dt: dt)} rescue nil
|
||||
self.destroy
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue