def update(self): """\ Since this could be instantiated as a subform of sort in the adding view, we are going to rebase the context up one level if that's the case. """ context = self.context while context and IAdding.providedBy(context): context = aq_parent(context) self.context = context return super(AddForm, self).update()
def __call__(self, context): # we are on an adding form if IAdding.providedBy(context): # quick and dirty way to have a context on adding form # is there some right solution for this? factory_name = context.request.getURL().split('/')[-1] if factory_name: factory = queryUtility(IFactory, name=factory_name) if factory is not None: try: context = factory() except Exception, e: # no luck, perhaps factory needs some arguments pass