hound fixes

This commit is contained in:
Stella Rouzi 2014-06-26 15:43:24 +03:00
parent e8990bfb12
commit fc753282d3
14 changed files with 180 additions and 144 deletions

View file

@ -114,7 +114,7 @@ class Conference < ActiveRecord::Base
def user_registered? user
return nil if user.nil?
if self.registrations.where(user_id: user.id).count == 0
if registrations.where(user_id: user.id).count == 0
logger.debug("User #{user.email} isn't registered to self.title")
return false
else

View file

@ -4,7 +4,7 @@ class DatatableSupporters < Datatable
items.each do |i|
item = []
if i.name.blank?
if !i.registration.nil? && !i.registration.user.nil?
unless i.registration.nil? || i.registration.user.nil?
item << i.registration.user.name
else
item << "Unknown"
@ -15,7 +15,7 @@ class DatatableSupporters < Datatable
end
if i.email.blank?
if !i.registration.nil? && !i.registration.user.nil?
unless i.registration.nil? && i.registration.user.nil?
item << i.registration.user.email
else
item << "Unknown"

View file

@ -7,46 +7,48 @@ class EmailSettings < ActiveRecord::Base
def get_values(conference, user, event = nil)
h = {
'email' => user.email,
'name' => user.name,
'conference' => conference.title,
'registrationlink' => Rails.application.routes.url_helpers.register_conference_url(conference.short_title, host: CONFIG['url_for_emails'])
'email' => user.email,
'name' => user.name,
'conference' => conference.title,
'registrationlink' => Rails.application.routes.url_helpers.register_conference_url(
conference.short_title, host: CONFIG['url_for_emails'])
}
if !event.nil?
h['eventtitle'] = event.title
h['proposalslink'] = Rails.application.routes.url_helpers.conference_proposal_url(conference.short_title, event, host: CONFIG['url_for_emails'])
h['proposalslink'] = Rails.application.routes.url_helpers.conference_proposal_url(
conference.short_title, event, host: CONFIG['url_for_emails'])
end
h
end
def generate_registration_email(conference, user)
values = get_values(conference, user)
template = self.registration_email_template
template = registration_email_template
parse_template(template, values)
end
def generate_accepted_email(event)
values = get_values(event.conference, event.submitter, event)
template = self.accepted_email_template
template = accepted_email_template
parse_template(template, values)
end
def generate_rejected_email(event)
values = get_values(event.conference, event.submitter, event)
template = self.rejected_email_template
template = rejected_email_template
parse_template(template, values)
end
def confirmed_but_not_registered_email(event)
values = get_values(event.conference, event.submitter, event)
template = self.confirmed_email_template
template = confirmed_email_template
parse_template(template, values)
end
def parse_template(text, values)
values.each do |key, value|
text = text.gsub"{#{key}}", value unless text.blank?
text = text.gsub "{#{key}}", value unless text.blank?
end
text
end

View file

@ -71,23 +71,23 @@ class Event < ActiveRecord::Base
def average_rating
@total_rating = 0
self.votes.each do |vote|
votes.each do |vote|
@total_rating = @total_rating + vote.rating
end
@total = self.votes.size
@total = votes.size
number_with_precision(@total_rating / @total.to_f, precision: 2, strip_insignificant_zeros: true)
end
def submitter
result = self.event_users.where(event_role: 'submitter').first
result = event_users.where(event_role: 'submitter').first
if !result.nil?
result.user
else
user = nil
# Perhaps the event_users haven't been saved, if this is a new proposal
self.event_users.each do |p|
if p.event_role == 'submitter'
user = p.user
event_users.each do |u|
if u.event_role == 'submitter'
user = u.user
end
end
user
@ -97,34 +97,34 @@ class Event < ActiveRecord::Base
def as_json(options)
json = super(options)
if self.room.nil?
if room.nil?
json[:room_guid] = nil
else
json[:room_guid] = self.room.guid
json[:room_guid] = room.guid
end
if self.track.nil?
if track.nil?
json[:track_color] = '#ffffff'
else
json[:track_color] = self.track.color;
json[:track_color] = track.color
end
if self.event_type.nil?
if event_type.nil?
json[:length] = 25
else
json[:length] = self.event_type.length
json[:length] = event_type.length
end
json
end
def transition_possible?(transition)
self.class.state_machine.events_for(self.current_state).include?(transition)
self.class.state_machine.events_for(current_state).include?(transition)
end
def process_confirmation
if self.conference.email_settings.send_on_confirmed_without_registration?
if self.conference.registrations.where(:user_id => self.submitter.id).first.nil?
if conference.email_settings.send_on_confirmed_without_registration?
if conference.registrations.where(user_id: submitter.id).first.nil?
Mailbot.confirm_reminder_mail(self).deliver
end
end
@ -147,10 +147,10 @@ class Event < ActiveRecord::Base
end
def abstract_word_count
if self.abstract.nil?
if abstract.nil?
0
else
self.abstract.split.size
abstract.split.size
end
end
@ -181,23 +181,19 @@ class Event < ActiveRecord::Base
private
def abstract_limit
len = self.abstract.split.size
max = self.event_type.maximum_abstract_length
min = self.event_type.minimum_abstract_length
len = abstract.split.size
max = event_type.maximum_abstract_length
min = event_type.minimum_abstract_length
if len < min
errors.add(:abstract, "cannot have less than #{min} words")
end
if len > max
errors.add(:abstract, "cannot have more than #{max} words")
end
errors.add(:abstract, "cannot have more than #{max} words") if len > max
end
def biography_exists
if self.submitter.biography_word_count == 0
errors.add(:user_biography, 'must be filled out')
end
errors.add(:user_biography, 'must be filled out') if submitter.biography_word_count == 0
end
def generate_guid

View file

@ -2,7 +2,6 @@ class User < ActiveRecord::Base
include Gravtastic
gravtastic size: 32
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
@ -54,7 +53,7 @@ class User < ActiveRecord::Base
end
def get_roles
return self.roles
roles
end
def setup_role
@ -86,7 +85,7 @@ class User < ActiveRecord::Base
end
def attended
registrations_attended = self.registrations.where(attended: true)
registrations_attended = registrations.where(attended: true)
if registrations_attended.count == 0
'None'
else
@ -98,32 +97,31 @@ class User < ActiveRecord::Base
!confirmed_at.nil?
end
def attending_conference? conference
def attending_conference?(conference)
Registration.where(conference_id: conference.id,
user_id: self.id).count
user_id: id).count
end
def proposals conference
def proposals(conference)
events.where('conference_id = ? AND event_users.event_role=?', conference.id, 'submitter')
end
def proposal_count conference
def proposal_count(conference)
proposals(conference).count
end
def biography_word_count
if self.biography.nil?
if biography.nil?
0
else
self.biography.split.size
biography.split.size
end
end
private
def biography_limit
if !self.biography.nil? && self.biography.split.size > 150
errors.add(:abstract, 'cannot have more than 150 words')
end
errors.add(:abstract, 'cannot have more than 150 words') if !biography.nil? &&
biography.split.size > 150
end
end