sending e-mail in external methods
Hello everybody, I am a new zope user that has received an application to maintain and I'm learning about zope at the same time. One of the features of the app requires users to subscribe to receive a newsletter. A user is presented with a very simple form <form method="post" tal:attributes="action string:${here/absolute_url}/Register" metal:fill-slot="content"> Name: <input name="name" type="text" tal:attributes="value request/name|nothing"> <br /> <br /> Email address: <input name="email" type="text" tal:attributes="value request/email|nothing"> <br /> <br /> <input type="submit" name="add" value="Submit"> </form> The code for Register simply validates the input and calls a function defined in an external module to send an e-mail to the person sending the request, to verify ownership of the e-mail address. This code is something like: errors = [] name = form.get('name','').strip() email = form.get('email','').strip() if not context.validateForm(email, name): errors.append('- Problems occurred with input data') if errors: errors.insert(0,'The following problems require correcting:') return context.register_index(messages=errors) import md5 from Products.PythonScripts.standard import url_quote sendEmail(['%s <%s>' % (name,email)], None, 'Newsletter Registration Request', """ Thank you for requesting more information about our Newsletter. Blah, blah, blah. To complete your registration please click on the link below %s/register/Register2?email=%s&name=%s&hash=%s Once you have done so, you will receive an e-mail confirming your registration. If you have any problems please email %s """ % ( container.absolute_url(), url_quote(email), url_quote(name), md5.new('%s%s%sSomeHashHiddenPassword' % (url_quote(email),url_quote(name))).hexdigest(), container.email_from_address), '') return context.register_index(name=name, email=email, message="A confirmation email has been sent to the address you provided.") The problem I have is that the sendEmail() function always requires the user to be logged in as manager of the portal to work. Whenever I click on the "Submit" button, I am asked to log in and the code will only proceed after successful log in. The same happens with Register2 that also sends an e-mail to confirm successful registration. When the user receives the e-mail to confirm his data and clicks on the link, he gets added to the database successfully and he should be sent an e-mail. But again, that only happens if the user is logged in as manager. As I am new to zope I'm sure I'm missing on something important about external methods, can anyone help? Thanks in advance, Squig.
--On 8. Juli 2005 14:59:46 +0100 Susana Beatson <sbeatson@gmail.com> wrote:
As I am new to zope I'm sure I'm missing on something important about external methods, can anyone help?
In general you should not see and Unauthorized exception causing the popup username/password request. First you should try to install VerboseSecurity to figure out any unauthorized issues and second don't import anything from PythonScript product when using external methods. The Python Library has the same methods (see Python Library Reference). -aj
I am using arrays in Postgres. I need to be able to compare a string value in a specific position of a text array field (text[] is a field type in Postgres) against a variable(argument) I am passing to my query. I am only using parts of the query to illustrate the problem as the rest is irrelevant. I replaced the table, field names and arguments with names that might make this more understandable. First. I am finding arrays work fine with select statements in DTML when you use sqlvar to request a specific value from the array. ie. SELECT a_table.an_array_field[<dtml-sqlvar some_value type="int">][2] FROM ....(rest of query) But when you put them inside a sqltest tag for evaluating values it throws an error because DTML cannot parse it. ie. SELECT ... blah blah..... <dtml-and> <dtml-sqltest column=a_table.an_array_field[<dtml-sqlvar an_array_key type="int">][2] name=a_title_var op="eq" type="string" optional> ..... (rest of query) The issue is how to test against these values when DTML cannot parse them? My raw sql query works fine giving me the desired results but I cannot construct the statement in DTML. The part of the query that throws the error is the dtml-sqltest tag (it gives a parsing error). ie. <dtml-and> <dtml-sqltest column=a_db.an_array_field[<dtml-sqlvar an_array_key type="int">][2] name=a_title op="eq" type="string" optional> should translate to: AND a_table.an_array_field[1][2] = 'This is a title' (This is a valid expression for Postgres) where an_array_key is a variable with value of 1 and a_title is variable with a value of 'This is a title' The above would give an invalid attribute name error for the an_array_key (variable/argument). Is this a bug or is there something else I ought to be doing? If this is a limitation of DTML, is there a work around? Regards, David
You cannot embed one dtml tag within another dtml tag. A couple of possible work-arounds: 1) use a python script to return the values you need 2) create a python script which 'builds' a new dtml script and then execute the new script (ugly, but it works - not very efficient, so how often you run this will be a factor). hth Jonathan ----- Original Message ----- From: David Pratt To: zope@zope.org Sent: Friday, July 08, 2005 1:08 PM Subject: [Zope] DTML bug with database arrays in sqltest I am using arrays in Postgres. I need to be able to compare a string value in a specific position of a text array field (text[] is a field type in Postgres) against a variable(argument) I am passing to my query. I am only using parts of the query to illustrate the problem as the rest is irrelevant. I replaced the table, field names and arguments with names that might make this more understandable. First. I am finding arrays work fine with select statements in DTML when you use sqlvar to request a specific value from the array. ie. SELECT a_table.an_array_field[<dtml-sqlvar some_value type="int">][2] FROM ....(rest of query) But when you put them inside a sqltest tag for evaluating values it throws an error because DTML cannot parse it. ie. SELECT ... blah blah..... <dtml-and> <dtml-sqltest column=a_table.an_array_field[<dtml-sqlvar an_array_key type="int">][2] name=a_title_var op="eq" type="string" optional> ..... (rest of query) The issue is how to test against these values when DTML cannot parse them? My raw sql query works fine giving me the desired results but I cannot construct the statement in DTML. The part of the query that throws the error is the dtml-sqltest tag (it gives a parsing error). ie. <dtml-and> <dtml-sqltest column=a_db.an_array_field[<dtml-sqlvar an_array_key type="int">][2] name=a_title op="eq" type="string" optional> should translate to: AND a_table.an_array_field[1][2] = 'This is a title' (This is a valid expression for Postgres) where an_array_key is a variable with value of 1 and a_title is variable with a value of 'This is a title' The above would give an invalid attribute name error for the an_array_key (variable/argument). Is this a bug or is there something else I ought to be doing? If this is a limitation of DTML, is there a work around? Regards, David ------------------------------------------------------------------------------ _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Do you mean external methods with db api for 1)? I find I can use a plain statement like this in DTML ... but I cannot make it conditional. To bad you couldn't use ZPT instead to make ZSQL methods since it is XML or even some kind of XML schema just for making queries. It wouldn't have to be that rich to get pretty much all the SQL commands in it. You could embed as well this way so long as it validated. AND a_table.an_array_field[<dtml-sqlvar an_array_key type="int">][2] = <dtml-sqlvar an_array_key type="string"> For 2) I am not understanding how a new dtml will solve this? Regards, David On Friday, July 8, 2005, at 02:16 PM, Jonathan wrote:
You cannot embed one dtml tag within another dtml tag. A couple of possible work-arounds: 1) use a python script to return the values you need 2) create a python script which 'builds' a new dtml script and then execute the new script (ugly, but it works - not very efficient, so how often you run this will be a factor). hth Jonathan
David Pratt wrote at 2005-7-8 14:08 -0300:
... <dtml-and> <dtml-sqltest column=a_table.an_array_field[<dtml-sqlvar an_array_key type="int">][2] name=a_title_var op="eq" type="string" optional> ..... (rest of query)
The issue is how to test against these values when DTML cannot parse them?
You can emulate the "dtml-sqltest" with "dtml-if" and "dtml-sqlvar" (or "dtml-var"). -- Dieter
This workaround is an excellent solution! I am doing: <dtml-if an_arg> and a_table.an_array_fieldt[<dtml-sqlvar an_array_key type=int>][2] = <dtml-sqlvar a_title type=string> </dtml-if> and just insert above any optional statements. Many thanks Dieter !!!! Regards, David On Sunday, July 10, 2005, at 06:59 PM, Dieter Maurer wrote:
David Pratt wrote at 2005-7-8 14:08 -0300:
... <dtml-and> <dtml-sqltest column=a_table.an_array_field[<dtml-sqlvar an_array_key type="int">][2] name=a_title_var op="eq" type="string" optional> ..... (rest of query)
The issue is how to test against these values when DTML cannot parse them?
You can emulate the "dtml-sqltest" with "dtml-if" and "dtml-sqlvar" (or "dtml-var").
-- Dieter
How about setting the proxy role of your Register script to 'Manager'? (to allow Register to invoke your external method) Jonathan ----- Original Message ----- From: "Susana Beatson" <sbeatson@gmail.com> To: <zope@zope.org> Sent: Friday, July 08, 2005 9:59 AM Subject: [Zope] sending e-mail in external methods
Hello everybody, I am a new zope user that has received an application to maintain and I'm learning about zope at the same time. One of the features of the app requires users to subscribe to receive a newsletter. A user is presented with a very simple form <form method="post" tal:attributes="action string:${here/absolute_url}/Register" metal:fill-slot="content"> Name: <input name="name" type="text" tal:attributes="value request/name|nothing"> <br /> <br /> Email address: <input name="email" type="text" tal:attributes="value request/email|nothing"> <br /> <br /> <input type="submit" name="add" value="Submit"> </form>
The code for Register simply validates the input and calls a function defined in an external module to send an e-mail to the person sending the request, to verify ownership of the e-mail address. This code is something like:
errors = [] name = form.get('name','').strip() email = form.get('email','').strip() if not context.validateForm(email, name): errors.append('- Problems occurred with input data') if errors: errors.insert(0,'The following problems require correcting:') return context.register_index(messages=errors)
import md5 from Products.PythonScripts.standard import url_quote
sendEmail(['%s <%s>' % (name,email)], None, 'Newsletter Registration Request', """ Thank you for requesting more information about our Newsletter. Blah, blah, blah. To complete your registration please click on the link below
%s/register/Register2?email=%s&name=%s&hash=%s
Once you have done so, you will receive an e-mail confirming your registration.
If you have any problems please email %s """ % ( container.absolute_url(), url_quote(email), url_quote(name), md5.new('%s%s%sSomeHashHiddenPassword' % (url_quote(email),url_quote(name))).hexdigest(), container.email_from_address), '')
return context.register_index(name=name, email=email, message="A confirmation email has been sent to the address you provided.")
The problem I have is that the sendEmail() function always requires the user to be logged in as manager of the portal to work. Whenever I click on the "Submit" button, I am asked to log in and the code will only proceed after successful log in. The same happens with Register2 that also sends an e-mail to confirm successful registration. When the user receives the e-mail to confirm his data and clicks on the link, he gets added to the database successfully and he should be sent an e-mail. But again, that only happens if the user is logged in as manager. As I am new to zope I'm sure I'm missing on something important about external methods, can anyone help? Thanks in advance, Squig. _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Susana Beatson wrote at 2005-7-8 14:59 +0100:
... The problem I have is that the sendEmail() function always requires the user to be logged in as manager of the portal to work.
What type of object is "sendEmail"? Have you (carefully) looked at the traceback (in your "error_log" object -- you need to reconfigure it in order not to discard "Unauthorized")? -- Dieter
participants (5)
-
Andreas Jung -
David Pratt -
Dieter Maurer -
Jonathan -
Susana Beatson