With this export manager is very easy to return and export information managed by LibreGeoSocial (social nodes) to other possible formats used by any application. In fact, any query done it in the core of LibreGeoSocial returns a list of Social Nodes, if we are using the REST interface, these social nodes are going to pass through the export manager to format it to json with an HTTPResponse. Alike, the export manager could be used to export a complete layer using xml format and storing it to a file, in order to make a backup.
Following a description of the module, with his main class and methods:
- class Export_Manager¶
This is the class to instance, in order to use the export manager.
- configure(exportEngine, outputEninge, backup, viewer)¶
After instance the class, you have to configure the different engines of the export manager:
Parameters:
- exportEngine (string) – supported engines: “json”, “xml”
- outputEngine (string) – supported engines: “HTTPResponse”
- backup (boolean) – the export result of the data include binaries
- viewer – the user making the export process. None for no privacy
- export(socialNodes, extraInfo[, viewer])¶
This method will export the list of social nodes regarding the configured engines.
Parameters:
- socialNodes (Social_node) – a list of social nodes objects
- extraInfo (dictionary) – a dict with extra info that could be used by the format engine to add extra information.
- viewer – LibreGeoSocial user requesting the export proccess
Return type: the result will depend on the ouputEngine, containing the social nodes information in the new format.
Next an example of how to use the export manager. This example is quite similar to the process used by the layers system returning information by the REST interface:
from social.export_manager.export_manager import Export_Manager
from social.core.api_photo import get_all
node_list = get_all()
exportManager = Export_Manager()
exportManager.configure("json", "HTTPResponse", backup = "False", "anonymous")
exportManager.export(node_list, None, None)