Just realized I'm doing something similar for the CSV Importer. I found myself querying for a taxonomy term by the term'sname
multiple times. This required me to also look up the taxonomy_vocabulary vid
multiple times... but rather than querying the farmOS server for the taxonomy vid
each time, I maintain a copy of the resources
from /farm.json
. This makes it easy to get a taxonomy vocabulary vid
from the vocabularyname
without a request to the server.
With the vid
, I then make a request for any term that matches the vocabulary name
and term name
.
Some preliminary helper code that handles getting a taxonomy term from a name
specified in a CSV file:
def _get_farmos_taxonomy_term(self, name, taxonomy_name, create=False):
taxonomy_vid = self.farm_client_info.get('resources').get('taxonomy_term').get(taxonomy_name).get('vid')
taxonomy_vid = int(taxonomy_vid)