|
[Webware-devel] Questions about actions handling in Page
From: <radek@lu...> - 2005-04-19 10:20
|
Why we want to have _actionSet() method in class Page?
Class Page(HTTPServlet):
(...)
def _respond(self, transaction):
req =3D transaction.request()
=20
if self.transaction().application().setting('OldStyleActions', ) =
\
and req.hasField('_action_'):
(*) action =3D self.methodNameForAction(req.field('_action_'))
actions =3D self._actionSet()
(*) if actions.has_key(action):
self.preAction(action)
apply(getattr(self, action), (transaction,))
self.postAction(action)
return
else:
raise PageError, "Action '%s' is not in the public list=20
of actions, %s, for %s." % (action, actions.keys(), self)
for action in self.actions():
if req.hasField('_action_%s' % action) or \
req.field('_action_', None) =3D=3D action or \
(req.hasField('_action_%s.x' % action) and \
req.hasField('_action_%s.y' % action)):
(**) if self._actionSet().has_key(action):
self.handleAction(action)
return
def _actionSet(self):
if not hasattr(self, '_actionDict'):
self._actionDict =3D {}
for action in self.actions():
(***) self._actionDict[action] =3D 1
return self._actionDict
def handleAction(self, action):
self.preAction(action)
getattr(self, action)()
self.postAction(action)
def methodNameForAction(self, name):
return name
I think condition in line marked with (**) is needless as=20
self.actionSet().key() are always equal to self.actions(). In my opinion=20
there should be one more condition in line (***) to make it sense:
(***) if getattr(self, action, None):
self._actionDict[action] =3D 1 =20
Consider lines marked with (*). Can it work correctly, if=20
self.methodNameForAction(name) returns with something other then name?
Another questions: It is intentional not to call methodNameForAction()=20
in code for new style actions? And is it correct to handle new style=20
action if user want old one?
I can prepare patches (for class Page form Webware and from WSGIKit and=20
for class CPage from Components) but I need to know answers for last to=20
questions.
Regards
--=20
Rados=B3aw Kintzi (radek at lucasconsulting dot pl)
|
| Thread | Author | Date |
|---|---|---|
| [Webware-devel] Questions about actions handling in Page | <radek@lu...> |