add pfb doc search form, with some real results
This commit is contained in:
parent
70469e91f5
commit
25bcf98d7e
|
@ -19,6 +19,13 @@
|
|||
template="docsearch.pt"
|
||||
permission="zope2.View"/>
|
||||
|
||||
<browser:page
|
||||
for=".form.IFolderWithPfbDocuments"
|
||||
name="folder_listing"
|
||||
class=".form.SearchView"
|
||||
template="docsearchpfb.pt"
|
||||
permission="zope2.View"/>
|
||||
|
||||
<browser:page
|
||||
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
|
||||
name="search2"
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
xmlns:metal="http://xml.zope.org/namespaces/metal"
|
||||
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
|
||||
lang="en"
|
||||
metal:use-macro="context/main_template/macros/master"
|
||||
i18n:domain="tabellio.searchform">
|
||||
<body>
|
||||
|
||||
<metal:main fill-slot="main">
|
||||
<tal:main-macro metal:define-macro="main">
|
||||
|
||||
<div tal:replace="structure provider:plone.abovecontenttitle" />
|
||||
<h1 class="documentFirstHeading" tal:content="context/title" />
|
||||
<div tal:replace="structure provider:plone.belowcontenttitle" />
|
||||
|
||||
<div tal:replace="structure view/document_pfb_search_form"/>
|
||||
|
||||
<div tal:define="Batch python:modules['Products.CMFPlone'].Batch;
|
||||
mq python:modules['ZTUtils'].make_query;
|
||||
url batch_base_url | request/ACTUAL_URL;
|
||||
batchformkeys batchformkeys|nothing;
|
||||
batchlinkparams python:batchformkeys and dict([(key, unicode(request.form[key]).encode('utf-8')) for key in batchformkeys if key in request]) or dict([(key, unicode(request.form[key]).encode('utf-8')) for key in request.form]);
|
||||
doc_results view/document_results;
|
||||
b_size python:10; b_size request/b_size | b_size;
|
||||
b_start python:0;b_start request/b_start | b_start;
|
||||
doc_batch python:Batch(doc_results, b_size,
|
||||
int(b_start), orphan=1);"
|
||||
tal:condition="doc_results">
|
||||
|
||||
<div id="resultsbox">
|
||||
<span>Nombre de résultats : <span tal:content="python: len(doc_results)"/></span>
|
||||
</div>
|
||||
|
||||
<div id="results">
|
||||
<ul>
|
||||
<tal:entry tal:repeat="doc doc_batch">
|
||||
<li tal:define="oddrow repeat/doc/odd;" tal:attributes="class python: oddrow and 'odd' or 'even'"><div>
|
||||
<h4><a href="#" tal:attributes="href doc/getURL" tal:content="doc/Title">Véronique Salvi</a></h4>
|
||||
<p class="authors" tal:content="python: doc.getObject().get_authors_as_string()" tal:condition="python: doc.getObject().authors" />
|
||||
</div></li>
|
||||
</tal:entry>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="results-nav" tal:define="p doc_batch/previous | nothing;
|
||||
n doc_batch/next | nothing">
|
||||
<a tal:condition="p" id="results-nav-prev" href="#">Précédent</a>
|
||||
<a tal:condition="n" id="results-nav-next" href="#">Suivant</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div tal:replace="structure provider:plone.belowcontentbody" />
|
||||
|
||||
</tal:main-macro>
|
||||
</metal:main>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,6 +1,7 @@
|
|||
from zope import interface, schema
|
||||
from z3c.form import form, field, button
|
||||
from plone.z3cform.layout import wrap_form
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
|
||||
from z3c.form.ptcompat import ViewPageTemplateFile
|
||||
|
||||
|
@ -12,10 +13,12 @@ from tabellio.searchform.interfaces import MessageFactory as _
|
|||
from Products.Five import BrowserView
|
||||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
||||
|
||||
|
||||
class IFolderWithDocuments(interface.Interface):
|
||||
pass
|
||||
|
||||
class IFolderWithPfbDocuments(interface.Interface):
|
||||
pass
|
||||
|
||||
class IDocumentSearch(interface.Interface):
|
||||
nodoc = schema.TextLine(title=_(u'Document Number'), required=False)
|
||||
nosuite = schema.TextLine(title=_(u'Suite Number'), required=False)
|
||||
|
@ -111,7 +114,76 @@ class QuestionSearchForm(form.Form):
|
|||
return
|
||||
|
||||
|
||||
class IDocumentPfbSearch(interface.Interface):
|
||||
nodoc = schema.TextLine(title=_(u'Document Number'), required=False)
|
||||
doctype = schema.Choice(title=_(u'Type'), required=False,
|
||||
values=[_(u'Lorem'), _(u'Ipsum')])
|
||||
#subjects =
|
||||
ttitle = schema.TextLine(title=_(u'Title'), required=False)
|
||||
text = schema.TextLine(title=_(u'Text'), required=False)
|
||||
authors = RelationList(title=_(u'Authors'), default=[], required=False,
|
||||
value_type=RelationChoice(title=_(u'Author'),
|
||||
source=ObjPathSourceBinder(
|
||||
portal_type=['themis.datatypes.deputy'])))
|
||||
# polgroups
|
||||
# session
|
||||
start = schema.Date(title=_(u'Start'), required=False)
|
||||
end = schema.Date(title=_(u'End'), required=False)
|
||||
|
||||
sort_on = schema.Choice(title=_(u'Sort By'), required=True,
|
||||
values=[_(u'Type'), _(u'Number'), _(u'Session')])
|
||||
|
||||
|
||||
class DocumentPfbSearchForm(form.Form):
|
||||
fields = field.Fields(IDocumentPfbSearch)
|
||||
ignoreContext = True
|
||||
template = ViewPageTemplateFile('form_templates/view_pfbdocsearch.pt')
|
||||
|
||||
@button.buttonAndHandler(u'Search')
|
||||
def handleApply(self, action):
|
||||
data, errors = self.extractData()
|
||||
if not errors and False:
|
||||
plone_utils = getToolByName(self.context.context, 'plone_utils')
|
||||
plone_utils.addPortalMessage(_('Your search has been completed!'))
|
||||
return self.request.response.redirect('./')
|
||||
return
|
||||
|
||||
|
||||
class SearchView(BrowserView):
|
||||
def document_results(self):
|
||||
f = DocumentPfbSearchForm(self.context, self.request)
|
||||
f.update()
|
||||
data, errors = f.extractData()
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
kw = {}
|
||||
if data.get('ttitle'):
|
||||
kw['Title'] = data.get('ttitle')
|
||||
if data.get('start') and data.get('end'):
|
||||
kw['dateDoc'] = {'query': [data.get('start'), data.get('end')], 'range': 'minmax'}
|
||||
elif data.get('start'):
|
||||
kw['dateDoc'] = {'query': data.get('start'), 'range': 'min'}
|
||||
elif data.get('end'):
|
||||
kw['dateDoc'] = {'query': data.get('end'), 'range': 'max'}
|
||||
|
||||
if data.get('sort_on') == 'Type':
|
||||
kw['sort_on'] = 'doctype'
|
||||
elif data.get('sort_on') == 'Number':
|
||||
kw['sort_on'] = 'no'
|
||||
elif data.get('session') == 'Session':
|
||||
kw['sort_on'] = 'session'
|
||||
|
||||
if not kw:
|
||||
return []
|
||||
|
||||
return catalog(
|
||||
portal_type=['tabellio.documents.document'],
|
||||
**kw)
|
||||
|
||||
def document_pfb_search_form(self):
|
||||
f = DocumentPfbSearchForm(self.context, self.request)
|
||||
f.update()
|
||||
return f.render()
|
||||
|
||||
def document_search_form(self):
|
||||
f = DocumentSearchForm(self.context, self.request)
|
||||
f.update()
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal">
|
||||
<body>
|
||||
<form method="post" action=".">
|
||||
<metal:use use-macro="context/@@ploneform-macros/fields" />
|
||||
<metal:use use-macro="context/@@ploneform-macros/actions" />
|
||||
</form>
|
||||
|
||||
</html>
|
Reference in New Issue