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 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))
示例#3
0
 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))
示例#4
0
 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)
     )
示例#5
0
    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)
示例#6
0
 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
示例#7
0
 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)
     )
示例#8
0
 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),
     )
示例#9
0
    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
示例#10
0
 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
示例#11
0
 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))
示例#12
0
 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
示例#13
0
 def test_works_on_empty_dict(self):
     self.assertEquals({}, unflatten_dotted_dict({}))
示例#14
0
 def test_leaves_regular_keys_untouched(self):
     dct = {"foo": 1, "bar": 2}
     self.assertEqual(dct, unflatten_dotted_dict(dct))
示例#15
0
 def test_leaves_regular_keys_untouched(self):
     dct = {'foo': 1, 'bar': 2}
     self.assertEqual(dct, unflatten_dotted_dict(dct))
示例#16
0
 def test_leaves_regular_keys_untouched(self):
     dct = {'foo': 1, 'bar': 2}
     self.assertEqual(dct, unflatten_dotted_dict(dct))
示例#17
0
 def test_works_on_empty_dict(self):
     self.assertEqual({}, unflatten_dotted_dict({}))
示例#18
0
 def reply(self):
     query = self.request.form.copy()
     query = unflatten_dotted_dict(query)
     return SearchHandler(self.context, self.request).search(query)
示例#19
0
 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))