From 41616734dd3c2cc87c60ab159ddd736654ea91db Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 14 Aug 2019 10:45:51 +0100 Subject: [PATCH] Page numbers for shared item search --- daemon.py | 21 +++++++++++++++---- webinterface.py | 56 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/daemon.py b/daemon.py index ed248f19..7598edbb 100644 --- a/daemon.py +++ b/daemon.py @@ -2204,8 +2204,17 @@ class PubServer(BaseHTTPRequestHandler): self.server.POSTbusy=False return - # decision to follow in the web interface is confirmed - if authorized and self.path.endswith('/searchhandle'): + # a search was made + if authorized and \ + (self.path.endswith('/searchhandle') or '/searchhandle?page=' in self.path): + # get the page number + pageNumber=1 + if '/searchhandle?page=' in self.path: + pageNumberStr=self.path.split('/searchhandle?page=')[1] + if pageNumberStr.isdigit(): + pageNumber=int(pageNumberStr) + self.path=self.path.split('?page=')[0] + actorStr=self.path.replace('/searchhandle','') length = int(self.headers['Content-length']) searchParams=self.rfile.read(length).decode('utf-8') @@ -2231,7 +2240,9 @@ class PubServer(BaseHTTPRequestHandler): nickname=getNicknameFromActor(self.path) if not self.server.session: self.server.session= \ - createSession(self.server.domain,self.server.port,self.server.useTor) + createSession(self.server.domain, \ + self.server.port, \ + self.server.useTor) profileStr= \ htmlProfileAfterSearch(self.server.baseDir, \ self.path.replace('/searchhandle',''), \ @@ -2251,7 +2262,9 @@ class PubServer(BaseHTTPRequestHandler): else: # shared items search sharedItemsStr= \ - htmlSearchSharedItems(self.server.baseDir,searchStr) + htmlSearchSharedItems(self.server.baseDir, \ + searchStr,pageNumber, \ + maxPostsInFeed,actorStr) if sharedItemsStr: self._login_headers('text/html') self.wfile.write(sharedItemsStr.encode('utf-8')) diff --git a/webinterface.py b/webinterface.py index efcf8120..945d7765 100644 --- a/webinterface.py +++ b/webinterface.py @@ -35,7 +35,11 @@ from content import getMentionsFromHtml from config import getConfigParam from skills import getSkills -def htmlSearchSharedItems(baseDir: str,searchStr: str) -> str: +def htmlSearchSharedItems(baseDir: str,searchStr: str,pageNumber: int,resultsPerPage: int,actor: str) -> str: + """Search results for shared items + """ + currPage=1 + ctr=0 sharedItemsForm='' searchStrLower=searchStr.replace('%2B','+').replace('%40','@').replace('%3A',':').replace('%23','#').lower().strip('\n') searchStrLowerList=searchStrLower.split('+') @@ -55,7 +59,6 @@ def htmlSearchSharedItems(baseDir: str,searchStr: str) -> str: sharesJson=commentjson.load(fp) for name,sharedItem in sharesJson.items(): matched=True - ctr=0 for searchSubstr in searchStrLowerList: subStrMatched=False searchSubstr=searchSubstr.strip() @@ -70,18 +73,43 @@ def htmlSearchSharedItems(baseDir: str,searchStr: str) -> str: if not subStrMatched: matched=False break - ctr+=1 if matched: - sharedItemsForm+='
' - sharedItemsForm+='' - sharedItemsForm+='' - sharedItemsForm+='Item image' - sharedItemsForm+='

'+sharedItem['summary']+'

' - sharedItemsForm+='

Type: '+sharedItem['itemType']+' ' - sharedItemsForm+='Category: '+sharedItem['category']+' ' - sharedItemsForm+='Location: '+sharedItem['location']+'

' - sharedItemsForm+='
' - resultsExist=True + if currPage==pageNumber: + sharedItemsForm+='
' + sharedItemsForm+='' + sharedItemsForm+='' + sharedItemsForm+='Item image' + sharedItemsForm+='

'+sharedItem['summary']+'

' + sharedItemsForm+='

Type: '+sharedItem['itemType']+' ' + sharedItemsForm+='Category: '+sharedItem['category']+' ' + sharedItemsForm+='Location: '+sharedItem['location']+'

' + sharedItemsForm+='
' + if not resultsExist and currPage>1: + # previous page link, needs to be a POST + sharedItemsForm+= \ + '
' \ + ' ' \ + '
' \ + '
' \ + ' Page up' \ + '
' \ + '
' + resultsExist=True + ctr+=1 + if ctr>=resultsPerPage: + currPage+=1 + if currPage>pageNumber: + # next page link, needs to be a POST + sharedItemsForm+= \ + '
' \ + ' ' \ + '
' \ + '
' \ + ' Page down' \ + '
' \ + '
' + break + ctr=0 if not resultsExist: sharedItemsForm+='
No results
' sharedItemsForm+=htmlFooter() @@ -181,7 +209,7 @@ def htmlHashtagSearch(baseDir: str,hashtag: str,pageNumber: int,postsPerPage: in if endIndex>0: # next page link - hashtagSearchForm+='
Page up
' + hashtagSearchForm+='
Page down
' hashtagSearchForm+=htmlFooter() return hashtagSearchForm