Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12297788
mediawiki.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
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
(
columns_names
,
rows
,
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
columns_names
]
lines
.
append
(
"! "
+
" !! "
.
join
(
headers
))
lines
.
extend
(
to_rows
(
rows
))
lines
.
append
(
"|}"
)
return
"
\n
"
.
join
(
lines
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Wed, Oct 22, 13:18 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3089918
Default Alt Text
mediawiki.py (1 KB)
Attached To
Mode
rRPRT Nasqueron internal reports
Attached
Detach File
Event Timeline
Log In to Comment