Example #1
0
    def get_context_data(self, **kwargs):
        kwargs = super(HomeView, self).get_context_data(**kwargs)
        home_page = HomePage.get_solo()
        home_slides = HomeSlide.objects.published().order_by('ordering')[:20]
        home_advantages = None  # HomeAdvantage.objects.published().order_by('ordering')[:5]

        home_catalogs = HomeCatalog.objects.published().order_by('ordering')

        home_catalog_products = defaultdict(list)
        for product in HomeCatalogProduct.objects.published()\
                .filter(product__status=StatusEnum.PUBLIC, catalog__status=StatusEnum.PUBLIC)\
                .select_related('product').order_by('ordering').iterator():
            home_catalog_products[product.catalog_id].append(product.product)

        home_catalog_manufacturers = defaultdict(list)
        for manufacturer in HomeCatalogManufacturer.objects.published()\
                .filter(manufacturer__status=StatusEnum.PUBLIC, catalog__status=StatusEnum.PUBLIC)\
                .select_related('manufacturer').order_by('ordering').iterator():
            home_catalog_manufacturers[manufacturer.catalog_id].append(
                manufacturer.manufacturer)

        kwargs.update(home_advantages=home_advantages,
                      home_catalogs=home_catalogs,
                      home_catalog_manufacturers=home_catalog_manufacturers,
                      home_catalog_products=home_catalog_products,
                      home_page=home_page,
                      home_slides=home_slides)
        return kwargs
Example #2
0
def import_page(name, path):
    with open(os.path.join(path, name, 'data'), 'rb') as f:
        data = pickle.load(f)

        def copy_data(target, data):
            copy_seo_data(target, data)
            translation.activate('en')
            target.content = html2text.html2text(data.text_en)
            translation.deactivate()

            translation.activate('fr')
            target.content = html2text.html2text(data.text_fr)
            translation.deactivate()

        if isinstance(data, models.HomePage):
            hp = HomePage.get_solo()

            copy_data(hp, data)

            push = HomePagePush()
            push.home_page = hp
            translation.activate('en')
            push.title = data.push_title_en
            push.content = html2text.html2text(data.push_content_en)
            translation.deactivate()

            translation.activate('fr')
            push.title = data.push_title_fr
            push.content = html2text.html2text(data.push_content_fr)
            translation.deactivate()
            push.save()

            hp.save()

        else:
            p = Page()
            p.slug = slugify(data.title_en.lower())

            copy_data(p, data)
            translation.activate('en')
            p.title = data.title_en
            translation.deactivate()

            translation.activate('fr')
            p.title = data.title_fr
            translation.deactivate()

            if hasattr(data, 'background'):
                img = make_master_image(
                    path,
                    data.background,
                    '{}-background'.format(data.title_en)
                )
                p.background = img

            p.save()
Example #3
0
def home(request):
    p = HomePage.get_solo()
    items = []
    items.extend(Section.objects.all())
    items.extend(Page.objects.all())
    context = {
        'page': p,
        'background': DefaultBackground.get_solo().background,
        'pushes': HomePagePush.objects.all(),
        'items': items,
    }
    return render(request, 'pages/home.html', context)