from random import choice
from string import digits, ascii_letters
from flask_security import current_user
from advlabdb.models import Semester
def makeTable(headerAndDataList, rows, tableId="table"):
def cellString(cell):
cell = str(cell)
if cell == "[]":
return "None"
excludeChars = """<>"'[]"""
for c in excludeChars:
if c in cell:
cell = cell.replace(c, "")
return cell
def td(cell):
return '
' + cellString(cell) + ' | '
def th(cell):
return '' + cellString(cell) + ' | '
table = '''
| '''
for i in headerAndDataList:
table += th(i[0])
table += '''
\n'''
for row in rows:
table += ' | '
for i in headerAndDataList:
table += td(eval(i[1]))
table += '
\n'
table += '''
'''
return table
def appointmentDate(date):
return date.strftime("%a %d.%m.%Y")
def randomPassword():
return ''.join(choice(ascii_letters + digits) for i in range(12))
def titleToTemplate(page):
return page.lower().replace(" ", "_")
def userActiveSemester():
lastSemesterId = Semester.query.all()[-1].id
if current_user.active_semester_id is None:
current_user.active_semester_id = lastSemesterId
elif current_user.active_semester_id != lastSemesterId:
activeSemester = Semester.query.get(current_user.active_semester_id)
if activeSemester:
flash(f"You are in the old semester {activeSemester.label}!", "warning")
else:
flash(f"Semester changed!", "warning")
current_user.active_semester_id = lastSemesterId
return Semester.query.get(current_user.active_semester_id)