0
Besvaret

Update a binder list row-by-row

jobu1342 10 år siden opdateret af Eugene Pankov (Project coordinator) 10 år siden 8
I have a binder that contains a list of items. I have a 'populate' button that is designed to fill out information in the binder, or simply update the information. Currently it works something like this: 

@on('populate', 'click')
def populate(self):
  for Info in self.collection:
    info.refresh()
    self.binder.update().populate()
   """ Ideally the list populates in the browser here,
   and then the code continues
   """

Where indicated in the code, I'd like the browser to update. Is this possible?
+2
Under vurdering
update() method updates the object with the information from UI. You only need populate() (update and populate have opposite effects) here. You can peek at the Binding demo plugin which demonstrates when to use update() and populate().

Browser side UI is automatically updated when there are any changes on the server-side. The reason why you don't see the updates is because you have overwritten your object data with empty values from UI when you called update() for the first time.
It sounds like all I need to do is remove the `update()` from the line:

self.binder.update().populate()
          vvv
self.binder.populate()

I tried this, restarted Ajenti, and the list still doesn't populate until the for loop is completed.
Oh I think you mean that you have some long-running code below that delays update in the browser? In this case, use Gevent task switching to let the other threads send the browser updates - add gevent.sleep(0) (import gevent) in the places where you want to give way to the updater thread: http://sdiehl.github.io/gevent-tutorial/#synchronous-asynchronous-execution
+1
It's also possible to directly force an UI update using self.context.endpoint.send_ui().
I couldn't get gevent to work, but forcing the UI update worked like a charm. Thanks!

Ajenti is awesome, BTW!

Kundesupport af UserEcho