Skip to content

Commit eb88f8c

Browse files
committed
test
1 parent f623072 commit eb88f8c

2 files changed

Lines changed: 22 additions & 21 deletions

File tree

agave/models/mongo.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ def dict(self) -> DictStrAny:
1616

1717
@classmethod
1818
def retrieve(cls, id: str, user_id: Optional[str] = None):
19+
query = Q(id=id)
20+
if user_id:
21+
query = query & Q(user_id=user_id)
1922
try:
20-
id_query = Q(id=id)
21-
if user_id:
22-
id_query = id_query & Q(user_id=user_id)
23-
id_obj = cls.objects.get(id_query)
23+
obj = cls.objects.get(query)
2424
except DoesNotExist:
2525
raise ObjectDoesNotExist
26-
return id_obj
26+
return obj
2727

2828
@classmethod
2929
def count(cls, filters: Any) -> int:
30-
count = cls.objects.filter(filters).count()
31-
return count
30+
return cls.objects.filter(filters).count()
3231

3332
@classmethod
34-
def filter_limit(cls, filters: Any, limit: int) -> Tuple[Any, bool]:
33+
def filter_limit(cls, filters: Q, limit: int) -> Tuple[Any, bool]:
3534
items = (
3635
cls.objects.order_by("-created_at").filter(filters).limit(limit)
3736
)

agave/models/redis.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Optional, Tuple
1+
from typing import Any, Dict, Optional, Tuple
22

33
from cuenca_validations.typing import DictStrAny
44
from cuenca_validations.validators import sanitize_item
@@ -23,7 +23,7 @@ def _from_redis(self, value):
2323
return value.decode('utf-8')
2424

2525

26-
def redis_to_dit(obj, exclude_fields: list = None) -> dict:
26+
def redis_to_dict(obj, exclude_fields: list = None) -> dict:
2727
excluded = ['o_id']
2828
response = {
2929
key: sanitize_item(value)
@@ -38,28 +38,30 @@ class RedisModel(BaseModel, Model):
3838
o_id = PrimaryKey() # Para que podamos usar `id` en los modelos
3939

4040
def dict(self) -> DictStrAny:
41-
return self._dict(redis_to_dit)
41+
return self._dict(redis_to_dict)
4242

4343
@classmethod
4444
def retrieve(cls, id: str, user_id: Optional[str] = None):
45+
params = dict(id=id)
4546
if user_id:
46-
id_obj = cls.query.filter(
47-
id=id,
48-
user_id=user_id,
49-
).first()
50-
else:
51-
id_obj = cls.get_by(id=id)
52-
if not id_obj:
47+
params['user_id'] = user_id
48+
49+
obj = cls.query.filter(**params).first()
50+
51+
if not obj:
5352
raise ObjectDoesNotExist
54-
return id_obj
53+
return obj
5554

5655
@classmethod
5756
def count(cls, filters: Any) -> int:
58-
count = cls.query.filter(**filters).count()
59-
return count
57+
return cls.query.filter(**filters).count()
6058

6159
@classmethod
60+
<<<<<<< HEAD
6261
def filter_limit(cls, filters: Any, limit: int) -> Tuple[List, bool]:
62+
=======
63+
def filter_limit(cls, filters: Dict, limit: int) -> Tuple[Any, bool]:
64+
>>>>>>> test
6365
items = (
6466
cls.query.filter(**filters).order_by('-created_at').limit(0, limit)
6567
)

0 commit comments

Comments
 (0)