Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F56391378
mediawiki.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
mediawiki.py
View Options
# -------------------------------------------------------------
# Nasqueron Reports :: Formats :: MediaWiki
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Format report as MediaWiki table
# License: BSD-2-Clause
# -------------------------------------------------------------
from
datetime
import
date
def
read_as_str
(
value
):
if
type
(
value
)
==
bytes
:
return
value
.
decode
()
return
str
(
value
)
def
to_row
(
row
):
return
[
"|-"
,
"| "
+
" || "
.
join
(
read_as_str
(
val
)
for
val
in
row
)]
def
to_rows
(
rows
):
mediawiki_rows
=
[
to_row
(
row
)
for
row
in
rows
]
return
[
line
for
lines
in
mediawiki_rows
for
line
in
lines
]
def
to_table
(
report
,
options
):
"""Format query result as MediaWiki table."""
today
=
date
.
today
()
.
isoformat
()
lines
=
[
'{| class="wikitable sortable"'
,
f
"|+ {today} report"
,
"|-"
]
columns_map
=
options
.
get
(
"cols"
,
{})
headers
=
[
columns_map
.
get
(
c
,
c
)
for
c
in
report
.
headers
]
lines
.
append
(
"! "
+
" !! "
.
join
(
headers
))
lines
.
extend
(
to_rows
(
report
.
rows
))
lines
.
append
(
"|}"
)
return
"
\n
"
.
join
(
lines
)
File Metadata
Details
Attached
Mime Type
text/x-script.python
Expires
Sat, Nov 7, 17:41 (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4253021
Default Alt Text
mediawiki.py (1 KB)
Attached To
Mode
rRPRT Nasqueron internal reports
Attached
Detach File
Event Timeline
Log In to Comment