def filter_byAgeGap(age_gap, ids, sort=False, tags: list = []): selector = { "user": { "$in": ids }, "$and": [{ "$where": "this.tags.length >= 5" }, { "$where": "this.images.length >= 1" }, { "$where": "this.gender != '%s'" % Account.GENDER_UNSET }, { "$where": "this.biography.length >= 25" }] } if age_gap >= 0: curr = Account.get({"user": current_user._id}, {"dob": 1})["dob"] min = curr - relativedelta.relativedelta(years=int(age_gap)) max = curr + relativedelta.relativedelta(years=int(age_gap)) selector = {**selector, **{"dob": {"$lte": max, "$gte": min}}} if tags: selector = {**selector, **{"tags": {"$all": tags}}} ret = Account.get(selector, {"user": 1, "class": 1, "dob": 1}) if not ret: return [] if not isinstance(ret, list): ret = [ret] if sort: ret.sort(key=lambda x: x.age(), reverse=True) ret = [x.user for x in ret] return ret
def filter_by_sexuality(users: list): crit = Account.get({"user": current_user._id}) ids = [x._id for x in users] if crit.interest == Account.INTEREST_BOTH: print("Interes in both") items = Account.get({"_id": {"$in": ids}}) elif crit.interest == Account.INTEREST_MEN: items = Account.get({ "_id": { "$in": ids }, "$and": [{ "gender": { "$in": [Account.GENDER_MALE] } }, { "interest": { "$in": [crit.gender, Account.INTEREST_BOTH] } }, { "tags": { "$all": crit.tags } }] }) elif crit.interest == Account.INTEREST_WOMEN: items = Account.get({ "_id": { "$in": ids }, "$and": [{ "gender": { "$in": [Account.GENDER_FEMALE] } }, { "interest": { "$in": [crit.gender, Account.INTEREST_BOTH] } }, { "tags": { "$all": crit.tags } }] }) if not items: return [] if not isinstance(items, list): return [q.user for q in [items]]