I have a class and portal_type Person and there are 2 methods in it:
class Person(BaseContent):
def print_all(self):
catalog = getToolByName(self, "portal_catalog")
results = catalog(portal_type = 'Person')
final_result = ''
for result in results:
final_result += result.getObject().print_person()
return final_result
def print_person(self):
return self.name
But I realised that print_all is not associated with any object so it should be static method. What I want to do is get all the instances of the person and call print_person(). But the problem is: what should I write in the catalog since there is no self object after I make the print_all method static method. For instance now I cannot write
catalog = getToolByName(self, "portal_catalog")
I want something like:
@staticmethod
def print_all():
instance = Person()
catalog = getToolByName(instance, "portal_catalog")
.
.
.
But it is giving me 'invalid syntax' error at instance = Person()! I hope my question is clear and any help will be appreciated!
You can replace
selfwithcontext, like this: