I know that I’d already post a message about deferred but I think I haven’t understand very well.

 

I have a function that is suppose to return a new dictionnary but it returns a deferred.

 

 

class MainPage(pages.BasePage):

    templateFile = "main.html"

 

    def initialize(self, dbpool=None):

        self.dbpool = dbpool

   

    def setUp(self, request, *args):

        var = self.initPermissions(request)      #var is suppose to get the new list

        print var

 

    def wmfactory_welcome(self, request):

        return "Bienvenue, %s" % request.getComponent(myguard.Authenticated).name

 

    def initPermissions(self, request):       #create and return the results of a sql query

        group = request.getComponent(myguard.Authenticated).group

        listGroup = group.split(',')

        sql = "select permission from permissions where 1"

        for item in listGroup:

            sql += " or permissions.group='%s'" % item.lstrip()

        theDeferred = self.dbpool.runQueryDict(sql)

        return theDeferred.addCallback(self.makeDict)        # suppose to call makeDict when the results has arrived

 

    def makeDict(self, results):

            # when I print what is in results, I can see all the data from the sql query

        listPermissions = []

        for item in results:

            listPermissions.append(item.get('permission'))

        return listPermissions                   # return the new list but the function setUp receive a deferred

 

 

I’ve put some comments in the code to help you understand what I want.

The big problem is that var receive a deferred and not the new list

 

Vicky