diff --git a/webinterface.py b/webinterface.py index adfe3bfd..d7640493 100644 --- a/webinterface.py +++ b/webinterface.py @@ -10,6 +10,7 @@ import json import time import os import commentjson +from collections import OrderedDict from datetime import datetime from datetime import date from dateutil.parser import parse @@ -1153,25 +1154,108 @@ def htmlProfileSkills(translate: {},nickname: str,domain: str,skillsJson: {}) -> profileStr='
'+profileStr+'
' return profileStr -def htmlProfileShares(translate: {},nickname: str,domain: str,sharesJson: {}) -> str: +def htmlIndividualShare(actor: str,item: {},translate: {},showContact: bool) -> str: + """Returns an individual shared item as html + """ + profileStr='
' + profileStr+='

'+item['displayName']+'

' + if item.get('imageUrl'): + profileStr+='' + profileStr+=''+translate['Item image']+'' + profileStr+='

'+item['summary']+'

' + profileStr+='

'+translate['Type']+': '+item['itemType']+' ' + profileStr+=''+translate['Category']+': '+item['category']+' ' + profileStr+=''+translate['Location']+': '+item['location']+'

' + if showContact: + contactActor=item['actor'] + sharedItemsForm+='

' + profileStr+='

' + return profileStr + +def htmlProfileShares(actor: str,translate: {},nickname: str,domain: str,sharesJson: {}) -> str: """Shows shares on the profile screen """ profileStr='' for item in sharesJson['orderedItems']: - profileStr+='
' - profileStr+='

'+item['displayName']+'

' - if item.get('imageUrl'): - profileStr+='' - profileStr+=''+translate['Item image']+'' - profileStr+='

'+item['summary']+'

' - profileStr+='

'+translate['Type']+': '+item['itemType']+' ' - profileStr+=''+translate['Category']+': '+item['category']+' ' - profileStr+=''+translate['Location']+': '+item['location']+'

' - profileStr+='
' + profileStr+=htmlIndividualShare(actor,item,translate,False) if len(profileStr)>0: profileStr='
'+profileStr+'
' return profileStr +def sharesTimelineJson(actor: str,pageNumber: int,itemsPerPage: int, \ + baseDir: str,maxSharesPerAccount: int) -> ({},bool): + """Get a page on the shared items timeline as json + maxSharesPerAccount helps to avoid one person dominating the timeline + by sharing a large number of things + """ + allSharesJson={} + for subdir, dirs, files in os.walk(baseDir+'/accounts'): + for handle in dirs: + if '@' in handle: + accountDir=baseDir+'/accounts/'+handle + sharesFilename=accountDir+'/shares.json' + if os.path.isfile(sharesFilename): + sharesJson=loadJson(sharesFilename) + if not sharesJson: + continue + ctr=0 + for itemID,item in sharesJson.items(): + allSharesJson[str(item['published'])]=item + ctr+=1 + if ctr>=maxSharesPerAccount: + break + # sort the shared items in descending order of publication date + sharesJson=OrderedDict(sorted(allSharesJson.items(),reverse=True)) + lastPage=False + startIndex=itemsPerPage*pageNumber + maxIndex=len(sharesJson.items()) + if maxIndex=maxIndex-itemsPerPage: + lastPage=True + startIndex=maxIndex-itemsPerPage + if startIndex<0: + startIndex=0 + ctr=0 + resultJson={} + for published,item in sharesJson.items(): + if ctr>=startIndex+itemsPerPage: + break + if ctr str: + """Show shared items timeline as html + """ + sharesJson,lastPage= \ + sharesTimelineJson(actor,pageNumber,itemsPerPage, \ + baseDir,maxSharesPerAccount) + domainFull=domain + if port!=80 and port!=443: + if ':' not in domain: + domainFull=domain+':'+str(port) + actor=httpPrefix+'://'+domainFull+'/users/'+nickname + timelineStr='' + + if pageNumber>1: + timelineStr+='
'+translate['Page up']+'
' + + for published,item in sharesJson.items(): + timelineStr+=htmlIndividualShare(actor,item,translate,True) + + if not lastPage: + timelineStr+='
'+translate['Page down']+'
' + + return timelineStr + def htmlProfile(translate: {},projectVersion: str, \ baseDir: str,httpPrefix: str,authorized: bool, \ ocapAlways: bool,profileJson: {},selected: str, \ @@ -1346,7 +1430,7 @@ def htmlProfile(translate: {},projectVersion: str, \ htmlProfileSkills(translate,nickname,domainFull,extraJson) if selected=='shares': profileStr+= \ - htmlProfileShares(translate,nickname,domainFull,extraJson)+licenseStr + htmlProfileShares(actor,translate,nickname,domainFull,extraJson)+licenseStr profileStr=htmlHeader(cssFilename,profileStyle)+profileStr+htmlFooter() return profileStr @@ -2311,6 +2395,13 @@ def htmlTimeline(translate: {},pageNumber: int, \ ' ' \ '' + if boxName=='tlshares': + maxSharesPerAccount=itemsPerPage + return htmlSharesTimeline(translate,pageNumber,itemsPerPage, \ + baseDir,nickname,domain,port, \ + maxSharesPerAccount,httpPrefix) + \ + htmlFooter() + # add the javascript for content warnings tlStr+=''