refactor utils file and move MAX_LEN parameter into config file

This commit is contained in:
Maximilian Keßler 2021-09-16 15:27:35 +02:00
parent 13b4852051
commit 7cbb6ea389
2 changed files with 6 additions and 2 deletions

View file

@ -20,3 +20,4 @@ LOCALE = "de_DE.utf8"
COURSE_IGNORE_FILE = '.courseignore' COURSE_IGNORE_FILE = '.courseignore'
COURSE_INFO_FILE = 'info.yaml' COURSE_INFO_FILE = 'info.yaml'
DEFAULT_MASTER_FILE_NAME = 'master.tex' DEFAULT_MASTER_FILE_NAME = 'master.tex'
MAX_LEN = 40

View file

@ -1,14 +1,17 @@
from config import MAX_LEN
def beautify(string): def beautify(string):
return string.replace('_', ' ').replace('-', ' ').title() return string.replace('_', ' ').replace('-', ' ').title()
def unbeautify(string): def unbeautify(string):
return string.replace(' ', '-').lower() return string.replace(' ', '-').lower()
MAX_LEN = 40
def generate_short_title(title): def generate_short_title(title):
short_title = title or 'Untitled' short_title = title or 'Untitled'
if len(title) >= MAX_LEN: if len(title) >= MAX_LEN:
short_title = title[:MAX_LEN - len(' ... ')] + ' ... ' short_title = title[:MAX_LEN - len(' ... ')] + ' ... '
short_title = short_title.replace('$', '') short_title = short_title.replace('$', '')
return short_title return short_title