Skip to content

Commit

Permalink
Merge pull request #24 from certego/develop
Browse files Browse the repository at this point in the history
0.3.5
  • Loading branch information
0ssigeno committed Sep 28, 2022
2 parents 4421e8e + 2c598e9 commit 772132f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: autoflake
args: ["--remove-all-unused-imports", "--remove-unused-variables", "--ignore-init-module-imports", "-i"]
- repo: https://github.com/psf/black
rev: 21.9b0
rev: 22.3.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
Expand Down
39 changes: 32 additions & 7 deletions atlasq/queryset/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,44 @@ def _cursor(self):
return cursor

def order_by(self, *keys):
other = self.clone()
order_by: List[Tuple[str, int]] = other._get_order_by(keys)
aggregation = {"$sort": {key: value for key, value in order_by}}
other._other_aggregations.append(aggregation)
return other
if not keys:
return self
qs: AtlasQuerySet = self.clone()
order_by: List[
Tuple[str, int]
] = qs._get_order_by( # pylint: disable=protected-access
keys
)
aggregation = {"$sort": dict(order_by)}
qs._other_aggregations.append(aggregation) # pylint: disable=protected-access
return qs

def __getitem__(self, key):
if isinstance(key, int):
from mongoengine.queryset.base import BaseQuerySet

qs = self.clone()
qs._limit = 1
return BaseQuerySet.__getitem__(qs, key)
return super().__getitem__(key)

@property
def _query(self):
if not self._search_result:
return None
start = self._skip
end = self._limit
# unfortunately here we have to actually run the query to get the objects
# i do not see other way to do this atm
self._query_obj = Q(id__in=[obj["_id"] for obj in self._search_result if obj])
# I do not see other way to do this atm
ids: List[str] = []
for i, obj in enumerate(self._search_result):
if end is not None and i >= end:
break
if start is not None and i < start:
continue
if obj:
ids.append(obj["_id"])
self._query_obj = Q(id__in=ids)
logger.debug(self._query_obj.to_query(self._document))
return super()._query

Expand Down
2 changes: 1 addition & 1 deletion atlasq/queryset/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def transform(
if atlas_index.ensured:
# if we are using the embedded object, in the index is defined only the first level
if atlas_index.use_embedded_documents:
path = path.split(".")[0]
path = path.split(".", maxsplit=1)[0]
self._ensure_keyword_is_indexed(atlas_index, path)
logger.debug(obj)

Expand Down
6 changes: 0 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
"""
# PyDragonfly
Robust Python SDK and CLI for interacting with Certego's Dragonfly service's API.
## Docs & Example Usage: https://github.com/certego/pydragonfly
"""

from pathlib import Path

from setuptools import find_packages, setup
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.3.4"
VERSION = "0.3.5"

0 comments on commit 772132f

Please sign in to comment.