def index(request, slug=None): section = None if slug is None: meta = MetaSeo() meta.metatitle = _('Catalog') crumbs = [{'label': _('Catalog')}] else: section = Section.objects.get(slug=slug) if section is None: raise Http404('Section with slug "%s" not found' % slug) crumbs = [{ 'label': _('Catalog'), 'url': reverse('midnight_catalog:catalog_list') }] + section.get_breadcrumbs() meta = MetaSeo(section) products = get_by_page(get_all(slug), request.GET.get('page'), getattr(settings, 'MIDNIGHT_CATALOG_PAGE_SIZE', 20)) return render(request, 'midnight_catalog/catalog/index.html', { 'products': products, 'section': section, 'meta': meta, 'crumbs': crumbs })
def index(request, slug=None): section = None if slug is None: q = News.objects.published() meta = MetaSeo() meta.metatitle = _('News') crumbs = [{'label': _('News')}] else: section = Section.objects.get(slug=slug) if section is None: raise Http404('Section with slug "%s" not found' % slug) crumbs = section.get_breadcrumbs() meta = MetaSeo(section) q = News.objects.published().filter(sections__slug=slug) q = q.prefetch_related('sections').order_by('-date', '-id') q = q.all() news = get_by_page(q, request.GET.get('page'), getattr(settings, 'MIDNIGHT_NEWS_PAGE_SIZE', 20)) return render(request, 'midnight_news/news/index.html', {'news': news, 'section': section, 'meta': meta, 'crumbs': crumbs})
def index(request, slug=None): section = None if slug is None: q = News.objects.published() meta = MetaSeo() meta.metatitle = _('News') crumbs = [{'label': _('News')}] else: section = Section.objects.get(slug=slug) if section is None: raise Http404('Section with slug "%s" not found' % slug) crumbs = section.get_breadcrumbs() meta = MetaSeo(section) q = News.objects.published().filter(sections__slug=slug) q = q.prefetch_related('sections').order_by('-date', '-id') q = q.all() news = get_by_page(q, request.GET.get('page'), getattr(settings, 'MIDNIGHT_NEWS_PAGE_SIZE', 20)) return render(request, 'midnight_news/news/index.html', { 'news': news, 'section': section, 'meta': meta, 'crumbs': crumbs })
def detail(request, section_slug, slug): item = get_one(slug) if not item: raise Http404('Item with slug "%s" not found' % slug) section = get_object_or_404(Section, slug=section_slug, active=True) crumbs = [{ 'label': _('Catalog'), 'url': reverse('midnight_catalog:catalog_list') }] + section.get_breadcrumbs(True) + [{ 'label': item.title }] text = Template(item.text).render(Context()) meta = MetaSeo(item) comments = get_object_comments(ProductComment, item.id) comments_form = ProductCommentForm(initial=get_comment_init(request, item)) return render( request, 'midnight_catalog/catalog/detail.html', { 'item': item, 'text': text, 'meta': meta, 'crumbs': crumbs, 'comments': comments, 'comments_form': comments_form })
def detail(request, section_slug, slug): item = get_object_or_404(News, slug=slug, active=True) section = get_object_or_404(Section, slug=section_slug, active=True) crumbs = section.get_breadcrumbs(True) + [{'label': item.title}] text = Template(item.text).render(Context()) meta = MetaSeo(item) comments = get_object_comments(NewsComment, item.id) comments_form = NewsCommentForm(initial=get_comment_init(request, item)) return render( request, 'midnight_news/news/detail.html', { 'item': item, 'text': text, 'meta': meta, 'crumbs': crumbs, 'comments': comments, 'comments_form': comments_form })
def index(request, slug=None): section = None if slug is None: meta = MetaSeo() meta.metatitle = _('Catalog') crumbs = [{'label': _('Catalog')}] else: section = Section.objects.get(slug=slug) if section is None: raise Http404('Section with slug "%s" not found' % slug) crumbs = [{'label': _('Catalog'), 'url': reverse('midnight_catalog:catalog_list')}] + section.get_breadcrumbs() meta = MetaSeo(section) products = get_by_page(get_all(slug), request.GET.get('page'), getattr(settings, 'MIDNIGHT_CATALOG_PAGE_SIZE', 20)) return render(request, 'midnight_catalog/catalog/index.html', {'products': products, 'section': section, 'meta': meta, 'crumbs': crumbs})
def get_page_tpl_ctx(page, request): """ Возвращает контекст для рендеринга представления текстовой страницы :param page: модель страницы :param request: запрос :return: """ text = Template(page.text).render(Context()) meta = MetaSeo(page) comments = get_object_comments(PageComment, page.id) comments_form = PageCommentForm(initial=get_comment_init(request, page)) if page.slug == Page.MAIN_SLUG: crumbs = None else: crumbs = page.get_breadcrumbs() return { 'page': page, 'comments': comments, 'comments_form': comments_form, 'text': text, 'meta': meta, 'crumbs': crumbs }