def get_objects(self): query = deepcopy(self.request.form) query.pop('excelexport.policy', None) query = unflatten_dotted_dict(query) query = self._parse_query(query) self._constrain_query_by_path(query) catalog = api.portal.get_tool('portal_catalog') return (b.getObject() for b in catalog.searchResults(**query))
def test_works_with_list_values(self): dct = { 'path.query': ['foo', 'bar'], 'path.depth': 2, } self.assertEqual({'path': { 'query': ['foo', 'bar'], 'depth': 2 }}, unflatten_dotted_dict(dct))
def test_works_with_list_values(self): dct = { 'path.query': ['foo', 'bar'], 'path.depth': 2, } self.assertEqual( {'path': {'query': ['foo', 'bar'], 'depth': 2}}, unflatten_dotted_dict(dct) )
def _process_reply(self): """Easier to override if necessary to call various ways from reply method.""" query = {} query.update(self._set_query_before_hook()) query.update(self._set_query_base_search()) query.update(self._set_query_additional_params()) query.update(self.request.form.copy()) query.update(self._set_query_after_hook()) self._clean_query(query) query = unflatten_dotted_dict(query) return SearchHandler(self.context, self.request).search(query)
def reply(self): query = self.request.form.copy() query = unflatten_dotted_dict(query) result = {} if "draw" in query: result["draw"] = query.pop("draw") handler = TreeSearchHandler(self.context) result["recordsTotal"], result[ "recordsFiltered"], data = handler.search(query) result["data"] = [ queryMultiAdapter((o, self.request), ISerializeToJson)() for o in data ] return result
def test_unflattens_dotted_dict(self): dct = { 'a.b.X': 1, 'a.b.Y': 2, 'a.foo': 3, 'bar': 4, } self.assertEqual( {'a': {'b': {'X': 1, 'Y': 2}, 'foo': 3}, 'bar': 4}, unflatten_dotted_dict(dct) )
def test_unflattens_dotted_dict(self): dct = {"a.b.X": 1, "a.b.Y": 2, "a.foo": 3, "bar": 4} self.assertEqual( { "a": { "b": { "X": 1, "Y": 2 }, "foo": 3 }, "bar": 4 }, unflatten_dotted_dict(dct), )
def query(self): query = self.request.form.copy() query = unflatten_dotted_dict(query) # Questi parametri vengono aggiunti di base a tutte le query base_query_parameters = {"portal_type": "Bando"} query.update(base_query_parameters) stato = query.get("stato_bandi") if stato: stato_query = self.query_stato(stato) del query['stato_bandi'] query.update(stato_query) return query
def parse_query(self): query = deepcopy(self.request.form) query = unflatten_dotted_dict(query) res = {} if "sort_on" in query: res["sort_index"] = query["sort_on"] del query["sort_on"] if "sort_order" in query: order = query["sort_order"] reverse = True if order in ["asc", "ascending"]: reverse = False res["reverse"] = reverse del query["sort_order"] res["query"] = query return res
def test_unflattens_dotted_dict(self): dct = { 'a.b.X': 1, 'a.b.Y': 2, 'a.foo': 3, 'bar': 4, } self.assertEqual({ 'a': { 'b': { 'X': 1, 'Y': 2 }, 'foo': 3 }, 'bar': 4 }, unflatten_dotted_dict(dct))
def generate_query(self): query = self.request.form.copy() query = unflatten_dotted_dict(query) if not query: return {"error": "You need to provide at least an author."} max_results = int(query.get("max_results", "10")) if max_results < 10 or max_results > 100: return {"error": "max_results should be between 10 and 100."} authors = query.get("authors", []) if not authors: return {"error": "You need to provide at least an author."} if isinstance(authors, six.string_types): authors = authors.split(",") res = { "query": "from: {}".format(" OR ".join(authors)), # additional infos for tweets "tweet.fields": "entities,source,public_metrics,created_at", "expansions": "attachments.media_keys,author_id", "media.fields": "type,preview_image_url,height,media_key,public_metrics,url,width", # noqa "user.fields": "name,profile_image_url,username", } return res
def test_works_on_empty_dict(self): self.assertEquals({}, unflatten_dotted_dict({}))
def test_leaves_regular_keys_untouched(self): dct = {"foo": 1, "bar": 2} self.assertEqual(dct, unflatten_dotted_dict(dct))
def test_leaves_regular_keys_untouched(self): dct = {'foo': 1, 'bar': 2} self.assertEqual(dct, unflatten_dotted_dict(dct))
def test_works_on_empty_dict(self): self.assertEqual({}, unflatten_dotted_dict({}))
def reply(self): query = self.request.form.copy() query = unflatten_dotted_dict(query) return SearchHandler(self.context, self.request).search(query)
def test_works_with_list_values(self): dct = {"path.query": ["foo", "bar"], "path.depth": 2} self.assertEqual({"path": { "query": ["foo", "bar"], "depth": 2 }}, unflatten_dotted_dict(dct))