def get_my_demand(user, page, t1id, aid, asc_of_price, count_per_page): """ TODO: using user_sid to get specified page :param user: :param page: :param t1id: :param aid: :param asc_of_price: :param count_per_page :return: """ qs = ProductDemand.objects.select_related('uid__user_validate', 'qid__t3id__t2id__t1id', 'aid__cid__pid', 'pmid', 'wcid').filter(uid=user, in_use=True) qs = filter_and_order_demand(qs, t1id, aid, asc_of_price) st, ed, n_pages = get_page_info( qs, count_per_page, page, index_error_excepiton=Error400("Page out of range")) # return sliced single page return qs[st:ed], n_pages
def get_popular_demand(role, user, page, t1id, aid, asc_of_price, count_per_page): """ :param role: :param user: :param page: start from one :param count_per_page: size of page :return: """ if user is None and role is None: raise Error400("Either user or role must not be null.") if user is not None: role = user.role qs = ProductDemand.objects.select_related( 'uid__user_validate', 'qid__t3id__t2id__t1id', 'aid__cid__pid', 'pmid', 'wcid').filter(in_use=True, match=True).filter(end_time__gt=now()).exclude( t_demand=t_demand_translator.from_role(role)) qs = filter_and_order_demand(qs, t1id, aid, asc_of_price) st, ed, n_pages = get_page_info( qs, count_per_page, page, index_error_excepiton=Error400("Page out of range")) # return sliced single page return qs[st:ed], n_pages
def get_search_demand(user, page, keyword, t1id, aid, asc_of_price, count_per_page): qs = ProductDemand.objects.select_related( 'uid__user_validate', 'qid__t3id__t2id__t1id', 'aid__cid__pid', 'pmid', 'wcid').filter(Q(uid__user_validate__company__contains=keyword) | Q(uid__user_validate__contact=keyword) | Q(pid__tname3=keyword), in_use=True).exclude(uid__role=user.role) if t1id is not None: qs = qs.filter(qid__t3id__t2id__t1id=t1id) if aid is not None: qs = qs.filter(aid=aid) if asc_of_price is not None: if asc_of_price: qs = qs.order_by("price", "-id") else: qs = qs.order_by("-price", "-id") else: qs = qs.order_by("-id") st, ed, n_pages = get_page_info( qs, count_per_page, page, index_error_excepiton=Error400("Page out of range")) # return sliced single page return qs[st:ed], n_pages
def run(self, page, count_per_page, **kwargs): qs, field_name, extra = self.get_paged_qs( page=page, count_per_page=count_per_page, **kwargs) if extra is None: extra = {} start, end, n_pages = get_page_info( qs, count_per_page, page, index_error_excepiton=self.out_of_range_exception( page=page, count_per_page=count_per_page, **kwargs)) qs_paged = qs[start:end] qs_transformed = self.transform_queryset(qs_paged, page=page, count_per_page=count_per_page, **kwargs) return dict( { field_name: [ self.transform_element(obj, page=page, count_per_page=count_per_page, **kwargs) for obj in qs_transformed ], 'n_pages': n_pages, }, **extra)
def obtain_history(user, page, count_per_page): # type: (UserBase, int, int) -> (QuerySet, int) qs = user.transaction start, end, n_pages = get_page_info(qs, count_per_page, page, index_error_excepiton=WLException( 400, "Page out of range")) return qs.order_by("-id")[start:end], n_pages
def obtain_order_list_by_o_state(page, count_per_page): # type: (int, int) -> (QuerySet, int, int) qs = OrderInfo.objects.filter(o_state=order_state_choice.CREATED) start, end, n_pages = get_page_info(qs, count_per_page, page, index_error_excepiton=WLException( 400, "Page out of range")) count = qs.count() return qs.order_by("-id")[start:end], n_pages, count
def obtain_order_list(user, page, count_per_page): # type: (UserBase, int, int) -> (QuerySet, int) qs = get_user_order_queryset(user).filter( o_state=order_state_choice.COMPLETED) start, end, n_pages = get_page_info(qs, count_per_page, page, index_error_excepiton=WLException( 400, "Page out of range")) return qs.order_by("-id")[start:end], n_pages, qs.count()
def obtain(user, t_invite, page, count_pre_page): """ :param user: :param t_invite: :param page: page number :param count_pre_page :return: invites, n_pages """ # if t_invite in ( # t_invite_choice.PROCEEDING_INVITES_MINE, # t_invite_choice.CLOSED_INVITES_MINE, # t_invite_choice.FINISHED_INVITES_MINE, # ): # qs = user.user_invite_src.select_related( # 'dmid_t__qid__t3id__t2id__t1id', # 'dmid_t__wcid', # 'uid_s__user_validate', # 'uid_t__user_validate' # ).filter(i_status__in=MAP_TINVITE_INVITE_STATUS[t_invite]) # elif t_invite in ( # t_invite_choice.PROCEEDING_INVITES_OTHERS, # t_invite_choice.CLOSED_INVITES_OTHERS, # t_invite_choice.FINISHED_INVITES_OTHERS, # ): # qs = user.user_invite_dst.select_related( # 'dmid_t__qid__t3id__t2id__t1id', # 'dmid_t__wcid', # 'uid_s__user_validate', # 'uid_t__user_validate' # ).filter(i_status__in=MAP_TINVITE_INVITE_STATUS[t_invite]) # else: # raise WLException(400, "t_invite is invalid") qs1 = user.user_invite_src.select_related( 'dmid_t__qid__t3id__t2id__t1id', 'dmid_t__wcid', 'uid_s__user_validate', 'uid_t__user_validate').filter( i_status__in=MAP_TINVITE_INVITE_STATUS[t_invite]) qs2 = user.user_invite_dst.select_related( 'dmid_t__qid__t3id__t2id__t1id', 'dmid_t__wcid', 'uid_s__user_validate', 'uid_t__user_validate').filter( i_status__in=MAP_TINVITE_INVITE_STATUS[t_invite]) qs = qs1 | qs2 start, end, n_pages = get_page_info(qs, count_pre_page, page, index_error_excepiton=WLException( 400, "Page out of range")) qs = qs.order_by('-id') return qs[start:end], n_pages
def obtain_order_list_by_state(user, o_state, page, count_per_page): # type: (UserBase, int, int, int) -> (QuerySet, int, int) if user.role != user_role_choice.RECYCLING_STAFF: raise WLException(401, u"无权操作") qs = OrderInfo.objects.filter(o_state=o_state) start, end, n_pages = get_page_info(qs, count_per_page, page, index_error_excepiton=WLException( 400, "Page out of range")) return qs.order_by("-id")[start:end], n_pages, qs.count()
def obtain_order_list(user, order_type, page, count_pre_page): # type: (UserBase, int, int) -> QuerySet qs = OrderInfo.objects.filter(ivid__in=(user.user_invite_dst.all() | user.user_invite_src.all())) if order_type == order_type_choice.PROCEEDING: qs = qs.exclude(o_status__in=(o_status_choice.CLOSED, o_status_choice.SUCCEEDED)) elif order_type == order_type_choice.CLOSED: qs = qs.filter(o_status=o_status_choice.CLOSED) elif order_type == order_type_choice.SUCCEEDED: qs = qs.filter(o_status=o_status_choice.SUCCEEDED) else: raise WLException(400, "order_type is invalid") start, end, n_pages = get_page_info(qs, count_pre_page, page, index_error_excepiton=WLException( 400, "Page out of range")) return qs.order_by("-id")[start:end], n_pages