[IMP] website_hr_recruitment: Search by country or/and department or/and by office. Default search by country with GeoIP

This commit is contained in:
Christophe Matthieu
2014-05-27 13:50:40 +02:00
parent 4da882d48f
commit 57e6ee4c4e
2 changed files with 54 additions and 14 deletions
@@ -5,22 +5,30 @@ from openerp import SUPERUSER_ID
from openerp.addons.web import http
from openerp.tools.translate import _
from openerp.addons.web.http import request
import logging
_logger = logging.getLogger(__name__)
try:
import GeoIP
except ImportError:
GeoIP = None
_logger.warn("Please install GeoIP python module to use events localisation.")
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>/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):
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)
@@ -29,19 +37,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)
# Default search by user country
if not country and not department and not office_id and GeoIP:
GI = GeoIP.open('/usr/share/GeoIP/GeoIP.dat', 0)
country_code = GI.country_code_by_addr(request.httprequest.remote_addr)
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 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,
})
@@ -230,13 +230,32 @@
</t>
</template>
<template id="job_countries" inherit_option_id="website_hr_recruitment.index" 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_option_id="website_hr_recruitment.index" 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,10 +271,10 @@
<template id="job_offices" inherit_option_id="website_hr_recruitment.index" 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-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/office/#{ slug(thisoffice) }" >
<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>