Skip to content

Commit 88ad04c

Browse files
Spec 26859: Build content reporting
-- Re-enable wiki and messageboard modules but only as explicitly unsupported modules -- Update wiki and messageboard to run under Python 3 (not re-tested under Python 2, probably won't work) -- Changed internals of wiki and messageboard to be more like query and experiment (like using server_context) -- Various other cleanups
1 parent a510318 commit 88ad04c

File tree

5 files changed

+260
-605
lines changed

5 files changed

+260
-605
lines changed

labkey/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
from labkey import query, experiment, utils # wiki, messageboard
16+
from labkey import query, experiment, utils
17+
import labkey.unsupported.wiki, labkey.unsupported.messageboard
1718
from pkg_resources import get_distribution
1819

1920
__title__ = get_distribution('labkey').project_name

labkey/messageboard.py

Lines changed: 0 additions & 271 deletions
This file was deleted.

labkey/unsupported/messageboard.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#
2+
# Copyright (c) 2015-2016 LabKey Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
"""
17+
WARNING: This module is not officially supported! Use at your own risk.
18+
19+
############################################################################
20+
NAME:
21+
LabKey Message Board API
22+
23+
SUMMARY:
24+
This module provides functions for interacting with Message Boards on the
25+
LabKey Server.
26+
27+
DESCRIPTION:
28+
This module is designed to simply programmatic editing of wikis and posting messages
29+
to Message Boards/Forums on the LabKey Server
30+
31+
Documentation:
32+
LabKey Python API:
33+
https://www.labkey.org/wiki/home/Documentation/page.view?name=python
34+
35+
Setup, configuration of the LabKey Python API:
36+
https://www.labkey.org/wiki/home/Documentation/page.view?name=setupPython
37+
38+
Using the LabKey Python API:
39+
https://www.labkey.org/wiki/home/Documentation/page.view?name=usingPython
40+
41+
Documentation for the LabKey client APIs:
42+
https://www.labkey.org/wiki/home/Documentation/page.view?name=viewAPIs
43+
44+
Support questions should be directed to the LabKey forum:
45+
https://www.labkey.org/announcements/home/Server/Forum/list.view?
46+
47+
48+
############################################################################
49+
"""
50+
51+
from labkey.utils import build_url, handle_response
52+
from requests.exceptions import SSLError
53+
54+
55+
def postMessage(server_context, messageTitle, messageBody, renderAs, container_path=None):
56+
"""
57+
############################################################################
58+
postMessage()
59+
60+
postMessage() can be used to post a message to a message board on the LabKey Server
61+
62+
The following are the minimum required params:
63+
64+
myresults = labkeyApi.postMessage(
65+
baseUrl = 'https://hosted.labkey.com',
66+
containerPath = 'PythonProject',
67+
messageTitle = 'Message Title',
68+
messageBody = 'This is the content of my message ....',
69+
renderAs = 'HTML')
70+
71+
The function will return the integer 1 for success and the integer 0 if the message post fails
72+
73+
----------------------------------------------------------------------------
74+
Test Code:
75+
76+
[NOT AVAILABLE]
77+
78+
############################################################################
79+
"""
80+
81+
# Build the URL for querying LabKey Server
82+
message_url = build_url(server_context, 'announcements', 'insert.api', container_path=container_path)
83+
84+
message_data = {
85+
'title': messageTitle,
86+
'body': messageBody,
87+
'rendererType': renderAs
88+
}
89+
90+
session = server_context['session']
91+
data = None
92+
93+
try:
94+
message_response = session.post(message_url, message_data, headers=None) # seems to be happy with Python dict directly
95+
except SSLError as e:
96+
print("There was problem while attempting to submit the message to " + str(e.geturl()) + ". The HTTP response code was " + str(e.getcode()))
97+
print("The HTTP client error was: "+ format(e))
98+
return(1)
99+
100+
return(0)

0 commit comments

Comments
 (0)