Replace important invalid characters in filename strings with useful separators

This commit is contained in:
17acres 2021-05-06 13:09:56 -04:00
parent bb0633a8e7
commit 66696c5733
1 changed files with 7 additions and 1 deletions

View File

@ -140,6 +140,9 @@ class courseView():
def makeValidFilename(input_str): def makeValidFilename(input_str):
# Remove invalid characters # Remove invalid characters
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits) valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
input_str = input_str.replace("+"," ") # Canvas default for spaces
input_str = input_str.replace(":","-")
input_str = input_str.replace("/","-")
input_str = "".join(c for c in input_str if c in valid_chars) input_str = "".join(c for c in input_str if c in valid_chars)
# Remove leading and trailing whitespace # Remove leading and trailing whitespace
@ -150,9 +153,12 @@ def makeValidFilename(input_str):
def makeValidFolderPath(input_str): def makeValidFolderPath(input_str):
# Remove invalid characters # Remove invalid characters
valid_chars = "-_.()/ %s%s" % (string.ascii_letters, string.digits) valid_chars = "-_.()/ %s%s" % (string.ascii_letters, string.digits)
input_str = input_str.replace("+"," ") # Canvas default for spaces
input_str = input_str.replace(":","-")
input_str = input_str.replace("/","-")
input_str = "".join(c for c in input_str if c in valid_chars) input_str = "".join(c for c in input_str if c in valid_chars)
# Remove leading and trailing whitespace # Remove leading and trailing whitespace, separators
input_str = input_str.lstrip().rstrip().strip("/").strip("\\") input_str = input_str.lstrip().rstrip().strip("/").strip("\\")
# Replace path separators with OS default # Replace path separators with OS default