[FIX] website_hr_recruitment full cleanups

- keep url namespace under /jobs
- public mode fixes
- moved jobs_ids field in hr_recruitment
- simplify code, remove dead code and data

bzr revid: al@openerp.com-20140129051403-cipao0bllxa85gsg
This commit is contained in:
Antony Lesuisse 2014-01-29 06:14:03 +01:00
parent 6b7d9f2bac
commit 6f8d8434dc
12 changed files with 83 additions and 120 deletions

View File

@ -654,13 +654,13 @@ class base_language_install(osv.osv_memory):
} }
return action return action
class SeoMetadata(osv.Model): class website_seo_metadata(osv.Model):
_name = 'website.seo.metadata' _name = 'website.seo.metadata'
_description = 'SEO metadata' _description = 'SEO metadata'
_columns = { _columns = {
'website_meta_title': fields.char("Website meta title", size=70, translate=True), 'website_meta_title': fields.char("Website meta title", translate=True),
'website_meta_description': fields.text("Website meta description", size=160, translate=True), 'website_meta_description': fields.text("Website meta description", translate=True),
'website_meta_keywords': fields.char("Website meta keywords", translate=True), 'website_meta_keywords': fields.char("Website meta keywords", translate=True),
} }

View File

@ -11,14 +11,14 @@ OpenERP Contact Form
'author': 'OpenERP SA', 'author': 'OpenERP SA',
'depends': ['website_partner', 'hr_recruitment', 'website_mail'], 'depends': ['website_partner', 'hr_recruitment', 'website_mail'],
'data': [ 'data': [
'data/website_hr_recruitment_data.xml',
'views/website_hr_recruitment.xml',
'views/hr_recruitment_backend.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'security/website_hr_recruitment_security.xml', 'security/website_hr_recruitment_security.xml',
'data/config_data.xml',
'views/hr_job_views.xml',
'views/templates.xml',
], ],
'demo': [ 'demo': [
'data/website_hr_recruitment_demo.xml', 'data/hr_job_demo.xml',
], ],
'css': [ 'css': [
'static/src/css/*.css' 'static/src/css/*.css'

View File

@ -1,102 +1,90 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import base64
from openerp.addons.web import http from openerp.addons.web import http
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp.addons.web.http import request from openerp.addons.web.http import request
from openerp.addons.website.controllers.main import Website as controllers
controllers = controllers()
import base64
class website_hr_recruitment(http.Controller): class website_hr_recruitment(http.Controller):
@http.route([ @http.route([
'/jobs', '/jobs',
'/jobs/department/<model("hr.department"):department>/office/<model("res.partner"):office>',
'/jobs/department/<model("hr.department"):department>', '/jobs/department/<model("hr.department"):department>',
'/jobs/office/<model("res.partner"):office>' '/jobs/office/<string:office>'
], type='http', auth="public", website=True, multilang=True) ], type='http', auth="public", website=True, multilang=True)
def jobs(self, department=None, office=None): def jobs(self, department=None, office=None):
context=dict(request.context, show_address=True, no_tag_br=True)
cr, uid = request.cr, request.uid
# office is restriced, deslugify manually
office_id = 0
if office:
office_id = int(office.split('-')[-1])
# Search all available jobs as uid
JobsObj = request.registry['hr.job'] JobsObj = request.registry['hr.job']
jobpost_ids = JobsObj.search(request.cr, request.uid, [], job_ids = JobsObj.search(cr, uid, [], order="website_published desc,no_of_recruitment desc", context=context)
order="website_published desc,no_of_recruitment desc",
context=request.context)
jobs = JobsObj.browse(request.cr, request.uid, jobpost_ids, context=dict(request.context, show_address=True, no_tag_br=True))
departments = set() # Browse jobs as superuser, because address is restricted
offices = set() jobs = JobsObj.browse(cr, 1, job_ids, context=context)
for job in jobs:
if job.department_id:
departments.add(job.department_id)
if job.address_id:
offices.add(job.address_id)
if department or office: # Deduce departments and offices of those jobs
_jobs = [] departments = set(j.department_id for j in jobs if j.department_id)
for job in jobs: offices = set(j.address_id for j in jobs if j.address_id)
if (department and job.department_id.id == department.id) or \
(office and job.address_id.id == office.id):
_jobs.append(job)
jobs = _jobs
# Filter the matching one
jobs = [j for j in jobs if department==None or j.department_id and j.department_id.id == department.id]
jobs = [j for j in jobs if office==None or j.address_id and j.address_id.id == office_id]
# Render page
return request.website.render("website_hr_recruitment.index", { return request.website.render("website_hr_recruitment.index", {
'jobs': jobs, 'jobs': jobs,
'departments': departments, 'departments': departments,
'offices': offices, 'offices': offices,
'active': department and department.id or None, 'department_id': department and department.id,
'office': office and office.id or None 'office_id': office_id,
}) })
@http.route(['/job/detail/<model("hr.job"):job>'], type='http', auth="public", website=True, multilang=True) @http.route('/jobs/add', type='http', auth="user", methods=['POST'], website=True)
def detail(self, job, **kwargs): def jobs_add(self, **kwargs):
cr, uid, context = request.cr, request.uid, request.context
value = {
'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)
@http.route(['/jobs/detail/<model("hr.job"):job>'], type='http', auth="public", website=True, multilang=True)
def jobs_detail(self, job, **kwargs):
return request.website.render("website_hr_recruitment.detail", { 'job': job, 'main_object': job }) return request.website.render("website_hr_recruitment.detail", { 'job': job, 'main_object': job })
@http.route(['/job/success'], methods=['POST'], type='http', auth="admin", website=True, multilang=True) @http.route(['/jobs/apply/<model("hr.job"):job>'], type='http', auth="public", website=True, multilang=True)
def success(self, **post): def jobs_apply(self, job):
data = { return request.website.render("website_hr_recruitment.apply", { 'job': job })
'name': _('Online Form'),
'phone': post.get('phone', False),
'email_from': post.get('email_from', False),
'partner_name': post.get('partner_name', False),
'description': post.get('description', False),
'department_id': post.get('department_id', False),
'job_id': post.get('job_id', False),
'user_id': False
}
@http.route(['/jobs/thankyou'], methods=['POST'], type='http', auth="admin", website=True, multilang=True)
def jobs_thankyou(self, **post):
cr, uid, context = request.cr, request.uid, request.context
imd = request.registry['ir.model.data'] imd = request.registry['ir.model.data']
try: value = {
model, source_id = imd.get_object_reference(request.cr, request.uid, 'hr_recruitment', 'source_website_company') 'name': _('Online Form'),
data['source_id'] = source_id 'user_id': False,
except ValueError: 'source_id' : imd.xmlid_to_res_id(cr, uid, 'hr_recruitment.source_website_company'),
pass }
for f in ['phone', 'email_from', 'partner_name', 'description', 'department_id', 'job_id']:
value[f] = post.get(f)
jobid = request.registry['hr.applicant'].create(request.cr, request.uid, data, context=request.context) job_id = request.registry['hr.applicant'].create(cr, uid, value, context=context)
if post['ufile']: if post['ufile']:
attachment_values = { attachment_value = {
'name': post['ufile'].filename, 'name': post['ufile'].filename,
'res_name': value['partner_name'],
'res_model': 'hr.applicant',
'res_id': job_id,
'datas': base64.encodestring(post['ufile'].read()), 'datas': base64.encodestring(post['ufile'].read()),
'datas_fname': post['ufile'].filename, 'datas_fname': post['ufile'].filename,
'res_model': 'hr.applicant', }
'res_name': data['partner_name'], request.registry['ir.attachment'].create(cr, uid, attachment_value, context=context)
'res_id': jobid
}
request.registry['ir.attachment'].create(request.cr, request.uid, attachment_values, context=request.context)
return request.website.render("website_hr_recruitment.thankyou", {}) return request.website.render("website_hr_recruitment.thankyou", {})
@http.route(['/job/apply'], type='http', auth="public", website=True, multilang=True) # vim :et:
def applyjobpost(self, job):
[job_object] = request.registry['hr.job'].browse(
request.cr, request.uid, [int(job)], context=request.context)
return request.website.render("website_hr_recruitment.applyjobpost", {
'job': job_object
})
@http.route('/job/add_job_offer/', type='http', auth="user", methods=['POST'], website=True, multilang=True)
def add_job_offer(self, **kwargs):
Job = request.registry.get('hr.job')
job_id = Job.create(request.cr, request.uid, {
'name': 'New Job Offer',
}, context=request.context)
return request.redirect("/job/detail/%s/?enable_editor=1" % job_id)

View File

@ -1,2 +1 @@
import hr_job import hr_job
import hr_department

View File

@ -1,11 +0,0 @@
# -*- coding: utf-8 -*-
from openerp.osv import osv, fields
class hr_department(osv.osv):
_inherit = "hr.department"
_columns = {
# add field for access right
'department_ids': fields.one2many('hr.job', 'department_id', 'Department'),
}

View File

@ -2,17 +2,14 @@
from openerp.osv import osv, fields from openerp.osv import osv, fields
class hr_job(osv.osv): class hr_job(osv.osv):
""" Override to add website-related columns: published, description. """
_name = 'hr.job' _name = 'hr.job'
_inherit = ['hr.job','website.seo.metadata'] _inherit = ['hr.job','website.seo.metadata']
def _website_url(self, cr, uid, ids, field_name, arg, context=None): def _website_url(self, cr, uid, ids, field_name, arg, context=None):
res = dict.fromkeys(ids, '') res = dict.fromkeys(ids, '')
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
for job in self.browse(cr, uid, ids, context=context): for job in self.browse(cr, uid, ids, context=context):
res[job.id] = "%s/job/detail/%s/" % (base_url, job.id) res[job.id] = "/jobs/detail/%s/" % job.id
return res return res
def job_open(self, cr, uid, ids, context=None): def job_open(self, cr, uid, ids, context=None):
@ -20,9 +17,9 @@ class hr_job(osv.osv):
return super(hr_job, self).job_open(cr, uid, ids, context) return super(hr_job, self).job_open(cr, uid, ids, context)
_columns = { _columns = {
'website_published': fields.boolean('Available in the website'), 'website_published': fields.boolean('Published'),
'website_description': fields.html('Description for the website'), 'website_description': fields.html('Website description'),
'website_url': fields.function(_website_url, string="Website url", type="char"), 'website_url': fields.function(_website_url, string="Website URL", type="char"),
} }
_defaults = { _defaults = {
'website_published': False 'website_published': False

View File

@ -13,12 +13,11 @@
<record id="hr_department_public" model="ir.rule"> <record id="hr_department_public" model="ir.rule">
<field name="name">Job department: Public</field> <field name="name">Job department: Public</field>
<field name="model_id" ref="hr.model_hr_department"/> <field name="model_id" ref="hr.model_hr_department"/>
<field name="domain_force">[('department_ids.website_published', '=', True)]</field> <field name="domain_force">[('jobs_ids.website_published', '=', True)]</field>
<field name="perm_read" eval="True"/> <field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/> <field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/> <field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/> <field name="perm_unlink" eval="False"/>
</record> </record>
</data> </data>
</openerp> </openerp>

View File

@ -1,7 +1,7 @@
<templates id="template" xml:space="preserve"> <templates id="template" xml:space="preserve">
<t t-extend="website.editorbar"> <t t-extend="website.editorbar">
<t t-jquery="ul.oe_content_menu" t-operation="append"> <t t-jquery="ul.oe_content_menu" t-operation="append">
<li><a href="/job/add_job_offer/" class="js_link2post">New Job Offer</a></li> <li><a href="/jobs/add" class="js_link2post">New Job Offer</a></li>
</t> </t>
</t> </t>
</templates> </templates>

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp> <openerp>
<data> <data>
<record id="view_hr_job_form" model="ir.ui.view"> <record id="view_hr_job_form" model="ir.ui.view">
<field name="name">hr.job.form.inherit</field> <field name="name">hr.job.form.inherit</field>
<field name="model">hr.job</field> <field name="model">hr.job</field>
@ -12,9 +11,7 @@
<field name="website_url" invisible="1"/> <field name="website_url" invisible="1"/>
<field name="website_published" class="pull-right" widget="website_button"/> <field name="website_published" class="pull-right" widget="website_button"/>
</xpath> </xpath>
</field> </field>
</record> </record>
</data>
</data>
</openerp> </openerp>

View File

@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp> <openerp>
<data> <data>
<record id="website_mail_jobs" model="mail.group">
<field name="name">Jobs</field>
<field name="public">public</field>
<field name="description">Job Posts on your website</field>
</record>
<template id="editor_head" inherit_id="website.editor_head" name="Jobs Editor" groups="base.group_hr_manager"> <template id="editor_head" inherit_id="website.editor_head" name="Jobs Editor" groups="base.group_hr_manager">
<xpath expr="//script[@id='website_tour_js']" position="after"> <xpath expr="//script[@id='website_tour_js']" position="after">
@ -71,7 +66,7 @@
<li t-foreach="jobs" t-as="job" class="media"> <li t-foreach="jobs" t-as="job" class="media">
<div class="media-body" t-att-data-publish="job.website_published and 'on' or 'off'"> <div class="media-body" t-att-data-publish="job.website_published and 'on' or 'off'">
<h3 class="media-heading"> <h3 class="media-heading">
<a t-attf-href="/job/detail/#{ slug(job) }/"> <a t-attf-href="/jobs/detail/#{ slug(job) }">
<span t-field="job.name"/> <span t-field="job.name"/>
</a> </a>
<small t-if="job.no_of_recruitment &gt; 1"> <small t-if="job.no_of_recruitment &gt; 1">
@ -127,7 +122,7 @@
"fields": ["address"], "fields": ["address"],
"no_tag_br": true "no_tag_br": true
}'/> }'/>
<h5 class="text-center text-muted"> e<h5 class="text-center text-muted">
<i class="fa fa-clock-o"/> <span t-field="job.write_date"/> <i class="fa fa-clock-o"/> <span t-field="job.write_date"/>
</h5> </h5>
</div> </div>
@ -138,7 +133,7 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-12 text-center mt16 mb16"> <div class="col-md-12 text-center mt16 mb16">
<a t-attf-href="/job/apply/?job=#{ job.id }" class="btn btn-primary btn-lg">Apply</a> <a t-attf-href="/jobs/apply/#{ job.id }" class="btn btn-primary btn-lg">Apply</a>
</div> </div>
</div> </div>
</div> </div>
@ -148,7 +143,7 @@
</t> </t>
</template> </template>
<template id="applyjobpost"> <template id="apply">
<t t-call="website.layout"> <t t-call="website.layout">
<t t-set="additional_title">Apply Job</t> <t t-set="additional_title">Apply Job</t>
<div id="wrap"> <div id="wrap">
@ -163,7 +158,7 @@
<div class="row"> <div class="row">
<section id="forms"> <section id="forms">
<!-- TODO Multilingual form action support ? --> <!-- TODO Multilingual form action support ? -->
<form class="form-horizontal mt32" action="/job/success" method="post" enctype="multipart/form-data"> <form class="form-horizontal mt32" action="/jobs/thankyou" method="post" enctype="multipart/form-data">
<input type="hidden" t-att-value="job and job.department_id.id or False" name="department_id"/> <input type="hidden" t-att-value="job and job.department_id.id or False" name="department_id"/>
<input type="hidden" t-att-value="job and job.id or False" name="job_id"/> <input type="hidden" t-att-value="job and job.id or False" name="job_id"/>
<div class="form-group"> <div class="form-group">
@ -237,10 +232,10 @@
<template id="job_departments" inherit_option_id="website_hr_recruitment.index" name="Filter by Departments"> <template id="job_departments" inherit_option_id="website_hr_recruitment.index" name="Filter by Departments">
<xpath expr="//div[@id='jobs_grid_left']" position="inside"> <xpath expr="//div[@id='jobs_grid_left']" position="inside">
<ul class="nav nav-pills nav-stacked mb32"> <ul class="nav nav-pills nav-stacked mb32">
<li t-att-class=" '' if active else 'active' "><a href="/jobs">All Departments</a></li> <li t-att-class=" '' if department_id else 'active' "><a href="/jobs">All Departments</a></li>
<t t-foreach="departments" t-as="department"> <t t-foreach="departments" t-as="department">
<li t-att-class="department.id == active and 'active' or ''"> <li t-att-class="'active' if department_id == department.id else ''">
<a t-attf-href="/jobs/department/#{ slug(department) }/" ><span t-field="department.name"/></a> <a t-attf-href="/jobs/department/#{ slug(department) }/" ><span t-field="department.name"/></a>
</li> </li>
</t> </t>
</ul> </ul>
@ -256,9 +251,9 @@
<template id="job_offices" inherit_option_id="website_hr_recruitment.index" name="Filter by Offices"> <template id="job_offices" inherit_option_id="website_hr_recruitment.index" name="Filter by Offices">
<xpath expr="//div[@id='jobs_grid_left']" position="inside"> <xpath expr="//div[@id='jobs_grid_left']" position="inside">
<ul class="nav nav-pills nav-stacked mb32"> <ul class="nav nav-pills nav-stacked mb32">
<li t-att-class=" '' if office else 'active' "><a href="/jobs">All Offices</a></li> <li t-att-class=" '' if office_id else 'active' "><a href="/jobs">All Offices</a></li>
<t t-foreach="offices" t-as="thisoffice"> <t t-foreach="offices" t-as="thisoffice">
<li t-att-class="thisoffice.id == office and 'active' or ''"> <li t-att-class=" 'active' if office_id == thisoffice.id else '' ">
<a t-attf-href="/jobs/office/#{ slug(thisoffice) }/" > <a t-attf-href="/jobs/office/#{ slug(thisoffice) }/" >
<span t-field="thisoffice.city"/><t t-if="thisoffice.country_id">, <span t-field="thisoffice.city"/><t t-if="thisoffice.country_id">,
<span t-field="thisoffice.country_id.name"/> <span t-field="thisoffice.country_id.name"/>
@ -276,6 +271,5 @@
</xpath> </xpath>
</template> </template>
</data> </data>
</openerp> </openerp>