newbie help ?
Beanie
nospam at diving.ukdiver.com
Thu May 15 10:42:40 EDT 2003
I have the code below which is supposed to run in plone to pull a code out
of a text file and mail it to a person, it dosen't work and i don't know
why. It dosn't help that I don't really no how to cofe in python i'm more of
a c/vb/asp/ada person. i've been loking throught the net for any online
tutorials / resources and ahven't found a lot that was helpful. anybody
sugest
a) what is wrong witht hescript - got to be something simple most of it is
hacked from examples
b) where to get good resources on python scripting
ta
# Example code:
# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE = request.RESPONSE
referer = request.came_from
if request.from_addr == '':
RESPONSE.redirect( '%s?portal_status_message=%s' % ( referer, "You have
not entered your E-Mail address" ) )
return
file=open("codes.txt",'r+') #open the file
strCode=file.readlines() # read all of the file into a list
strDiscountCode = strCode.pop(0) #get one code
if strDiscountCode =="": #if its null we run out so mail me
mail_text = context.comments_template(
from_name = " Discount Codes",
from_addr = "codes at domain",
who = "me at me",
comments = request.from_addr , "tried for a code but we run out.")
host = context.MailHost
host.send( mail_text )
RESPONSE.redirect( '%s?portal_status_message=%s' % ( referer, "Sorry we
have temporarily run out of codes one will be sent as soon as
possible!" ) );
else: # else send them the code
mail_text = context.comments_template(
from_name = "Discount Codes",
from_addr = "codes at domain",
who = request.from_addr,
comments = "Your Discount code is:" & strDiscountCode & ".")
host = context.MailHost
host.send( mail_text )
RESPONSE.redirect( '%s?portal_status_message=%s' % ( referer, "Your
discount code has been sent. Thank you." ) );
file.writelines(strCodes) #rewrite the file with missing code
file.close()# close the file
--
Beanie
"Fear is the path to the dark side! Fear leads to anger, anger leads to
hate, hate leads to suffering!"
"There is no Emotion, there is Peace.
There is no Ignorance, there is Knowledge.
There is no Passion, there is Serenity.
There is no Death, there is the Force"
More information about the Python-list
mailing list