Instantiate a "grok view" with the parameters self.context and self.request in another grok view

StackOverflow https://stackoverflow.com/questions/16677014

  •  30-05-2022
  •  | 
  •  

Question

I have a site product with a code like this:

class AClass(grok.View):
    """ Code of AClass """
    pass

class BClass(AClass):
    """ Code of BClass with 'update' method defined """
    pass

class CClass(BClass):
    def update(self):
        self.panel = BClass(self.context, self.request)
        # more code     

My doubt is why BClass is instantiate/called in CClass code with two parameters (self.context and self.request). BClass has a update method without other parameters (just self) and doesn't have a __init__ method explicitly. So, what's the function of self.context and self.request in this case? Is this a kind of inheritance or acquisition?

After that I saw this, I think so that I didn't fully understand the omnipresent concepts of context and container in Plone.

Was it helpful?

Solution

It makes no sense to both subclass from BClass and have a BClass as an instance. I don't understand what the line self.panel = BClass(self.context, self.request) is supposed to achieve.

context and container are in no way omnipresent. The context is the object which you are viewing. It is set in the classes __init__ method. The container is an attribute of the context, typically __parent__.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top