Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change date #57

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/controllers/jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,15 @@ def unwatch
flash[:notice] = 'Job is now unwatched. You can find a list of your watched jobs on the dashboard.'
redirect_to :back
end

def close_jobs
jobs = Job.where('latest_start_date < ?', Time.now)


jobs.each do |job|
job.update_attribute(:status, 1)
job.save(validate: false)
end
end

protected

Expand Down
17 changes: 15 additions & 2 deletions app/models/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ def self.human_attribute_name(attr, options = {})
end
return super
end

def self.close_jobs
jobs = Job.where('latest_start_date < ?', Time.now)

jobs.each do |job|
job.update_attribute(:status, 1)
job.save(validate: false)
end
end

# Returns a string containing the category names taken by this Job
# e.g. "robotics,signal processing"
Expand Down Expand Up @@ -434,15 +443,19 @@ def resend_email(send_email = false)
end
end



protected

#delete this?
def earliest_start_date_must_be_before_latest
errors[:earliest_start_date] << "cannot be later than the latest start date" if
errors[:start_date] << "cannot be later than the latest start date" if
latest_start_date.present? && earliest_start_date.present? && earliest_start_date > latest_start_date

end

def latest_start_date_must_be_before_end_date
errors.add(:latest_start_date, "cannot be later than the end date") if
errors.add(:apply_by_date, "cannot be later than the end date") if
latest_start_date.present? && !open_ended_end_date &&
latest_start_date > end_date
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/jobs/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
%dd
= text_field :proglang, :name, :value => @job.proglang_list_of_job(true), :class => 'form-control', :id => 'proglangs-input', :placeholder => "(e.g. Python, machine shop)"
%dt
= f.label :earliest_start_date, 'Earliest start date *'
= f.label :earliest_start_date, 'Start date *'
%dd
= f.text_field :earliest_start_date, :class => 'datepicker form-control', value: @job.earliest_start_date.present? ? @job.earliest_start_date.strftime("%Y-%m-%d") : nil
%dt
= f.label :latest_start_date, 'Latest start date *'
= f.label :latest_start_date, 'Application Deadline*'
%dd
= f.text_field :latest_start_date, :class => 'datepicker form-control', value: @job.latest_start_date.present? ? @job.latest_start_date.strftime("%Y-%m-%d") : nil
%dt
Expand Down
4 changes: 2 additions & 2 deletions app/views/jobs/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@
= h @job.proglang_list_of_job(true)
- else
(none)
%dt Earliest start date
%dt Start date
%dd
= @job.earliest_start_date.strftime("%b %e, %Y")
%dt Latest start date
%dt Application Deadline
%dd
= @job.latest_start_date.strftime("%b %e, %Y")
%dt Position end date
Expand Down
4 changes: 4 additions & 0 deletions lib/tasks/scheduler.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
desc "This task is called by the Heroku scheduler add-on"
task :close_jobs => :environment do
Jobs.close_jobs
end