From d0693db8ba87f0c1ce7d7e25a66076cc8aee2381 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 22 Jul 2019 10:38:02 +0100 Subject: [PATCH] More generic profile page --- daemon.py | 51 +++++++++++++++++----- webinterface.py | 110 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 123 insertions(+), 38 deletions(-) diff --git a/daemon.py b/daemon.py index 9b66408c..bd5d08db 100644 --- a/daemon.py +++ b/daemon.py @@ -46,8 +46,6 @@ from skills import outboxSkills from availability import outboxAvailability from webinterface import htmlIndividualPost from webinterface import htmlProfile -from webinterface import htmlFollowing -from webinterface import htmlFollowers from webinterface import htmlInbox from webinterface import htmlOutbox from webinterface import htmlPostReplies @@ -638,27 +636,60 @@ class PubServer(BaseHTTPRequestHandler): self.server.GETbusy=False return authorized=self._isAuthorized() + following=getFollowingFeed(self.server.baseDir,self.server.domain, \ self.server.port,self.path, \ - self.server.httpPrefix, + self.server.httpPrefix, \ authorized,followsPerPage) if following: if 'text/html' in self.headers['Accept']: - self._set_headers('text/html') - self.wfile.write(htmlFollowing(following).encode('utf-8')) + if 'page=' not in self.path: + # get a page of following, not the summary + following=getFollowingFeed(self.server.baseDir,self.server.domain, \ + self.server.port,self.path+'?page=1', \ + self.server.httpPrefix, \ + authorized,followsPerPage) + getPerson = personLookup(self.server.domain,self.path.replace('/following',''), \ + self.server.baseDir) + if getPerson: + self._set_headers('text/html') + self.wfile.write(htmlProfile(self.server.baseDir, \ + self.server.httpPrefix, \ + authorized, \ + self.server.ocapAlways, \ + getPerson,'following', \ + following).encode('utf-8')) + self.server.GETbusy=False + return else: self._set_headers('application/json') self.wfile.write(json.dumps(following).encode('utf-8')) - self.server.GETbusy=False - return + self.server.GETbusy=False + return followers=getFollowingFeed(self.server.baseDir,self.server.domain, \ self.server.port,self.path, \ self.server.httpPrefix, \ authorized,followsPerPage,'followers') if followers: if 'text/html' in self.headers['Accept']: - self._set_headers('text/html') - self.wfile.write(htmlFollowers(followers).encode('utf-8')) + if 'page=' not in self.path: + # get a page of followers, not the summary + followers=getFollowingFeed(self.server.baseDir,self.server.domain, \ + self.server.port,self.path+'?page=1', \ + self.server.httpPrefix, \ + authorized,followsPerPage,'followers') + getPerson = personLookup(self.server.domain,self.path.replace('/followers',''), \ + self.server.baseDir) + if getPerson: + self._set_headers('text/html') + self.wfile.write(htmlProfile(self.server.baseDir, \ + self.server.httpPrefix, \ + authorized, \ + self.server.ocapAlways, \ + getPerson,'followers', \ + followers).encode('utf-8')) + self.server.GETbusy=False + return else: self._set_headers('application/json') self.wfile.write(json.dumps(followers).encode('utf-8')) @@ -674,7 +705,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ authorized, \ self.server.ocapAlways, \ - getPerson).encode('utf-8')) + getPerson,'posts').encode('utf-8')) else: self._set_headers('application/json') self.wfile.write(json.dumps(getPerson).encode('utf-8')) diff --git a/webinterface.py b/webinterface.py index 236ca211..6dc16dd7 100644 --- a/webinterface.py +++ b/webinterface.py @@ -36,7 +36,22 @@ def htmlFooter() -> str: '\n' return htmlStr -def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,profileJson: {}) -> str: +def htmlProfilePosts(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,nickname: str,domain: str,port: int) -> str: + """Shows posts on the profile screen + """ + profileStr='' + outboxFeed=personBoxJson(baseDir,domain, \ + port,'/users/'+nickname+'/outbox?page=1', \ + httpPrefix, \ + 4, 'outbox', \ + authorized, \ + ocapAlways) + for item in outboxFeed['orderedItems']: + if item['type']=='Create': + profileStr+=individualPostAsHtml(item) + return profileStr + +def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,profileJson: {},selected: str,extraJson=None) -> str: """Show the profile page as html """ nickname=profileJson['name'] @@ -51,6 +66,24 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,p domainFull=domain+':'+str(port) profileDescription=profileJson['publicKey']['summary'] profileDescription='A test description' + postsButton='button' + followingButton='button' + followersButton='button' + rolesButton='button' + skillsButton='button' + sharesButton='button' + if selected=='posts': + postsButton='buttonselected' + elif selected=='following': + followingButton='buttonselected' + elif selected=='followers': + followersButton='buttonselected' + elif selected=='roles': + rolesButton='buttonselected' + elif selected=='skills': + skillsButton='buttonselected' + elif selected=='shares': + sharesButton='buttonselected' profileStr= \ '
' \ '
' \ @@ -62,12 +95,12 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,p '
' \ '
\n' \ '
' \ - ' ' \ - ' ' \ - ' ' \ - ' ' \ - ' ' \ - ' ' \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ '
' \ '
' @@ -157,6 +190,46 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,p ' opacity: 1;' \ ' right: 0;' \ '}' \ + '.buttonselected {' \ + ' border-radius: 4px;' \ + ' background-color: #666;' \ + ' border: none;' \ + ' color: #FFFFFF;' \ + ' text-align: center;' \ + ' font-size: 18px;' \ + ' padding: 10px;' \ + ' width: 20%;' \ + ' max-width: 200px;' \ + ' min-width: 100px;' \ + ' transition: all 0.5s;' \ + ' cursor: pointer;' \ + ' margin: 5px;' \ + '}' \ + '' \ + '.buttonselected span {' \ + ' cursor: pointer;' \ + ' display: inline-block;' \ + ' position: relative;' \ + ' transition: 0.5s;' \ + '}' \ + '' \ + '.buttonselected span:after {' \ + " content: '\\00bb';" \ + ' position: absolute;' \ + ' opacity: 0;' \ + ' top: 0;' \ + ' right: -20px;' \ + ' transition: 0.5s;' \ + '}' \ + '' \ + '.buttonselected:hover span {' \ + ' padding-right: 25px;' \ + '}' \ + '' \ + '.buttonselected:hover span:after {' \ + ' opacity: 1;' \ + ' right: 0;' \ + '}' \ '.container {' \ ' border: 2px solid #dedede;' \ ' background-color: #f1f1f1;' \ @@ -219,30 +292,11 @@ def htmlProfile(baseDir: str,httpPrefix: str,authorized: bool,ocapAlways: bool,p ' color: #999;' \ '}' - # show some posts - outboxFeed=personBoxJson(baseDir,domain, \ - port,'/users/'+nickname+'/outbox?page=1', \ - httpPrefix, \ - 4, 'outbox', \ - authorized, \ - ocapAlways) - for item in outboxFeed['orderedItems']: - if item['type']=='Create': - profileStr+=individualPostAsHtml(item) - + if selected=='posts': + profileStr+=htmlProfilePosts(baseDir,httpPrefix,authorized,ocapAlways,nickname,domain,port) profileStr=htmlHeader(profileStyle)+profileStr+htmlFooter() return profileStr -def htmlFollowing(followingJson: {}) -> str: - """Show the following collection as html - """ - return htmlHeader()+"

Following collection

"+htmlFooter() - -def htmlFollowers(followersJson: {}) -> str: - """Show the followers collection as html - """ - return htmlHeader()+"

Followers collection

"+htmlFooter() - def individualPostAsHtml(postJsonObject: {}) -> str: avatarPosition='' containerClass='container'