Skip to content

Commit

Permalink
Merge pull request #159 from syslabcom/scrum-1990-search-template
Browse files Browse the repository at this point in the history
Use results-listing in search
  • Loading branch information
reinhardt authored Feb 29, 2024
2 parents e864029 + b4c7732 commit 46e06e9
Show file tree
Hide file tree
Showing 4 changed files with 358 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/recensio/plone/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@
permission="zope2.View"
/>

<browser:page
name="search"
for="plone.app.layout.navigation.interfaces.INavigationRoot"
class=".listing.RecensioSearch"
template="templates/search.pt"
permission="zope2.View"
layer="recensio.plone.interfaces.IRecensioPloneLayer"
/>

<browser:page
name="base_view"
for="recensio.plone.content.person.IPerson"
Expand Down
5 changes: 5 additions & 0 deletions src/recensio/plone/browser/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from plone import api
from plone.app.contentlisting.interfaces import IContentListing
from Products.CMFPlone.browser.navtree import getNavigationRoot
from Products.CMFPlone.browser.search import Search
from Products.CMFPlone.utils import normalizeString
from Products.Five.browser import BrowserView
from recensio.plone import _
Expand Down Expand Up @@ -67,6 +68,10 @@ def criteria(self, **kwargs):
return criteria


class RecensioSearch(Search, ListingBase):
"""Add recensio capabilities"""


class ReviewSectionsListing(ListingBase):
@property
def title(self):
Expand Down
6 changes: 4 additions & 2 deletions src/recensio/plone/browser/templates/results-listing.pt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
gnd_view nocall:context/@@gnd-view;
">

<dl class="searchResults">
<dl class="searchResults"
id="search-results"
>
<tal:results repeat="result batch">
<tal:entry define="
result_url result/getURL;
Expand All @@ -61,7 +63,7 @@
use_view_action site_properties/typesUseViewActionInListings|python:();
url python:result_url+'/view' if result_type in use_view_action else result_url+'/';
searchterm request/SearchableText|nothing;
url python:url if searchterm is None else u'%s?searchterm=%s' % (url, searchterm.decode('utf-8'));
url python:url if searchterm is None else u'%s?searchterm=%s' % (url, searchterm);
normalizeString nocall: context/plone_utils/normalizeString;
result_class python:'contenttype-' + normalizeString(result.portal_type);
result_class python:result_foreign and (result_class + ' foreign portal-' + result_portal) or result_class;
Expand Down
340 changes: 340 additions & 0 deletions src/recensio/plone/browser/templates/search.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1,340 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:tal="http://xml.zope.org/namespaces/tal"
lang="en"
metal:use-macro="context/@@main_template/macros/master"
xml:lang="en"
i18n:domain="plone"
>

<head>
<metal:block metal:fill-slot="head_slot">

<link href="${context/@@plone_context_state/object_url}/search_rss?${request/QUERY_STRING}"
rel="alternate"
title="RSS 1.0"
type="application/rss+xml"
tal:condition="request/SearchableText|nothing"
/>
<link href="${view/navroot_url}"
rel="home"
title="Home"
i18n:attributes="title"
/>

</metal:block>

<metal:block fill-slot="top_slot"
tal:define="
disable_column_one python:request.set('disable_plone.leftcolumn',1);
disable_column_two python:request.set('disable_plone.rightcolumn',1);
"
/>
</head>

<body>

<div id="content-core"
metal:fill-slot="main"
tal:define="
b_start python:0;
b_start request/b_start | b_start;
batch python: view.results(b_start=b_start);
results batch;
normalizeString nocall:context/@@plone/normalizeString;
"
>

<form class="searchPage pat-formautofocus"
id="searchform"
action="@@search"
name="searchform"
role="search"
tal:define="
portal context/@@plone_portal_state/portal;
first_call not:request/advanced_search|nothing;
st python:request.get('SearchableText', '');
DateTime python:modules['DateTime'].DateTime;
navigation_root_url view/navroot_url;
icons python:context.restrictedTraverse('@@iconresolver');
"
>

<input name="sort_on"
type="hidden"
value=""
/>
<input name="sort_order"
type="hidden"
value=""
/>
<input id="search-batch-start"
name="b_start:int"
type="hidden"
value="${request/b_start|string:0}"
/>
<input id="advanced-search-input"
name="advanced_search"
type="hidden"
value="${python: 'True' if view.show_advanced_search() else 'False'}"
/>

<div class="input-group">
<input class="searchPage form-control"
name="SearchableText"
size="25"
title="Search Site"
type="text"
value="${st}"
i18n:attributes="title title_search_title;"
/>
<span class="input-group-btn">
<input class="searchPage allowMultiSubmit btn btn-primary"
type="submit"
value="Search"
i18n:attributes="value label_search;"
/>
</span>
</div>

<input name="created.range:record"
type="hidden"
value="min"
/>

<div class="mt-3">
<h1 id="search-term">
<span tal:condition="not:st"
i18n:translate=""
>Search results</span>
<span tal:condition="st"
i18n:translate=""
>
Search results for
<span class="text-muted"
tal:content="st"
i18n:name="term"
>
Search Term
</span>
</span>
</h1>
</div>

<div class="d-flex mb-2">

<div class="flex-fill">
<a class="nav-link active ps-2"
aria-current="page"
href="#"
>
<span class="d-flex"
id="results-count"
i18n:domain="plone"
i18n:translate="batch_x_items_matching_your_criteria"
>
<span class="badge bg-primary me-2 d-flex justify-content-center align-items-center"
id="search-results-number"
tal:content="batch/sequence_length|string:0"
i18n:name="number"
>234</span>
items matching your search terms.
</span>
</a>
</div>

<div class="nav-item dropdown"
id="search-filter"
>
<a class="nav-link dropdown-toggle"
id="search-filter-toggle"
aria-expanded="false"
href="#"
role="button"
data-bs-toggle="dropdown"
i18n:translate="narrow_search_options"
>
Filter the results
</a>
<div class="dropdown-menu dropdown-menu-md-end">
<div class="d-flex text-nowrap">
<div class="mx-3">
<span class="fw-bold"
i18n:translate="label_item_type"
>Item type</span>
<ul class="list-unstyled search-type-options"
tal:define="
portal_types portal/portal_types;
types_list view/types_list;
all_checked python:(len(types_list) == len(request.get('portal_type', []))) or first_call;
toggle_select_state python:all_checked and 'true' or 'false';
"
>
<li>
<div class="form-check">
<input class="form-check-input"
id="pt_toggle"
checked="${python:'checked' if all_checked else ''}"
name="pt_toggle"
type="checkbox"
value="#"
/>
<label class="form-check-label"
for="pt_toggle"
i18n:translate="label_toggle"
>Select All/None</label>
</div>
</li>
<li tal:repeat="type types_list">
<div class="form-check">
<input class="form-check-input"
id="portal_type_${repeat/type/number}"
checked="${python:'checked' if ((type in request.get('portal_type', [])) or first_call) else ''}"
name="portal_type:list"
type="checkbox"
value="${type}"
/>
<label class="form-check-label"
for="portal_type_${repeat/type/number}"
tal:content="python: portal_types.getTypeInfo(type).Title()"
i18n:translate=""
></label>
</div>
</li>
</ul>
</div>
<div class="mx-3">
<span class="fw-bold"
i18n:translate="label_new_items_since"
>New items since</span>
<ul class="list-unstyled"
tal:define="
today python:DateTime().earliestTime();
yesterday python:(today-1).ISO();
lastweek python:(today-7).ISO();
lastmonth python:(today-31).ISO();
ever python:DateTime('1970-01-02').ISO();
checked python:request.get('created', {}).get('query', ever);
"
>
<li>
<div class="form-check">
<input class="form-check-input"
id="query-date-yesterday"
checked="${python:'checked' if checked==yesterday else ''}"
name="created.query:record:date"
type="radio"
value="${yesterday}"
/>
<label class="form-check-label"
for="query-date-yesterday"
i18n:translate="time_yesterday"
>Yesterday</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input"
id="query-date-lastweek"
checked="${python:'checked' if checked==lastweek else ''}"
name="created.query:record:date"
type="radio"
value="${lastweek}"
/>
<label class="form-check-label"
for="query-date-lastweek"
i18n:translate="time_last_week"
>Last week</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input"
id="query-date-lastmonth"
checked="${python:'checked' if checked==lastmonth else ''}"
name="created.query:record:date"
type="radio"
value="${lastmonth}"
/>
<label class="form-check-label"
for="query-date-lastmonth"
i18n:translate="time_last_month"
>Last month</label>
</div>
</li>
<li>
<div class="form-check">
<input class="form-check-input"
id="query-date-ever"
checked="${python:'checked' if checked==ever else ''}"
name="created.query:record:date"
type="radio"
value="${ever}"
/>
<label class="form-check-label"
for="query-date-ever"
i18n:translate="time_ever"
>Ever</label>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>

<div class="nav-item dropdown">
<a class="nav-link dropdown-toggle"
aria-expanded="false"
href="#"
role="button"
data-bs-toggle="dropdown"
i18n:translate="sort_by"
>Sort by</a>
<ul class="dropdown-menu dropdown-menu-md-end"
id="sorting-options"
>
<li tal:repeat="item view/sort_options">
<a class="dropdown-item"
href="${item/url}"
data-order="${python:'reverse' if item.reverse else ''}"
data-sort="${item/sortkey}"
tal:content="item/title"
>sort option</a>
</li>
</ul>
</div>

</div>

<div id="search-results-wrapper">

<metal:searchresults define-macro="search_results"
use-macro="here/@@results-listing/macros/content-core"
/>

</div>

<div class="my-3"
id="rss-subscription"
tal:condition="context/@@syndication-util/search_rss_enabled"
i18n:domain="plone"
>
<a class="mx-2 text-decoration-none -flex align-items-center"
href="${context/@@plone_context_state/object_url}/search_rss?${request/QUERY_STRING}"
>
<img tal:replace="structure python:icons.tag('rss-fill')" />
<span class="ms-1"
i18n:translate="title_subscribe_rss_feed"
>
Subscribe to an always-updated RSS feed.
</span>
</a>
</div>

</form>
</div>

</body>
</html>

0 comments on commit 46e06e9

Please sign in to comment.