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 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 __init__(self, selected_category, search_query=None, children=None, *args, **kwargs): super().__init__(*args, **kwargs) self.category = self.get_category_model().objects.get(pk=selected_category) if selected_category else None self.selected_category = self.category self.search_query = search_query.strip() if search_query else None self.producer = self.context['request'].GET.get('pr', False) self.usersite, self.template, self.organization = get_usersite_objects() # self.children = [x for x in children.all().values_list('id', flat=True)] if children else None self.children = children if children else None
def b2c_producers(selected_category=None): usersite, template, organization = get_usersite_objects() producers = B2CProduct.objects\ .filter(company_id=organization.pk)\ .filter(producer__isnull=False) if selected_category and isinstance(selected_category, B2CProductCategory): producers = producers.filter( producer__b2c_categories__in=[selected_category] ) return producers.values_list('producer__pk', 'producer__name').distinct()
def b2c_categories_ex(): usersite, template, organization = get_usersite_objects() ch = [x for x in organization.children.all().values_list('id', flat=True)] categories = B2CProductCategory.objects.filter( products__company_id__in=ch, products__is_active=True ).order_by('level').distinct() return {'items': ((c.id, {'slug': c.slug, 'name': c.name, 'level': c.level})\ for c in categories)}
def exhibitions(context, template_name, on_page, page=1, order_by='-created_at'): usersite, template, organization = get_usersite_objects() queryset = Exhibition.get_active_objects().filter(organization=organization) return ItemsTag( order_by=order_by, context=context, queryset=queryset, template_path=template_name, on_page=on_page, current_page=page, url_paginator='exhibition:paginator', queryset_key='exhibitions').result_data
def b2b_categories(): usersite, template, organization = get_usersite_objects() categories = B2BProductCategory.objects.filter( products__company_id=organization.pk, products__is_deleted=False, products__is_active=True ).order_by('level').distinct() return OrderedDict(sorted( load_category_hierarchy( B2BProductCategory, categories ).items(), key=lambda x: [x[1].tree_id, x[1].lft]))
def interface(request): organization = get_usersite_objects(typeof=True)['organization'] menu = [{ 'name': _('Home'), 'href': 'home/' }] if organization.news.exists(): menu.append({ 'name': _('News'), 'href': 'news/' }) if isinstance(organization, Company) and (organization.b2b_products.exists() or organization.b2c_products.exists()): sub_categories = [] menu.append({ 'name': _('Products'), 'href': 'products/', "subCategories": sub_categories }) if organization.b2c_products.exists(): sub_categories.append({ "name": _("B2C"), "href": "b2c/" }) if organization.b2b_products.exists(): sub_categories.append({ "name": _("B2B"), "href": "b2b/" }) if organization.galleries.exists(): menu.append({ 'name': _('Gallery'), 'href': 'gallery/' }) menu += [{ "name": _("Structure"), "href": "structure/" }, { "name": _("Contacts"), "href": "contact/" }] return Response(menu)
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 b2c_categories(show_as_list=False): usersite, template, organization = get_usersite_objects() categories = B2CProductCategory.objects.filter( products__company_id=organization.pk, products__is_deleted=False, products__is_active=True ).order_by('level').distinct() if not show_as_list: return OrderedDict(sorted( load_category_hierarchy(B2CProductCategory, categories)\ .items(), key=lambda x: [x[1].tree_id, x[1].lft])) else: return {'items': ((c.id, {'slug': c.slug, 'name': c.name, 'level': c.level})\ for c in categories)}
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
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
def __init__(self, **kwargs): self.usersite, self.template, self.organization = get_usersite_objects()
def settings_api(request): usersite, template, organization = get_usersite_objects() result = { 'menu': [], 'slides': [], 'contacts': { 'tel': clean_html(organization.phone) if organization.phone else None, 'email': clean_html(organization.email) if organization.email else None, 'address': clean_html(organization.address) if organization.address else None, 'orgName': clean_html(organization.name) }, 'map': None, "orgLogo": organization.logo.original if organization.logo else None, "logo": usersite.logo.original if usersite.logo else None, "offerIcons": [], "footerBanner": None, } # Deprecated for page in organization.additional_pages.all(): result['menu'].append({ 'name': clean_html(page.title), 'href': "/current", }) import glob if usersite.slider_images: images = [obj.image.original for obj in usersite.slider_images.only('image')] else: static_url = "%susersites/templates" % settings.STATIC_URL d = template.folder_name images = ["%s/%s/%s" % ( static_url, os.path.basename(d), os.path.basename(image) ) for image in glob.glob(d + "/*.jpg")] for image in images: result['slides'].append({ 'url': image, }) if organization.location: lat, long = organization.location.split(',') result['map'] = { "lat": lat, "longt": long } # TOOD cache it banner_blocks = ['SITES RIGHT 1', 'SITES RIGHT 2', 'SITES RIGHT 3', 'SITES RIGHT 4', 'SITES RIGHT 5', 'SITES FOOTER'] for block in banner_blocks: banner = Banner.objects.filter( site_id=usersite.pk, block__code=block, block__block_type='user_site', image__isnull=False ).order_by('?').first() if not banner: continue if block == 'SITES FOOTER': result['footerBanner'] = { 'url': banner.image.url, 'title': banner.title, 'link': banner.link } else: result['offerIcons'].append({ 'url': banner.image.url, 'title': banner.title, 'link': banner.link }) return Response(result)
def filter_queryset(self, queryset): organization = get_usersite_objects(typeof=True)['organization'] return queryset.filter(organization=organization)
def get_queryset(self): organization = get_usersite_objects(typeof=True)['organization'] return organization.additional_pages
def filter_queryset(self, queryset): organization = get_usersite_objects(typeof=True)['organization'] return queryset.filter( products__company_id=organization.pk ).order_by('level').distinct()