Hi ,
I have a list of studiants in website , I want to add a search bar to search name ,age,...
How to make it ?
Thanks.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi ,
I have a list of studiants in website , I want to add a search bar to search name ,age,...
How to make it ?
Thanks.
Odoo default "portal_searchbar" template using search records in website.
Call the template in XML and Controllers return search and search_in parameter corresponding value based on your requirements.
sortby, filterby, groupby is extra features based on complex data can add, if required.
Example default core module.
<template id="portal_my_timesheets" name="My Timesheets">
<t t-call="portal.portal_layout">
<t t-set="breadcrumbs_searchbar" t-value="True"/>
<t t-call="portal.portal_searchbar">
<t t-set="title">Timesheets</t>
</t>
<t t-if="not grouped_timesheets">
<div class="alert alert-warning mt8" role="alert">
There are no timesheets.
</div>
</t>
<t t-if="grouped_timesheets">
<t t-call="portal.portal_table">
<t t-foreach="grouped_timesheets" t-as="timesheets">
<thead>
<tr t-attf-class="{{'thead-light' if not groupby == 'none' else ''}}">
<th t-if="groupby == 'none'">Description</th>
<th t-else="">
<em class="font-weight-normal text-muted">Timesheets for project:</em>
<span t-field="timesheets[0].project_id.name"/></th>
<th>Date</th>
<th>Employee</th>
<th class="text-right">Duration</th>
</tr>
</thead>
<tbody>
<t t-foreach="timesheets" t-as="timesheet">
<tr>
<td><span t-esc="timesheet.name"/></td>
<td><span t-field="timesheet.date" t-options='{"widget": "date"}'/></td>
<td><span t-field="timesheet.employee_id"/></td>
<td class="text-right"><span t-field="timesheet.unit_amount" t-options='{"widget": "duration", "unit": "hour", "round": "minute"}'/></td>
</tr>
</t>
</tbody>
</t>
</t>
</t>
</t>
</template>
@http.route(['/my/timesheets', '/my/timesheets/page/<int:page>'], type='http', auth="user", website=True)
def portal_my_timesheets(self, page=1, sortby=None, filterby=None, search=None, search_in='all', groupby='project', **kw):
Timesheet_sudo = request.env['account.analytic.line'].sudo()
values = self._prepare_portal_layout_values()
domain = request.env['account.analytic.line']._timesheet_get_portal_domain()
searchbar_sortings = {
'date': {'label': _('Newest'), 'order': 'date desc'},
'name': {'label': _('Name'), 'order': 'name'},
}
searchbar_inputs = {
'all': {'input': 'all', 'label': _('Search in All')},
}
searchbar_groupby = {
'none': {'input': 'none', 'label': _('None')},
'project': {'input': 'project', 'label': _('Project')},
}
today = fields.Date.today()
quarter_start, quarter_end = date_utils.get_quarter(today)
last_week = today + relativedelta(weeks=-1)
last_month = today + relativedelta(months=-1)
last_year = today + relativedelta(years=-1)
searchbar_filters = {
'all': {'label': _('All'), 'domain': []},
'today': {'label': _('Today'), 'domain': [("date", "=", today)]},
}
# default sort by value
if not sortby:
sortby = 'date'
order = searchbar_sortings[sortby]['order']
# default filter by value
if not filterby:
filterby = 'all'
domain = AND([domain, searchbar_filters[filterby]['domain']])
if search and search_in:
domain = AND([domain, [('name', 'ilike', search)]])
timesheet_count = Timesheet_sudo.search_count(domain)
# pager
pager = portal_pager(
url="/my/timesheets",
url_args={'sortby': sortby, 'search_in': search_in, 'search': search, 'filterby': filterby},
total=timesheet_count,
page=page,
step=self._items_per_page
)
if groupby == 'project':
order = "project_id, %s" % order
timesheets = Timesheet_sudo.search(domain, order=order, limit=self._items_per_page, offset=pager['offset'])
if groupby == 'project':
grouped_timesheets = [Timesheet_sudo.concat(*g) for k, g in groupbyelem(timesheets, itemgetter('project_id'))]
else:
grouped_timesheets = [timesheets]
values.update({
'timesheets': timesheets,
'grouped_timesheets': grouped_timesheets,
'page_name': 'timesheet',
'default_url': '/my/timesheets',
'pager': pager,
'searchbar_sortings': searchbar_sortings,
'search_in': search_in,
'sortby': sortby,
'groupby': groupby,
'searchbar_inputs': searchbar_inputs,
'searchbar_groupby': searchbar_groupby,
'searchbar_filters': OrderedDict(sorted(searchbar_filters.items())),
'filterby': filterby,
})
return request.render("hr_timesheet.portal_my_timesheets", values)
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
3
Apr 24
|
1024 | ||
|
0
May 24
|
46 | ||
|
1
Apr 24
|
1829 | ||
|
4
Sep 23
|
3085 | ||
|
2
Sep 23
|
5593 |