def crawldir(directory, language=None, country=None, foreign_id=None): """Crawl the given directory.""" if directory is None or not os.path.exists(directory): log.error("Invalid directory: %r", directory) return directory = os.path.abspath(os.path.normpath(directory)) if foreign_id is None: foreign_id = 'directory:%s' % slugify(directory) collection = Collection.by_foreign_id(foreign_id) if collection is None: collection = Collection.create({ 'foreign_id': foreign_id, 'label': directory, 'managed': True }) if language is not None: collection.languages = [language] if country is not None: collection.countries = [country] db.session.commit() update_collection(collection) log.info('Crawling %r to %r...', directory, collection.foreign_id) document = Document.by_keys(collection=collection, foreign_id=directory) ingest_document(document, directory)
def create(): authz.require(authz.logged_in()) collection = Collection.create(request_data(), request.auth_role) db.session.commit() update_collection(collection) log_event(request) return view(collection.id)
def load_collection(self, data): foreign_id = data.get('foreign_id') collection = Collection.by_foreign_id(foreign_id) if collection is None: collection = Collection.create(data) db.session.commit() update_collection(collection) return collection
def update(id): collection = obj_or_404(Collection.by_id(id)) request.authz.require(request.authz.collection_write(collection)) collection.update(request_data()) db.session.add(collection) db.session.commit() update_collection(collection) log_event(request) return view(id)
def create(): request.authz.require(request.authz.logged_in) data = request_data() data['managed'] = False collection = Collection.create(data, request.authz.role) db.session.commit() update_collection(collection) log_event(request) return jsonify(collection)
def update(id): authz.require(authz.collection_write(id)) collection = obj_or_404(Collection.by_id(id)) collection.update(request_data()) db.session.add(collection) db.session.commit() update_collection(collection) log_event(request) return view(id)
def test_index(self): update_collection(self.col) flush_index() res = self.client.get('/api/2/collections') assert res.status_code == 200, res assert res.json['total'] == 0, res.json _, headers = self.login(is_admin=True) res = self.client.get('/api/2/collections', headers=headers) assert res.status_code == 200, res assert res.json['total'] == 1, res.json
def test_admin_all_access(self): self.wl = Collection() self.wl.label = "Test Collection" self.wl.foreign_id = 'test' self.wl.creator = self.create_user('watcher') db.session.add(self.wl) db.session.commit() update_collection(self.wl) _, headers = self.login(foreign_id='admin', is_admin=True) res = self.client.get('/api/2/collections/%s' % self.wl.id, headers=headers) assert res.status_code == 200, res
def load_collection(self, data): collection = Collection.create(data) db.session.commit() update_collection(collection) return collection