Ejemplo n.º 1
0
    def get_context_data(self, **kwargs):
        context = super(BlogDetailView, self).get_context_data(**kwargs)
        blog = get_object_or_404(Blog, slug=kwargs['blog_slug'], is_show=True)
        post = get_object_or_404(Post,
                                 slug=kwargs['post_slug'],
                                 blog_id=blog.id,
                                 is_show=True)

        initial = {
            'obj': post,
            'request': self.request,
        }
        comment_form = CommentForm(initial=initial)

        context.update({
            'post':
            post,
            'next_prev':
            get_next_prev(Post, post),
            'comment_form':
            comment_form,
            'comments':
            Comment.objects.filter(post_id=post.id,
                                   is_show=True).select_related(),
            'leftbar':
            get_leftbar(Blog, post.blog),
        })

        return context
Ejemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super(GalleryDetailView, self).get_context_data(**kwargs)
        context['object'] = Gallery.objects.get(slug=context['slug'])
        context['leftbar'] = get_leftbar(Gallery, context['object'])
        gallery_id = context['leftbar']['root_obj'].id
        context['current_mainmenu'] = context['mainmenu'].filter(
            gallery_id=gallery_id).first()

        context['objects'] = GalleryImage.objects.filter(
            gallery_id=context['object'])
        context['objects'] = get_pagination(self.request, context['objects'])

        return context
Ejemplo n.º 3
0
 def get_context_data(self, **kwargs):
     context = super(PageView, self).get_context_data(**kwargs)
     context['object'] = get_object_or_404(Page,
                                           slug=context['slug'],
                                           is_show=True)
     initial = {
         'obj': context['object'],
         'request': self.request,
     }
     comment_form = CommentForm(initial=initial)
     context['comment_form'] = comment_form
     context['leftbar'] = get_leftbar(Blog, Blog.objects.first())
     return context
Ejemplo n.º 4
0
 def get_context_data(self, **kwargs):
     context = super(BlogListView, self).get_context_data(**kwargs)
     context['object'] = Blog.objects.get(slug=context['slug'],
                                          is_show=True)
     context['leftbar'] = get_leftbar(Blog, context['object'])
     blog_id = context['leftbar']['root_obj'].id
     context['current_mainmenu'] = context['mainmenu'].filter(
         blog_id=blog_id,
         is_show=True,
     ).first()
     print(1)
     context['objects'] = Post.objects.filter(blog_id=context['object'].id,
                                              is_show=True)
     context['objects'] = sort_by_params(self.request, context['objects'])
     context['objects'] = get_pagination(self.request, context['objects'])
     return context
Ejemplo n.º 5
0
    def get_context_data(self, **kwargs):
        context = super(CatalogView, self).get_context_data(**kwargs)
        try:
            context['object'] = Catalog.objects.get(slug=context['slug'], is_show=True)
            context['leftbar'] = get_leftbar(Catalog, context['object'])
            catalog_id = context['leftbar']['root_obj'].id
            context['current_mainmenu'] = context['mainmenu'].filter(
                catalog_id=catalog_id
            ).first()

            context['objects'] = Product.objects.filter(catalog=context['object'], is_show=True).order_by('-id')
            context['objects'] = sort_by_params(self.request, context['objects'])
            context['objects'] = get_pagination(self.request, context['objects'])
        except Catalog.DoesNotExist:
            # --- redirect in product  ---
            self.template_name = 'product/templates/product_detail.html'
            context = ProductDetail.get_context_for_catalog(context)
        return context
Ejemplo n.º 6
0
    def get_context_data(self, **kwargs):
        context = super(ProductDetail, self).get_context_data(**kwargs)
        context['product'] = get_object_or_404(Product, slug=kwargs['product'])

        initial = {
            'obj': context['product'],
            'request': self.request,
        }
        comment_form = CommentForm(initial=initial)

        context['comment_form'] = comment_form
        context['comments'] = ProductComment.objects.filter(
            is_show=True, product_id=context['product'].id)
        context['catalog'] = get_object_or_404(Catalog, slug=kwargs['catalog'])
        context['cart_product_form'] = CartAddProductForm()
        context['next_prev'] = get_next_prev(Product, context['product'])
        context['leftbar'] = get_leftbar(Catalog, context['catalog'])

        return context
Ejemplo n.º 7
0
    def get_context_for_catalog(context):
        """
        Попадая на страницу какатога, если ее нет - перейти на страницу товара
        Todo: заглушка
        """
        context['template_name'] = 'product_detail.html'
        context['product'] = get_object_or_404(Product, slug=context['slug'])

        initial = {
            'obj': context['product'],
            'request': context['request'],
        }
        comment_form = CommentForm(initial=initial)

        context['comment_form'] = comment_form
        context['comments'] = ProductComment.objects.filter(
            is_show=True, product_id=context['product'].id)
        context['catalog'] = context['product'].catalog.first()
        context['cart_product_form'] = CartAddProductForm()
        context['next_prev'] = get_next_prev(Product, context['product'])
        context['leftbar'] = get_leftbar(Catalog, context['catalog'])
        return context