I'm looking for a way to execute a python script upon exporting a print composer. Specifically, I want it to run once for each page exported. (logging some data and possibly updating a database).
So far I've created a custom expression that writes a log to a file and returns an empty string. I created an off-page label that runs the expression.
The problem is, this runs every time the page refreshes so it's running a bunch just paging through the atlas.
Trying to get it to run only on export, I put it in the 'export filename' field but that too runs every time the page refreshes.
Is there some way I can either force it to only run on export, or in the python code detect if the page is being exported before running?
edit: here's the test code I'm running so far:
def logTest(logitem):
global logFileName
f = open(logFileName, 'a')
f.write("{}\n".format(logitem))
f.close()
@qgsfunction(args='auto', group='Territory')
def postData(postItem, feature, parent):
logTest(str(postItem))
return u''
and my expression to test it is simply:
postData("id")