def post_json(self): # NOTE: this is same basic code as docstore.index return docstore.DocstoreManager( docstore.INDEX_PREFIX, config.DOCSTORE_HOST, config).post( self, docstore._public_fields().get(self.identifier.model, []), { 'parent_id': self.parent_id, })
def test_post(publishable_objects): """Right now this only tests if you can post() without raising exceptions """ ds = docstore.DocstoreManager(docstore.INDEX_PREFIX, config.DOCSTORE_HOST, config) post_these = [o for o in publishable_objects if o.id in POST_OBJECT_IDS] for o in post_these: print(o) o.status = 'completed' o.public = 1 o.write_json() status = ds.post(o) print(status)
def reindex(self): """Reindex Collection objects to Elasticsearch """ ds = docstore.DocstoreManager(docstore.INDEX_PREFIX, config.DOCSTORE_HOST, config) # check for ES connection before going to all the trouble health = ds.health() index_name = ds.index_name(self.identifier.model) index_exists = ds.index_exists(index_name) if not index_exists: return {'error': 'Missing Elasticsearch index "%s"' % index_name} return ds.post_multi(self.identifier.path_abs(), recursive=True, force=True)
def test_post_multi(publishable_objects): """Right now this only tests if you can post() without raising exceptions """ ds = docstore.DocstoreManager(docstore.INDEX_PREFIX, config.DOCSTORE_HOST, config) print(ds) post_these = [o for o in publishable_objects if o.id in POST_OBJECT_IDS] collection_path = post_these[0].identifier.collection_path() print(collection_path) # make all objects publishable for o in post_these: o.status = 'completed' o.public = 1 o.write_json() # post result = ds.post_multi(collection_path, recursive=False) print(result) result = ds.post_multi(collection_path, recursive=True) print(result)
def test_delete(publishable_objects): ds = docstore.DocstoreManager(docstore.INDEX_PREFIX, config.DOCSTORE_HOST, config) print(ds) # delete single f = None for o in publishable_objects: if o.identifier.model == 'file': f = o print(f) result = ds.delete(f.id, recursive=False) print(result) # c = None for o in publishable_objects: if o.identifier.model == 'collection': c = o print(c) result = ds.delete(c.id, recursive=True) print(result)