# 1st Profile for Example 9--Message board
#
# WebKeystone profile that displays all the messages in the
# wkMessageBoard application.
#
#
#
# Read in message board information.
DB_READ 'database/' + 'messageInfo.dat'
count
messages
# If this is the first time setting up the message board.
IF not exist('count')
LOCK 'wkMessageBoard'
count = 0
messages = {'id':[],'parent':[],'email':[],'subject':[],'message':[],'date':[],'timestamp':[]}
DB_WRITE 'database/' + 'messageInfo.dat'
count
messages
# Build a tree
messageTree = tree(messages['id'],messages['parent'],messages['subject'],messages['email'],messages['date'])
# Return the endfile.
RETURN 'examples/example9showMessages.htm'
treeTemplate = '%(map)s %(2)s
%(3)s %(4)s \n'
indent = " " * 4
mapping = messageTree.map(indent, indent, indent, indent)
template = {"_item":treeTemplate,"UserID":UserID, "map":mapping}
#------------------------
Example 9 Message Board
Example 9 Message Board
RELOAD
Click your "Back" button to return to Example 9.
# examples/example9viewMessage.prof
#
# This profile displays a message in the wkMessageBoard tool.
#
#
#
# Read in message information.
DB_READ 'database/' + 'messageInfo.dat'
messages
# Get the index of the message that we're looking for.
index = messages['id'].index(id)
# Retrieve the message information.
subject = messages['subject'][index]
email = messages['email'][index]
date = messages['date'][index]
# Get the 'message' contents'
DB_READ 'database/' + str(id) + '.dat'
message
# Put together the reply message.
formattedMessage = f.string.splitfields(message, ' \n')
formattedMessage = f.string.joinfields(map(lambda x : '>' + x, formattedMessage), '\n')
# Return the endfile.
RETURN 'examples/example9viewMessage.htm'
# examples/example9addMessage.prof
#
# This Profile adds a message to the Webkeystone Message
# board.
#
IF MissingReq
RETURN RAW 'Please go back and complete all the fields correctly'
# Get the current time - one in a 'pleasant' human viewable form,
# and another in a timestamp form that can be used for comparing times.
niceNow = f.time.strftime('%m/%d/%Y %H:%M', f.time.localtime(f.time.time()))
now = f.time.strftime('%Y%m%d%H%M%S', f.time.localtime(f.time.time()))
# Make sure the message information is 'HTML SAFE'. This means
# removing any tags that could distort how the message will look in a
# browser.
message = f.string.replace(message, '\015\012', '\n')
message = f.string.replace(message, '\015', '\n')
message = f.string.replace(message, '<', '<')
message = f.string.replace(message, '>', '>')
message = f.string.replace(message, '\n', ' \n')
subject = f.string.replace(subject, '<', '<')
subject = f.string.replace(subject, '>', '>')
email = f.string.replace(email, '<', '<')
email = f.string.replace(email, '>', '>')
# Get the current messages.
LOCK 'wkMessageBoard'
DB_READ 'messageInfo.dat'
count
messages
# Add the new message to the current messages.
count = count + 1
dummy = messages['id'].append(count)
dummy = messages['parent'].append(parent)
dummy = messages['subject'].append(subject)
dummy = messages['email'].append(email)
dummy = messages['date'].append(niceNow)
dummy = messages['timestamp'].append(now)
# Write the message board information out.
DB_WRITE 'messageInfo.dat'
count
messages
# Write the new message information out.
DB_WRITE str(count) + '.dat'
message
# Go back and display the tree of messages.
CALL 'examples/example9showMessages.prof'
|