python: document list

This commit is contained in:
Andrey Panov
2019-11-01 10:45:02 +03:00
parent f7867e4bc3
commit c1454eff13
9 changed files with 143 additions and 12 deletions

View File

@ -65,16 +65,16 @@ def getCorrectName(filename, req):
return name
def getFileUri(filename, req):
host = req.META['HTTP_REFERER'].rstrip('/')
host = config.EXAMPLE_DOMAIN.rstrip('/')
curAdr = req.META['REMOTE_ADDR']
return f'{host}{settings.STATIC_URL}{curAdr}/{filename}'
def getCallbackUrl(filename, req):
host = req.META['HTTP_REFERER']
host = config.EXAMPLE_DOMAIN
curAdr = req.META['REMOTE_ADDR']
return f'{host}track?filename={filename}&userAddress={curAdr}'
def getStoragePath(filename, req):
def getRootFolder(req):
if isinstance(req, str):
curAdr = req
else:
@ -85,8 +85,24 @@ def getStoragePath(filename, req):
if not os.path.exists(directory):
os.makedirs(directory)
return directory
def getStoragePath(filename, req):
directory = getRootFolder(req)
return os.path.join(directory, filename)
def getStoredFiles(req):
directory = getRootFolder(req)
files = os.listdir(directory)
fileInfos = []
for f in files:
fileInfos.append({ 'type': fileUtils.getFileType(f), 'title': f, 'url': getFileUri(f, req) })
return fileInfos
def createFile(stream, path, meta = False):
bufSize = 8196
with io.open(path, 'wb') as out:

View File

@ -3,25 +3,25 @@ from urllib.parse import unquote
USERS = [
{
'uid': 'uid-1',
'name': 'John Smith'
'uname': 'John Smith'
},
{
'uid': 'uid-2',
'name': 'Mark Pottato'
'uname': 'Mark Pottato'
},
{
'uid': 'uid-3',
'name': 'Hamish Mitchell'
'uname': 'Hamish Mitchell'
}
]
DEFAULT_USER = USERS[0]
def getUserFromReq(req):
uid = unquote(req.COOKIES.get('uid'))
uname = unquote(req.COOKIES.get('uname'))
uid = req.COOKIES.get('uid')
uname = req.COOKIES.get('uname')
if (not uid) | (not uname):
return DEFAULT_USER
else:
return { 'uid': uid, 'uname': uname }
return { 'uid': unquote(uid), 'uname': unquote(uname) }