Tidying of individual shared item search result

main
Bob Mottram 2021-07-27 10:43:36 +01:00
parent 3a19ec4d2e
commit ec3b083543
1 changed files with 54 additions and 51 deletions

View File

@ -119,6 +119,56 @@ def _matchSharedItem(searchStrLowerList: [],
return False return False
def _htmlSearchResultShare(sharedItem: {}, translate: {},
httpPrefix: str, domainFull: str,
contactNickname: str, name: str,
actor: str) -> str:
"""Returns the html for an individual shared item
"""
sharedItemsForm = '<div class="container">\n'
sharedItemsForm += \
'<p class="share-title">' + sharedItem['displayName'] + '</p>\n'
if sharedItem.get('imageUrl'):
sharedItemsForm += \
'<a href="' + sharedItem['imageUrl'] + '">\n'
sharedItemsForm += \
'<img loading="lazy" src="' + sharedItem['imageUrl'] + \
'" alt="Item image"></a>\n'
sharedItemsForm += '<p>' + sharedItem['summary'] + '</p>\n<p>'
if sharedItem.get('itemQty'):
sharedItemsForm += \
'<b>' + translate['Quantity'] + \
':</b> ' + str(sharedItem['itemQty']) + ' '
sharedItemsForm += \
'<b>' + translate['Type'] + ':</b> ' + sharedItem['itemType'] + ' '
sharedItemsForm += \
'<b>' + translate['Category'] + ':</b> ' + sharedItem['category'] + ' '
sharedItemsForm += \
'<b>' + translate['Location'] + ':</b> ' + sharedItem['location']
if sharedItem.get('itemPrice') and \
sharedItem.get('itemCurrency'):
if isfloat(sharedItem['itemPrice']):
if float(sharedItem['itemPrice']) > 0:
sharedItemsForm += \
' <b>' + translate['Price'] + \
':</b> ' + sharedItem['itemPrice'] + \
' ' + sharedItem['itemCurrency']
sharedItemsForm += '</p>\n'
contactActor = \
httpPrefix + '://' + domainFull + '/users/' + contactNickname
sharedItemsForm += \
'<p><a href="' + actor + '?replydm=sharedesc:' + \
sharedItem['displayName'] + '?mention=' + contactActor + \
'"><button class="button">' + translate['Contact'] + '</button></a>\n'
if actor.endswith('/users/' + contactNickname):
sharedItemsForm += \
' <a href="' + actor + '?rmshare=' + \
name + '"><button class="button">' + \
translate['Remove'] + '</button></a>\n'
sharedItemsForm += '</p></div>\n'
return sharedItemsForm
def htmlSearchSharedItems(cssCache: {}, translate: {}, def htmlSearchSharedItems(cssCache: {}, translate: {},
baseDir: str, searchStr: str, baseDir: str, searchStr: str,
pageNumber: int, pageNumber: int,
@ -165,58 +215,11 @@ def htmlSearchSharedItems(cssCache: {}, translate: {},
for name, sharedItem in sharesJson.items(): for name, sharedItem in sharesJson.items():
if _matchSharedItem(searchStrLowerList, sharedItem): if _matchSharedItem(searchStrLowerList, sharedItem):
if currPage == pageNumber: if currPage == pageNumber:
sharedItemsForm += '<div class="container">\n'
sharedItemsForm += \ sharedItemsForm += \
'<p class="share-title">' + \ _htmlSearchResultShare(sharedItem, translate,
sharedItem['displayName'] + '</p>\n' httpPrefix, domainFull,
if sharedItem.get('imageUrl'): contactNickname,
sharedItemsForm += \ name, actor)
'<a href="' + \
sharedItem['imageUrl'] + '">\n'
sharedItemsForm += \
'<img loading="lazy" src="' + \
sharedItem['imageUrl'] + \
'" alt="Item image"></a>\n'
sharedItemsForm += \
'<p>' + sharedItem['summary'] + '</p>\n<p>'
if sharedItem.get('itemQty'):
sharedItemsForm += \
'<b>' + translate['Quantity'] + \
':</b> ' + str(sharedItem['itemQty']) + ' '
sharedItemsForm += \
'<b>' + translate['Type'] + \
':</b> ' + sharedItem['itemType'] + ' '
sharedItemsForm += \
'<b>' + translate['Category'] + \
':</b> ' + sharedItem['category'] + ' '
sharedItemsForm += \
'<b>' + translate['Location'] + \
':</b> ' + sharedItem['location']
if sharedItem.get('itemPrice') and \
sharedItem.get('itemCurrency'):
if isfloat(sharedItem['itemPrice']):
if float(sharedItem['itemPrice']) > 0:
sharedItemsForm += \
' <b>' + translate['Price'] + \
':</b> ' + sharedItem['itemPrice'] + \
' ' + sharedItem['itemCurrency']
sharedItemsForm += '</p>\n'
contactActor = \
httpPrefix + '://' + domainFull + \
'/users/' + contactNickname
sharedItemsForm += \
'<p><a href="' + actor + \
'?replydm=sharedesc:' + \
sharedItem['displayName'] + \
'?mention=' + contactActor + \
'"><button class="button">' + \
translate['Contact'] + '</button></a>\n'
if actor.endswith('/users/' + contactNickname):
sharedItemsForm += \
' <a href="' + actor + '?rmshare=' + \
name + '"><button class="button">' + \
translate['Remove'] + '</button></a>\n'
sharedItemsForm += '</p></div>\n'
if not resultsExist and currPage > 1: if not resultsExist and currPage > 1:
postActor = \ postActor = \
getAltPath(actor, domainFull, getAltPath(actor, domainFull,