[IMP] website_hr_recruitment: new API
This commit is contained in:
parent
fcfa5a56ef
commit
3f8fd0dad6
|
@ -114,7 +114,7 @@ def slugify(s, max_length=None):
|
|||
def slug(value):
|
||||
if isinstance(value, orm.browse_record):
|
||||
# [(id, name)] = value.name_get()
|
||||
id, name = value.id, value[value._rec_name]
|
||||
id, name = value.id, value.display_name
|
||||
else:
|
||||
# assume name_search result tuple
|
||||
id, name = value
|
||||
|
|
|
@ -6,6 +6,8 @@ from openerp import http
|
|||
from openerp.tools.translate import _
|
||||
from openerp.http import request
|
||||
|
||||
from openerp.addons.website.models.website import slug
|
||||
|
||||
class website_hr_recruitment(http.Controller):
|
||||
@http.route([
|
||||
'/jobs',
|
||||
|
@ -16,19 +18,17 @@ class website_hr_recruitment(http.Controller):
|
|||
'/jobs/country/<model("res.country"):country>/office/<int:office_id>',
|
||||
'/jobs/department/<model("hr.department"):department>/office/<int:office_id>',
|
||||
'/jobs/country/<model("res.country"):country>/department/<model("hr.department"):department>/office/<int:office_id>',
|
||||
], type='http', auth="public", website=True)
|
||||
], type='http', auth="public", website=True)
|
||||
def jobs(self, country=None, department=None, office_id=None):
|
||||
context=dict(request.context, show_address=True, no_tag_br=True)
|
||||
cr, uid = request.cr, request.uid
|
||||
env = request.env(context=dict(request.env.context, show_address=True, no_tag_br=True))
|
||||
|
||||
Country = request.registry['res.country']
|
||||
Jobs = request.registry['hr.job']
|
||||
|
||||
# Search all available jobs as uid
|
||||
job_ids = Jobs.search(cr, uid, [], order="website_published desc,no_of_recruitment desc", context=context)
|
||||
Country = env['res.country']
|
||||
Jobs = env['hr.job']
|
||||
|
||||
# List jobs available to current UID
|
||||
job_ids = Jobs.search([], order="website_published desc,no_of_recruitment desc").ids
|
||||
# Browse jobs as superuser, because address is restricted
|
||||
jobs = Jobs.browse(cr, 1, job_ids, context=context)
|
||||
jobs = Jobs.sudo().browse(job_ids)
|
||||
|
||||
# Deduce departments and offices of those jobs
|
||||
departments = set(j.department_id for j in jobs if j.department_id)
|
||||
|
@ -36,12 +36,11 @@ class website_hr_recruitment(http.Controller):
|
|||
countries = set(o.country_id for o in offices if o.country_id)
|
||||
|
||||
# Default search by user country
|
||||
if not country and not department and not office_id:
|
||||
if not (country or department or office_id):
|
||||
country_code = request.session['geoip'].get('country_code')
|
||||
if country_code:
|
||||
country_ids = Country.search(cr, uid, [('code', '=', country_code)], context=context)
|
||||
if country_ids:
|
||||
country = Country.browse(cr, uid, country_ids[0], context=context)
|
||||
countries_ = Country.search([('code', '=', country_code)])
|
||||
country = countries[0] if countries_ else None
|
||||
|
||||
# Filter the matching one
|
||||
if country:
|
||||
|
@ -64,31 +63,33 @@ class website_hr_recruitment(http.Controller):
|
|||
|
||||
@http.route('/jobs/add', type='http', auth="user", website=True)
|
||||
def jobs_add(self, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
value = {
|
||||
job = request.env['hr.job'].create({
|
||||
'name': _('New Job Offer'),
|
||||
}
|
||||
job_id = request.registry.get('hr.job').create(cr, uid, value, context=context)
|
||||
return request.redirect("/jobs/detail/%s?enable_editor=1" % job_id)
|
||||
})
|
||||
return request.redirect("/jobs/detail/%s?enable_editor=1" % slug(job))
|
||||
|
||||
@http.route(['/jobs/detail/<model("hr.job"):job>'], type='http', auth="public", website=True)
|
||||
@http.route('/jobs/detail/<model("hr.job"):job>', type='http', auth="public", website=True)
|
||||
def jobs_detail(self, job, **kwargs):
|
||||
return request.website.render("website_hr_recruitment.detail", { 'job': job, 'main_object': job })
|
||||
return request.render("website_hr_recruitment.detail", {
|
||||
'job': job,
|
||||
'main_object': job,
|
||||
})
|
||||
|
||||
@http.route(['/jobs/apply/<model("hr.job"):job>'], type='http', auth="public", website=True)
|
||||
@http.route('/jobs/apply/<model("hr.job"):job>', type='http', auth="public", website=True)
|
||||
def jobs_apply(self, job):
|
||||
error = {}
|
||||
default = {}
|
||||
if 'website_hr_recruitment_error' in request.session:
|
||||
error = request.session.pop('website_hr_recruitment_error')
|
||||
default = request.session.pop('website_hr_recruitment_default')
|
||||
return request.website.render("website_hr_recruitment.apply", { 'job': job, 'error': error, 'default': default})
|
||||
return request.render("website_hr_recruitment.apply", {
|
||||
'job': job,
|
||||
'error': error,
|
||||
'default': default,
|
||||
})
|
||||
|
||||
@http.route(['/jobs/thankyou'], methods=['POST'], type='http', auth="public", website=True)
|
||||
@http.route('/jobs/thankyou', methods=['POST'], type='http', auth="public", website=True)
|
||||
def jobs_thankyou(self, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
imd = request.registry['ir.model.data']
|
||||
|
||||
error = {}
|
||||
for field_name in ["partner_name", "phone", "email_from"]:
|
||||
if not post.get(field_name):
|
||||
|
@ -101,8 +102,10 @@ class website_hr_recruitment(http.Controller):
|
|||
request.session['website_hr_recruitment_default'] = post
|
||||
return request.redirect('/jobs/apply/%s' % post.get("job_id"))
|
||||
|
||||
# public user can't create applicants (duh)
|
||||
env = request.env(user=SUPERUSER_ID)
|
||||
value = {
|
||||
'source_id' : imd.xmlid_to_res_id(cr, SUPERUSER_ID, 'hr_recruitment.source_website_company'),
|
||||
'source_id' : env.ref('hr_recruitment.source_website_company').id,
|
||||
'name': '%s\'s Application' % post.get('partner_name'),
|
||||
}
|
||||
for f in ['email_from', 'partner_name', 'description']:
|
||||
|
@ -112,7 +115,7 @@ class website_hr_recruitment(http.Controller):
|
|||
# Retro-compatibility for saas-3. "phone" field should be replace by "partner_phone" in the template in trunk.
|
||||
value['partner_phone'] = post.pop('phone', False)
|
||||
|
||||
applicant_id = request.registry['hr.applicant'].create(cr, SUPERUSER_ID, value, context=context)
|
||||
applicant_id = env['hr.applicant'].create(value).id
|
||||
if post['ufile']:
|
||||
attachment_value = {
|
||||
'name': post['ufile'].filename,
|
||||
|
@ -122,7 +125,7 @@ class website_hr_recruitment(http.Controller):
|
|||
'datas': base64.encodestring(post['ufile'].read()),
|
||||
'datas_fname': post['ufile'].filename,
|
||||
}
|
||||
request.registry['ir.attachment'].create(cr, SUPERUSER_ID, attachment_value, context=context)
|
||||
return request.website.render("website_hr_recruitment.thankyou", {})
|
||||
env['ir.attachment'].create(attachment_value)
|
||||
return request.render("website_hr_recruitment.thankyou", {})
|
||||
|
||||
# vim :et:
|
||||
|
|
Loading…
Reference in New Issue