wiki upgrade

This commit is contained in:
www
2020-12-27 19:11:52 +00:00
parent c20b688237
commit 35081dee68
4 changed files with 106 additions and 74 deletions

View File

@@ -3,9 +3,11 @@ import urllib.parse
from etherpad_lite import EtherpadLiteClient, EtherpadException
import logging
logger = logging.getLogger(__name__)
from datetime import datetime, timedelta
#SERVER_URL = settings.ETHERPAD_CLIENT["exturl"]
logger.info("loading api.py")
class EtherpadLiteLazyAPI():
"""This is a small wrapper for EtherpadLiteClient
url is the url with port the client should connect to.
@@ -99,3 +101,23 @@ class EtherpadLiteLazyAPI():
if padID is None: return "#"
if not self.connect(): return "#"
return urllib.parse.urljoin(self.exturl, 'p/' + self.group["groupID"] + '$' + str(padID))
def getSessionID(self, username):
if not self.connect(): return "#"
author = self.epc.createAuthorIfNotExistsFor(
name=str(username),
authorMapper=str(username)
)['authorID']
expires = datetime.utcnow() + timedelta(hours=3)
try:
result = self.epc.createSession(
groupID=str(self.group['groupID']),
authorID=str(author),
validUntil=str(int(expires.timestamp()))
)
except Exception as e:
raise e
return None
return result['sessionID']#, expires