Beispiel #1
0
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
Beispiel #2
0
    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()
Beispiel #3
0
 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
Beispiel #4
0
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()
Beispiel #5
0
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)}
Beispiel #6
0
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
Beispiel #7
0
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]))
Beispiel #8
0
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)
Beispiel #9
0
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
        }
Beispiel #10
0
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)}
Beispiel #11
0
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
Beispiel #12
0
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
Beispiel #13
0
 def __init__(self, **kwargs):
     self.usersite, self.template, self.organization = get_usersite_objects()
Beispiel #14
0
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)
Beispiel #15
0
 def filter_queryset(self, queryset):
     organization = get_usersite_objects(typeof=True)['organization']
     return queryset.filter(organization=organization)
Beispiel #16
0
 def get_queryset(self):
     organization = get_usersite_objects(typeof=True)['organization']
     return organization.additional_pages
Beispiel #17
0
 def filter_queryset(self, queryset):
     organization = get_usersite_objects(typeof=True)['organization']
     return queryset.filter(
             products__company_id=organization.pk
         ).order_by('level').distinct()