summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2014-06-23 17:56:38 +0200
committerChristophe Matthieu <chm@odoo.com>2014-06-23 17:56:38 +0200
commited6becb2c063e97ff98e4cd945ecea4bbf20873c (patch)
tree21ef83421c4b9d2cd3f177e1497a9794f28e67e7
parentc81708a891c629480e927df7b1206b7c8c46de7c (diff)
parentbe4dddca8aa361f88675ff507808013b9bea9a84 (diff)
Merge pull request #233 from odoo-dev/master-website_hr_recruitment-GeoIP-chm
[IMP] website_hr_recruitment: Search by country or/and department or/and by office. Default search by country with GeoIP
-rw-r--r--addons/website_hr_recruitment/controllers/main.py32
-rw-r--r--addons/website_hr_recruitment/views/templates.xml47
2 files changed, 53 insertions, 26 deletions
diff --git a/addons/website_hr_recruitment/controllers/main.py b/addons/website_hr_recruitment/controllers/main.py
index 64fda74368f..84f1973cd8c 100644
--- a/addons/website_hr_recruitment/controllers/main.py
+++ b/addons/website_hr_recruitment/controllers/main.py
@@ -9,19 +9,18 @@ from openerp.addons.web.http import request
class website_hr_recruitment(http.Controller):
@http.route([
'/jobs',
+ '/jobs/country/<model("res.country"):country>',
'/jobs/department/<model("hr.department"):department>',
- '/jobs/office/<string:office>',
- '/jobs/country/<model("res.country"):country>'
+ '/jobs/country/<model("res.country"):country>/department/<model("hr.department"):department>',
+ '/jobs/office/<int:office_id>',
+ '/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)
- def jobs(self, department=None, office=None, country=None):
+ 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
- # 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']
job_ids = JobsObj.search(cr, uid, [], order="website_published desc,no_of_recruitment desc", context=context)
@@ -30,21 +29,32 @@ class website_hr_recruitment(http.Controller):
jobs = JobsObj.browse(cr, 1, job_ids, context=context)
# Deduce departments and offices of those jobs
+ countries = set(j.address_id.country_id for j in jobs if j.address_id and j.address_id.country_id)
departments = set(j.department_id for j in jobs if j.department_id)
offices = set(j.address_id for j in jobs if j.address_id)
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:
+ country_code = request.session['geoip'].get('country_code')
+ if country_code:
+ country_ids = request.registry.get('res.country').search(cr, uid, [('code', '=', country_code)], context=context)
+ if country_ids:
+ country = country_ids[0]
+
# Filter the matching one
+ jobs = [j for j in jobs if country==None or j.address_id==None or j.address_id.country_id and j.address_id.country_id.id == country.id]
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]
- jobs = [j for j in jobs if country==None or j.address_id and j.address_id.country_id and j.address_id.country_id.id == country.id]
+ jobs = [j for j in jobs if office_id==None or j.address_id and j.address_id.id == office_id]
# Render page
return request.website.render("website_hr_recruitment.index", {
'jobs': jobs,
+ 'countries': countries,
'departments': departments,
'offices': offices,
- 'department_id': department and department.id,
+ 'country_id': country,
+ 'department_id': department,
'office_id': office_id,
'countries': countries
})
diff --git a/addons/website_hr_recruitment/views/templates.xml b/addons/website_hr_recruitment/views/templates.xml
index 8530c277400..f0eb4569e07 100644
--- a/addons/website_hr_recruitment/views/templates.xml
+++ b/addons/website_hr_recruitment/views/templates.xml
@@ -230,13 +230,32 @@
</t>
</template>
+<template id="job_countries" inherit_id="website_hr_recruitment.index" optional="disabled" name="Filter by Countries">
+ <xpath expr="//div[@id='jobs_grid_left']" position="inside">
+ <ul class="nav nav-pills nav-stacked mb32">
+ <li t-att-class=" '' if country_id else 'active' "><a t-attf-href="/jobs#{ '/department/%s' % slug(department_id) if department_id else '' }#{ '/office/%s' % office_id if office_id else '' }">All Countries</a></li>
+ <t t-foreach="countries" t-as="country">
+ <li t-att-class="'active' if country_id and country_id.id == country.id else ''">
+ <a t-attf-href="/jobs/country/#{ slug(country) }#{ '/department/%s' % slug(department_id) if department_id else '' }#{ '/office/%s' % office_id if office_id else '' }" ><span t-field="country.name"/></a>
+ </li>
+ </t>
+ </ul>
+ </xpath>
+ <xpath expr="//div[@id='jobs_grid_left']" position="attributes">
+ <attribute name="class">col-md-3</attribute>
+ </xpath>
+ <xpath expr="//div[@id='jobs_grid']" position="attributes">
+ <attribute name="class">col-md-9</attribute>
+ </xpath>
+</template>
+
<template id="job_departments" inherit_id="website_hr_recruitment.index" optional="disabled" name="Filter by Departments">
<xpath expr="//div[@id='jobs_grid_left']" position="inside">
<ul class="nav nav-pills nav-stacked mb32">
- <li t-att-class=" '' if department_id else 'active' "><a href="/jobs">All Departments</a></li>
+ <li t-att-class=" '' if department_id else 'active' "><a t-attf-href="/jobs#{ '/country/%s' % slug(country_id) if country_id else '' }#{ '/office/%s' % office_id if office_id else '' }">All Departments</a></li>
<t t-foreach="departments" t-as="department">
- <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>
+ <li t-att-class="'active' if department_id and department_id.id == department.id else ''">
+ <a t-attf-href="/jobs#{ '/country/%s' % slug(country_id) if country_id else '' }/department/#{ slug(department) }#{ '/office/%s' % office_id if office_id else '' }" ><span t-field="department.name"/></a>
</li>
</t>
</ul>
@@ -252,18 +271,16 @@
<template id="job_offices" inherit_id="website_hr_recruitment.index" optional="disabled" name="Filter by Offices">
<xpath expr="//div[@id='jobs_grid_left']" position="inside">
<ul class="nav nav-pills nav-stacked mb32">
- <li t-att-class=" '' if office_id else 'active' "><a href="/jobs">All Offices</a></li>
- <li t-foreach="countries" t-as="thiscountry"><a t-attf-href="/jobs/country/#{slug(thiscountry)}" t-field="thiscountry.name"/>
- <ul class="nav nav-pills nav-stacked nav-hierarchy">
- <t t-foreach="offices" t-as="thisoffice">
- <li t-if="thisoffice.country_id == thiscountry" t-att-class=" 'active' if office_id == thisoffice.id else '' ">
- <a t-attf-href="/jobs/office/#{ slug(thisoffice) }" >
- <span t-field="thisoffice.city"/>
- </a>
- </li>
- </t>
- </ul>
- </li>
+ <li t-att-class=" '' if office_id else 'active' "><a t-attf-href="/jobs#{ '/country/%s' % slug(country_id) if country_id else '' }#{ '/department/%s' % slug(department_id) if department_id else '' }">All Offices</a></li>
+ <t t-foreach="offices" t-as="thisoffice">
+ <li t-att-class=" 'active' if office_id == thisoffice.id else '' ">
+ <a t-attf-href="/jobs#{ '/country/%s' % slug(country_id) if country_id else '' }#{ '/department/%s' % slug(department_id) if department_id else '' }/office/#{ thisoffice.id }" >
+ <span t-field="thisoffice.city"/><t t-if="thisoffice.country_id">,
+ <span t-field="thisoffice.country_id.name"/>
+ </t>
+ </a>
+ </li>
+ </t>
</ul>
</xpath>
<xpath expr="//div[@id='jobs_grid_left']" position="attributes">