def b2c_products(context, template_name, on_page, page=1, selected_category=None, search_query=None, order_by=('-show_on_main', '-created_at')): usersite, template, organization = get_usersite_objects() if search_query is None: url_paginator = "b2c_products:category_paged" if selected_category else "b2c_products:paginator" else: url_paginator = "b2c_products:search_paginator" if not isinstance(order_by, (list, tuple)): order_by = [order_by, ] if template.typeof == 1: children = organization.children.all() queryset = B2CProduct.get_active_objects().filter(company__in=children).order_by(*order_by) else: if isinstance(organization, Company): queryset = B2CProduct.get_active_objects().filter(company=organization).order_by(*order_by) else: queryset = B2CProduct.objects.none() return ProductsTag( order_by=order_by, selected_category=selected_category, search_query=search_query, context=context, queryset=queryset, template_path=template_name, on_page=on_page, current_page=page, url_paginator=url_paginator, queryset_key='products').result_data
def get_company_content(self): self.proposals = BusinessProposal.get_active_objects().filter( organization=self.organization) self.news = News.get_active_objects().filter( organization=self.organization) self.exhibitions = Exhibition.get_active_objects().filter( organization=self.organization) if isinstance(self.organization, Company): self.b2c_products = B2CProduct.get_active_objects().filter( company=self.organization).order_by('-show_on_main') self.b2c_coupons = B2CProduct.get_active_objects().filter( company=self.organization, coupon_dates__contains=now().date(), coupon_discount_percent__gt=0).order_by("-created_at") self.b2b_products = B2BProduct.get_active_objects().filter( company=self.organization) else: self.b2b_products = None self.b2c_products = None self.b2c_coupons = None
def b2c_products_special(context, template_name, on_page): usersite, template, organization = get_usersite_objects() if template.typeof == 1: children = organization.children.all() queryset = B2CProduct.get_active_objects().filter(company__in=children).order_by('?')[:3] else: if isinstance(organization, Company): queryset = B2CProduct.get_active_objects().filter(company=organization).order_by('?')[:3] else: queryset = B2CProduct.objects.none() return { 'template': get_template_with_base_path(template_name), 'products': queryset }
def home(request, country=None): products = B2CProduct.get_active_objects()\ .order_by('-show_on_main', '-created_at')[:4] top_product_list = B2CProduct.get_active_objects().order_by('?')[:4] coupons = B2CProduct.get_active_objects().filter(coupon_dates__contains=now().date(), coupon_discount_percent__gt=0) \ .order_by("-created_at")[:3] product_sale = B2CProduct.get_active_objects().filter(discount_percent__gt=0)\ .exclude(coupon_dates__contains=now().date()).order_by("-created_at")[:3] if country: products = products.filter(company__country=country) top_product_list = top_product_list.filter(company__country=country) coupons = coupons.filter(company__country=country) product_sale = product_sale.filter(company__country=country) return render_to_response("centerpokupok/index.html", {'coupons': coupons, "newProducrList": products, "topPoductList": top_product_list, "productsSale": product_sale, 'country': country}, context_instance=RequestContext(request))
def storeMain(request, company, category=None): if not Company.objects.filter(pk=company).exists(): return HttpResponseNotFound() new_products = B2CProduct.objects.filter(company=company).order_by('-created_at')[:4] if category: new_products = new_products.filter(category=category) top_products = B2CProduct.objects.filter(company=company).order_by('?')[:4] if category: top_products = top_products.filter(category=category) coupons = B2CProduct.get_active_objects() \ .filter(company=company, coupon_dates__contains=now().date(), coupon_discount_percent__gt=0) \ .order_by("-created_at")[:3] if category: coupons = coupons.filter(category=category) product_sale = B2CProduct.get_active_objects().filter(discount_percent__gt=0, company=company) \ .exclude(coupon_dates__contains=now().date()).order_by("-created_at")[:15] if category: product_sale = product_sale.filter(category=category) template_params = { 'companyID': company, 'coupons': coupons, 'product_sale': product_sale, 'new_products': new_products, 'top_products': top_products, 'menu': 'main', 'store_url': 'companies:category' } return render_to_response("centerpokupok/Company/index.html", template_params, context_instance=RequestContext(request))
def _tab_b2c_products(request, company, page=1): products = B2CProduct.get_active_objects().filter(company=company) paginator = Paginator(products, 10) page = paginator.page(page) paginator_range = func.get_paginator_range(page) url_paginator = "companies:tab_b2c_products_paged" template_params = { 'page': page, 'paginator_range': paginator_range, 'url_paginator': url_paginator, 'url_parameter': company } return render(request, 'b24online/Companies/tab_B2CProducts.html', template_params)
def coupons_ex(context, template_name, on_page, page=1, selected_category=None, order_by='-created_at'): usersite, template, organization = get_usersite_objects() url_paginator = None if selected_category else None children = organization.children.all() queryset = B2CProduct.get_active_objects().filter( company__in=children, coupon_dates__contains=now().date(), coupon_discount_percent__gt=0 ) return ProductsTag( order_by=order_by, selected_category=selected_category, context=context, queryset=queryset, template_path=template_name, on_page=on_page, current_page=page, url_paginator=url_paginator, queryset_key='coupons').result_data
class B2CProductViewSet(viewsets.ReadOnlyModelViewSet): pagination_class = PaginationClass queryset = B2CProduct.get_active_objects() filter_backends = (CategoryFilterBackend,) def filter_queryset(self, queryset): queryset = super().filter_queryset(queryset) organization = get_current_site().user_site.organization if isinstance(organization, Company): return queryset.filter(company=organization) else: return queryset.none() def get_serializer_class(self): if hasattr(self, 'action'): if self.action == 'list': return ListB2CProductSerializer else: return DetaiB2ClProductSerializer return None
class CouponViewSet(viewsets.ReadOnlyModelViewSet): pagination_class = PaginationClass queryset = B2CProduct.get_active_objects() filter_backends = (CategoryFilterBackend,) def filter_queryset(self, queryset): queryset = super().filter_queryset(queryset) organization = get_usersite_objects(typeof=True)['organization'] if isinstance(organization, Company): return queryset.filter(company=organization, coupon_dates__contains=now().date(), coupon_discount_percent__gt=0).order_by("-created_at") else: return queryset.none() def get_serializer_class(self): if hasattr(self, 'action'): if self.action == 'list': return ListCouponSerializer else: return DetaiCouponSerializer return None
def coupons(context, template_name, on_page, page=1, selected_category=None, order_by='-created_at'): usersite, template, organization = get_usersite_objects() # TODO url_paginator = None if selected_category else None if isinstance(organization, Company): queryset = B2CProduct.get_active_objects().filter( company=organization, coupon_dates__contains=now().date(), coupon_discount_percent__gt=0 ) else: queryset = B2CProduct.objects.none() return ProductsTag( order_by=order_by, selected_category=selected_category, context=context, queryset=queryset, template_path=template_name, on_page=on_page, current_page=page, url_paginator=url_paginator, queryset_key='coupons').result_data
class B2CProductList(BaseListApi): serializer_class = B2CProductSerializer queryset = B2CProduct.get_active_objects().prefetch_related( 'company__countries')