Using Classes in Python scripts
Hi, I just want to hold some data structures in the session data. The application I want to write gatheres data from a database according to several options which can be set in a several step menu system. I have to keep track to the options. After reading /Examples/ShoppingCart of the Zope hierarchy I tried to adopt this scheme of data tagged by keys in the session data but I found out that I lost overview about this stuff if I would dive deeper into the data structure I would need. I thought I would find the solution in defining my own class variables and found out that this is not possible in Python scripts for security reasons. Next I tried External Python methods but I've got strange effects with this approach and I think it would not work as well. I thought I would find the solution at http://www.zopelabs.com/cookbook/991933953 but I just got an error right in the first line of the example code: Zope has encountered an error while publishing this resource. Error Type: ImportError Error Value: import of "Products.PythonScripts.Utility" is unauthorized So I have two questions: 1. Is this the right approach to accumulate several data in the session variable even if there is a more complex menu structure of options which are sometimes dependand one from some others. 2. If yes what is the best way to get this working. Kind regards Andreas.
Andreas Tille writes:
... defining classes ... Next I tried External Python methods but I've got strange effects with this approach Which effects. This should work (I sometimes do it), but for simple cases, I prefer dictionaries. An alternative would be "PersistentMapping". ... 1. Is this the right approach to accumulate several data in the session variable even if there is a more complex menu structure of options which are sometimes dependand one from some others. The session object is global. Thus, it is a very good idea to use application specific namespaces to avoid name clashes.
I like subobjects for this approach also it makes life a bit more difficult (we must explicitly tell the session that it changed when we modified the subobject unless the subobject is persistent itself). An alternative would be to use hierarchical keys.
2. If yes what is the best way to get this working. I usually use nested dictionaries with special precaution to tell the session when it has changed.
Dieter
participants (2)
-
Andreas Tille -
Dieter Maurer