Re: [Zope] converting Dictionary to Result
Alric Aneron wrote: > Hello, > I have a dictionary object and a result set object (that was returned > from a ZSQL method). Is there any way I can merge them into one > variable and use them in a dtml-in statement? You should know which one should update which one. So assuming your dictionary has to override/extent attributes returned from ZSQL-Methods, you can write res=context.yourZSQLMethod(args...).dictionaries() # see API docs for item in res: item.update(yourdictionary) return res thats all. The other way round could be: res=context.yourZSQLMethod(args...).dictionaries() return [dict(yourdictionary,**item) for item in res] (see python docs about list comprehension and function argument forms) Regards Tino ___ 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 )
Re: [Zope] dictionary from sequence-item
Alric Aneron wrote: Hello, I am looping through a list of dictionary objects using and within the dtml-in body I have: Some of the dictionaries in the list don't have 'titled' key so it should replace it with the word "none", but it gives me an error Error Type: KeyError Error Value: 'titled' I don't understand. Another option is that I can use but it doesn't work, says has_key is an unknown attribute. This is the stupidest thing ever! it's a dictionary object! I try to typecast it using the dict(_.getitem('sequence-item')).has_key('titled') it gives me an error saying it can't typecast, but I am 100% sure it's a dictionary object because I can access it easily _.getitem('sequence-item')['titled'] for those that have that key. Any idea how I can check if the titled key is in the dictionary for the current list item? Thanks in advance guys! Alric, Your earlier post indicated that your DTML obtains the sequence of dictionaries from a python script - and *then* tries to filter it and process it. Why not do your filtering, e.g. appending only thoses values that have a key == 'key1' in your python script first? Thats why "god" invented python scripts :-) . And as Jonathan indicated, you should also simplify the list returned. I would just return a list of filtered values, e.g. # --- # python script (based on your earlier message) # --- # DTML call to this script can pass these as parameters or obtain them from the request ... mydict = {'key1': 'value1', 'key2': 'value2'} mydict2 = {'key1': 'value3', 'key2': 'value4'} desired_key = 'key1' #results bucket finalList = [] for dict in (mydict,mydict2): # we avoid returning list of dictionaries which can be awkward in DTML for k in dict.keys(): if k == desired_key: # <--- filter it here so DTML doesn't have to finalList.append( dict[ k ] ) return finalList Now your DTML is simple. 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 )
Re: [Zope] dictionary from sequence-item
Thanks,I tried your suggestion Jonathan and I get this:Error Type: AttributeError Error Value: has_keyThanks anyway.I never used ZPT, I'm not sure how to approach it from that angle...would it be easy to do? (You mean tal and metal right?)Anyone have any other suggestions?ThanksJonathan <[EMAIL PROTECTED]> wrote: It might make your life easier if you used a dtml-let (WARNING: untested): do something here But this is still pretty ugly. Another approach would be to clean up the data in your list/dicts within the python script, before you get to the dtml method. Jonathan - Original Message -From:AlricAneronTo: zope@zope.orgSent: Monday, June 19, 2006 2:46 PM Subject: [Zope] dictionary fromsequence-item Hello,I am looping through a list of dictionary objectsusing and within the dtml-in body I have:Some of thedictionaries in the list don't have 'titled' key so it should replace it withthe word "none", but it gives me an errorError Type: KeyErrorError Value: 'titled'I don'tunderstand. Another option is that I can use but it doesn't work, sayshas_key is an unknown attribute. This is the stupidest thing ever! it'sa dictionary object!I try to typecast it using thedict(_.getitem('sequence-item')).has_key('titled') it gives me an error sayingit can't typecast, but I am 100% sure it's a dictionary object because I canaccess it easily _.getitem('sequence-item')['titled'] for those that have thatkey.Any idea how I can check if the titled key is in the dictionaryfor the current list item?Thanks in advance guys! Yahoo!Messenger with Voice. PC-to-Phone calls for ridiculously low rates. ___Zope maillist - Zope@zope.orghttp://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) Love cheap thrills? Enjoy PC-to-Phone calls to 30+ countries for just 2¢/min with Yahoo! Messenger with Voice.___ 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 )
Re: [Zope] dictionary from sequence-item
It might make your life easier if you used a dtml-let (WARNING: untested): do something here But this is still pretty ugly. Another approach would be to clean up the data in your list/dicts within the python script, before you get to the dtml method. Jonathan - Original Message - From: Alric Aneron To: zope@zope.org Sent: Monday, June 19, 2006 2:46 PM Subject: [Zope] dictionary from sequence-item Hello,I am looping through a list of dictionary objects using and within the dtml-in body I have:Some of the dictionaries in the list don't have 'titled' key so it should replace it with the word "none", but it gives me an errorError Type: KeyErrorError Value: 'titled'I don't understand. Another option is that I can use but it doesn't work, says has_key is an unknown attribute. This is the stupidest thing ever! it's a dictionary object!I try to typecast it using the dict(_.getitem('sequence-item')).has_key('titled') it gives me an error saying it can't typecast, but I am 100% sure it's a dictionary object because I can access it easily _.getitem('sequence-item')['titled'] for those that have that key.Any idea how I can check if the titled key is in the dictionary for the current list item?Thanks in advance guys! Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates. ___Zope maillist - Zope@zope.orghttp://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 ) ___ 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 )
[Zope] dictionary from sequence-item
Hello,I am looping through a list of dictionary objects using and within the dtml-in body I have:Some of the dictionaries in the list don't have 'titled' key so it should replace it with the word "none", but it gives me an errorError Type: KeyError Error Value: 'titled' I don't understand. Another option is that I can use but it doesn't work, says has_key is an unknown attribute. This is the stupidest thing ever! it's a dictionary object!I try to typecast it using the dict(_.getitem('sequence-item')).has_key('titled') it gives me an error saying it can't typecast, but I am 100% sure it's a dictionary object because I can access it easily _.getitem('sequence-item')['titled'] for those that have that key.Any idea how I can check if the titled key is in the dictionary for the current list item?Thanks in advance guys! Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.___ 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 )
Re: [Zope] converting Dictionary to Result
You could try something like: contents of myscript():mydict = {'key1': 'value1', 'key2': 'value2'}mydict2 = {'key1': 'value3', 'key2': 'value4'} rList = [] for item in mydict.keys(): rList.append( (item, mydict1[item]) )for item in mydict2.keys(): rList.append( (item, mydict2[item]) )return rList then, in your DTML method: , Jonathan - Original Message - From: Alric Aneron To: Andreas Jung ; zope@zope.org Sent: Monday, June 19, 2006 12:35 PM Subject: Re: [Zope] converting Dictionary to Result Thanks,Here is what I'm trying to do:Let's say:contents of myscript():mydict = {'key1': 'value1', 'key2': 'value2'}mydict2 = {'key1': 'value3', 'key2': 'value4'}finalList = [mydict, mydict2]return finalListWhen I do this in a dtml-method: This will not return me this:value1value2It gives me a key error.However if I loop through a recordset, it produces proper output.I'd like to merge a record object and a dictionary object so I can access them like I showed you here with dtml-in - so I can loop over both of them.Is there a way?Thanks in advance guys!Andreas Jung <[EMAIL PROTECTED]> wrote: --On 19. Juni 2006 09:16:23 -0700 Alric Aneron <[EMAIL PROTECTED]>wrote:> Hello,> I have a dictionary object and a result set object (that was returned> from a ZSQL method). Is there any way I can merge them into one variable> and use them in a dtml-in statement?>result sets have a dictionaries() method and dict have an update() method..everything else is one-liner-Python magic and depends on your usecase.-aj-- ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 T�bingen - GermanyWeb: www.zopyx.com - Email: [EMAIL PROTECTED] - Phone +49 - 7071 - 793376E-Publishing, Python, Zope & Plone development, Consulting Yahoo! Sports Fantasy Football 06 - Go with the leader. Start your league today! ___Zope maillist - Zope@zope.orghttp://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 ) ___ 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 )
Re: [Zope] converting Dictionary to Result
Thanks,Here is what I'm trying to do:Let's say:contents of myscript():mydict = {'key1': 'value1', 'key2': 'value2'}mydict2 = {'key1': 'value3', 'key2': 'value4'}finalList = [mydict, mydict2]return finalListWhen I do this in a dtml-method: This will not return me this:value1value2It gives me a key error.However if I loop through a recordset, it produces proper output.I'd like to merge a record object and a dictionary object so I can access them like I showed you here with dtml-in - so I can loop over both of them.Is there a way?Thanks in advance guys!Andreas Jung <[EMAIL PROTECTED]> wrote: --On 19. Juni 2006 09:16:23 -0700 Alric Aneron <[EMAIL PROTECTED]> wrote:> Hello,> I have a dictionary object and a result set object (that was returned> from a ZSQL method). Is there any way I can merge them into one variable> and use them in a dtml-in statement?>result sets have a dictionaries() method and dict have an update() method..everything else is one-liner-Python magic and depends on your usecase.-aj-- ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 T�bingen - GermanyWeb: www.zopyx.com - Email: [EMAIL PROTECTED] - Phone +49 - 7071 - 793376E-Publishing, Python, Zope & Plone development, Consulting Yahoo! Sports Fantasy Football 06 - Go with the leader. Start your league today! ___ 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 )
Re: [Zope] converting Dictionary to Result
--On 19. Juni 2006 09:16:23 -0700 Alric Aneron <[EMAIL PROTECTED]> wrote: Hello, I have a dictionary object and a result set object (that was returned from a ZSQL method). Is there any way I can merge them into one variable and use them in a dtml-in statement? result sets have a dictionaries() method and dict have an update() method..everything else is one-liner-Python magic and depends on your usecase. -aj -- ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany Web: www.zopyx.com - Email: [EMAIL PROTECTED] - Phone +49 - 7071 - 793376 E-Publishing, Python, Zope & Plone development, Consulting pgpo87SQUikt8.pgp Description: PGP signature ___ 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 )
[Zope] converting Dictionary to Result
Hello,I have a dictionary object and a result set object (that was returned from a ZSQL method). Is there any way I can merge them into one variable and use them in a dtml-in statement?Thanks in advance. Yahoo! Sports Fantasy Football 06 - Go with the leader. Start your league today! ___ 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 )
[Zope] load balancing ftp over ZEO clients
Hi, We have an intranet that has a ZEO setup. For http and webdav there are even fronproxies installed which are loadbalanced though a Alteon server. (yes it is kind of an overkill setup but we wanted to get some experience with such a setup for future projects). We now would like to rollout ftp acces for the users that cannot use webdav for some reason. Has anyone experiences with load balancing ftp over several ZEO clients? What are the todo's and todont's? Can I forward both port 20 and 21 to the ftp port of the ZEO? Is it possible to use passive and active ftp? Thanks, -- __ "Nothing is as subjective as reality" Reinoud van Leeuwen[EMAIL PROTECTED] http://www.xs4all.nl/~reinoud __ ___ 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 )
[Zope] Re: SSL Redirect for CookieCrumbler
Hi Chris, I need to redirect all my http requests to the login_form of the CookieCrumble to https, so, I wrote this rule in apache: Why bother? Just because the form is secure doesn't make cookie authentication any more secure. Yes, you're right. That is exactly the conclusion I also figured out after finding an interesting article in plone.org, which talks about this: * Secure login without plain text passwords http://plone.org/documentation/how-to/secure-login-without-plain-text-passwords The only Problem is that the product mentioned there, SessionCrumbler, is based on the CMF CookieCrumbler and not the Standalone version. I guess it wouldn't be difficult to port; I even tried it by replacing the CMF imports by the Standalone version, but it didn't work. Zope hangt and I even didn't get a TraceBack. Anyway, I'm not going to spend more time trying to get this working. I will perhaps try to do some patch to the basic http authentication like CookieCrumbler does, but instead of showing the login forms, I want to do a redirect if the request is insecure, so, you will still get the popup window, but in https. Do you say in https once authenticated? Yes, the problem, if you read my post was that with the apache RewriteRule, I could authenticated myself in ssl, but after that the browser took me back again to http -> See the article; it exposes clearly the problem. Regards Josef ___ 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 )
Re: [Zope] SSL Redirect for CookieCrumbler
Josef Meile wrote: I need to redirect all my http requests to the login_form of the CookieCrumble to https, so, I wrote this rule in apache: Why bother? Just because the form is secure doesn't make cookie authentication any more secure. Do you say in https once authenticated? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ 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 )
Re: [Zope] acl_users in MySQL
Cliff Ford wrote: Suggestion: have a look at exUserFolder. It has a MySQL Authentication Source. The minimum requirement is a table with Username, Password and Roles fields. I think you'll actually find SimpleUserFolder much easier and more flexible for this specific requirement: http://www.simplistix.co.uk/software/zope/simpleuserfolder cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ 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 )
Re: [Zope] questions on multilingual sites
John Schinnerer wrote: Can additional language support be added in later, or is it necessary to build it all in from the start (even if not used yet)? Once you've done it properly for one language, all you need to do is add in more translations. Doing thefirst one you can do at any point in the project, but you might make your end result more i18n-friendly if you do it that way from the start.. What are the basic docs/tutorials/howtos I should look at to start understanding how zope language support works and how to best apply/use it? Umm, yeah, Five has some docs, *waves hands in air* ummm... ...yeah, this stuff isn't really documented coherently in one place. Philipp's Zope 3 book isn't a bad place to start, though, since nowadays you really want to be using Zope 3's i18n via Five in Zope 2 rather than any of the horrific existing i18n solutions for Zope 2. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ 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 )
Re: [Zope] data type
On 6/19/06, George <[EMAIL PROTECTED]> wrote: On 6/19/06, Andreas Jung < [EMAIL PROTECTED]> wrote: --On 19. Juni 2006 15:11:42 +0300 George <[EMAIL PROTECTED]> wrote:> How can I find a variable's data type in dtml? >> Sorry if it's sth obvious, thx in advance! There is only the same_type() method available. Perhaps instance() butyou can't use the type() method of Python for security reasons.The Zope Book should explain the usage of same_type().-aj OK, perfect! I have done it before, but bad memory :)Thx for your quick response! I wonder what are the security reasons... :) ___ 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 )
Re: [Zope] data type
On 6/19/06, Andreas Jung <[EMAIL PROTECTED]> wrote: --On 19. Juni 2006 15:11:42 +0300 George <[EMAIL PROTECTED]> wrote:> How can I find a variable's data type in dtml?>> Sorry if it's sth obvious, thx in advance! There is only the same_type() method available. Perhaps instance() butyou can't use the type() method of Python for security reasons.The Zope Book should explain the usage of same_type().-aj OK, perfect! I have done it before, but bad memory :)Thx for your quick response! ___ 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 )
Re: [Zope] data type
--On 19. Juni 2006 15:11:42 +0300 George <[EMAIL PROTECTED]> wrote: How can I find a variable's data type in dtml? Sorry if it's sth obvious, thx in advance! There is only the same_type() method available. Perhaps instance() but you can't use the type() method of Python for security reasons. The Zope Book should explain the usage of same_type(). -aj pgpRjQIVn5d8T.pgp Description: PGP signature ___ 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 )
[Zope] data type
How can I find a variable's data type in dtml? Sorry if it's sth obvious, thx in advance! ___ 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 )
Re: [Zope] manage_changeProperties has strange side effect on response Content-Type.
On Friday 16 June 2006 20:28, Dieter Maurer wrote: > Gaute Amundsen wrote at 2006-6-16 13:05 +0200: > >All my pages normally have a content-type of ISO-8859-1 > >I have not spent much thought on this, it has just worked nicely like > > that. > > > >Today I had a page that called a python script, that even when I made it > >return an empty string, changed the content-type of my page to utf-8. > > > >I finally tracked it down to this difference: > > > >item.manage_changeProperties({'title':'Hustype'})gives utf-8. > > "manage_changeProperties" has two usage modes: one for programmatic > use and one for ZMI use. As many other management functions, > it distinquishes between the two mode by checking whether > "REQUEST" is "None". When used from the ZMI, the ZPublisher > passes in "REQUEST" which therefore is not None. > > You passed a positional argument to "manage_changeProperties" > which it interprets as "REQUEST". Therefore, it thinks it were > used from the ZMI and uses the "management_charset" (or something > like that) as encoding. > > Use "manage_changeProperties(**dict)" instead of > "manage_changeProperties(dict)" to avoid this problem. Makes perfect sense when you put it like that, I guess. But I woluld never have guessed it from reading the APIdoc... I would have liked to ad a comment about this in the doc, but that function seems to be out of order for both FF, and Opera. Thanks anyway. Gaute ___ 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 )