Skip to content
Snippets Groups Projects
Commit 1ed3cb37 authored by Jérome Maes's avatar Jérome Maes
Browse files

[IMP] website_slides: provide search bar on channel

Visitor are now able to search a channel, based
on the name or description with a search bar on
the channel list page.

Task-1902304
parent c839df6e
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@ import werkzeug
from odoo import http, _
from odoo.exceptions import AccessError, UserError
from odoo.http import request
from odoo.osv import expression
from odoo.addons.http_routing.models.ir_http import slug
from odoo.addons.website.models.ir_http import sitemap_qs2dom
......@@ -67,15 +69,21 @@ class WebsiteSlides(http.Controller):
redirects directly to its slides
"""
domain = request.website.website_domain()
# search bar
search_term = post.get('search')
if search_term:
domain = expression.AND([domain, ['|', ('name', 'ilike', search_term), ('description', 'ilike', search_term)]])
channels = request.env['slide.channel'].search(domain, order='sequence, id')
if not channels:
return request.render("website_slides.channel_not_found")
elif len(channels) == 1:
return request.render("website_slides.channel_not_found", {'search_term': search_term})
elif len(channels) == 1 and not search_term: # don't auto redirect to only result when searching
return request.redirect("/slides/%s" % channels.id)
return request.render('website_slides.channels', {
'channels': channels,
'user': request.env.user,
'is_public_user': request.website.is_public_user(),
'search_term': search_term,
})
@http.route([
......
......@@ -16,7 +16,22 @@
<template id="channels" name="Channels">
<t t-call="website.layout">
<div class="container mt16">
<h1>Select a Channel</h1>
<div class="d-flex justify-content-between mb-4">
<h1 t-if="not search_term">Select a Channel</h1>
<h1 t-if="search_term">Channel found for "<i><t t-esc="search_term"/></i>"</h1>
<div class="form-inline justify-content-center">
<form method="GET" class="o_website_slides_search">
<div class="input-group">
<input type="text" name="search" class="search-query form-control oe_search_box" placeholder="Search..." t-att-value="search_term"/>
<div class="input-group-append">
<button type="submit" class="btn btn-primary oe_search_button" aria-label="Search" title="Search">
<i class="fa fa-search"/>
</button>
</div>
</div>
</form>
</div>
</div>
<div class="row">
<t t-foreach="channels" t-as="channel">
<div t-if="channel_index % 3 == 0" class="clearfix"/>
......@@ -69,7 +84,12 @@
<t t-call="website.layout">
<div class="container">
<div class="oe_structure">
<h2>No channel created or published yet.</h2>
<t t-if="search_term">
<h2>No channel found when searching "<i><t t-esc="search_term"/></i>".</h2>
</t>
<t t-else="">
<h2>No channel created or published yet.</h2>
</t>
</div>
</div>
</t>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment