def do_filtering(query_params, order): ads_list = Advert_Users.objects(**query_params).order_by(order) if 'period__contains' in query_params: if query_params['period__contains'] == 'day': query_params['action_type'] = 'daily_rent' else: query_params['action_type'] = 'rent' del query_params['period__contains'] if 'exchange' in query_params: if query_params['exchange'] == True: query_params['action_type'] = 'exchange' else: query_params['action_type'] = 'sale' del query_params['exchange'] del query_params['action_type__contains'] ads_list2 = Advert.objects(**query_params).order_by(order) return QuerySetChain(ads_list, ads_list2)
def get_my_favorites(user, _to_curr='byr', order='-images_len'): try: favorites = user.favorites except: favorites = [] query_params = {} query_params[ 'id__in' ] = favorites ads_list = Advert_Users.objects(**query_params).order_by(order) for ad in ads_list: ad.price = price_convert(ad.price, ad.currency, _to_curr) ad.currency = _to_curr ads_list2 = Advert.objects(**query_params).order_by(order) for ad in ads_list2: ad.price = price_convert(ad.price, ad.currency, _to_curr) ad.currency = _to_curr my_ads = list(ads_list) + list(ads_list2) return my_ads