Skip to content

Commit 1dad790

Browse files
authored
Merge pull request #3 from LabKey/fb_buildcontent_26859
2 parents a510318 + 83f6537 commit 1dad790

13 files changed

+463
-816
lines changed

labkey/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
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
17-
from pkg_resources import get_distribution
16+
from labkey import query, experiment, utils
1817

19-
__title__ = get_distribution('labkey').project_name
20-
__version__ = get_distribution('labkey').version
18+
__title__ = 'labkey'
19+
__version__ = '0.4.2'
2120
__author__ = 'LabKey'
2221
__license__ = 'Apache License 2.0'

labkey/messageboard.py

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

labkey/unsupported/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# No content required

labkey/unsupported/messageboard.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
unsupported.messageboard
18+
~~~~~~~~~~~~~~~~
19+
WARNING: This module is not officially supported! Use at your own risk.
20+
21+
This module provides functions for interacting with Message Boards on the
22+
LabKey Server.
23+
"""
24+
from __future__ import unicode_literals
25+
from requests.exceptions import SSLError
26+
from labkey.utils import build_url
27+
28+
29+
def post_message(server_context, message_title, message_body, render_as, container_path=None):
30+
"""
31+
Post a message to a message board on a LabKey instance.
32+
:param server_context: A LabKey server context. See utils.create_server_context.
33+
:param message_title: The title of the message.
34+
:param message_body: The content of the message.
35+
:param render_as: The content of the message.
36+
:param container_path: Optional container path that can be used to override the server_context container path
37+
:return: Returns 1 if successful, 0 is post failed.
38+
"""
39+
# Build the URL for querying LabKey Server
40+
message_url = build_url(server_context, 'announcements', 'insert.api', container_path=container_path)
41+
42+
message_data = {
43+
'title': message_title,
44+
'body': message_body,
45+
'rendererType': render_as
46+
}
47+
48+
session = server_context['session']
49+
50+
try:
51+
message_response = session.post(message_url, message_data)
52+
except SSLError as e:
53+
print("There was problem while attempting to submit the message to " + str(e.geturl()) + ". The HTTP response code was " + str(e.getcode()))
54+
print("The HTTP client error was: " + format(e))
55+
return 0
56+
57+
return 1

0 commit comments

Comments
 (0)