1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00
AdvLabDB/advlabdb/utils.py

67 lines
1.5 KiB
Python
Raw Normal View History

2021-04-01 12:08:42 +00:00
from random import choice
from string import digits, ascii_letters
def makeTable(headerAndDataList, rows, tableId="tab"):
2021-03-19 17:09:07 +00:00
def cellString(cell):
cell = str(cell)
2021-03-20 14:41:22 +00:00
if cell == "[]":
return "<em>None</em>"
excludeChars = """<>"'[]"""
for c in excludeChars:
if c in cell:
cell = cell.replace(c, "")
return cell
2021-03-19 17:09:07 +00:00
2021-03-19 15:30:02 +00:00
def td(cell):
return '<td>' + cellString(cell) + '</td>'
2021-03-19 15:30:02 +00:00
def th(cell):
return '<th data-sortable="true" data-field="' + titleToTemplate(cell) + '">' + cellString(cell) + '</th>'
2021-03-19 17:09:07 +00:00
table = '''<table
id="''' + tableId + '''"
2021-03-19 17:09:07 +00:00
data-classes="table table-bordered table-striped"
data-toggle="table"
data-thead-classes="table-dark"
data-search="true"
data-show-toggle="true"
data-show-columns="true"
data-click-to-select="true"
2021-03-19 17:09:07 +00:00
data-show-export="true"
data-export-types="['json', 'xml', 'csv', 'txt', 'sql', 'pdf']">
<thead>
<tr>
<th data-field="state" data-checkbox="true"></th>'''
2021-03-19 15:30:02 +00:00
for i in headerAndDataList:
table += th(i[0])
2021-03-19 17:09:07 +00:00
table += '''</tr>
</thead>
<tbody>\n'''
2021-03-19 15:30:02 +00:00
for row in rows:
table += '<tr><td></td>'
2021-03-19 15:30:02 +00:00
for i in headerAndDataList:
table += td(eval(i[1]))
table += '</tr>\n'
2021-03-19 17:09:07 +00:00
table += '''</tbody>
</table>
<br>
<hr>
<br>'''
2021-03-19 15:30:02 +00:00
return table
def appointmentDate(date):
return date.strftime("%a %d.%m.%Y")
2021-03-31 23:04:21 +00:00
def randomPassword():
2021-04-01 12:08:42 +00:00
return ''.join(choice(ascii_letters + digits) for i in range(12))
def titleToTemplate(page):
return page.lower().replace(" ", "_")