How to use the dispatch.apps.content.models.Article.objects.filter function in dispatch

To help you get started, we’ve selected a few dispatch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ubyssey / dispatch / dispatch / apps / manager / views.py View on Github external
def section(request, section):
    section = Section.objects.get(name=section)
    article_list = Article.objects.filter(section=section,is_active=True,head=True).order_by('-created_at')

    q = request.GET.get('q', '')
    if q:
        article_list = article_list.filter(headline__icontains=q)

    unpublished = article_list.exclude(status=Article.PUBLISHED).count()

    paginator = Paginator(article_list, 15) # Show 15 articles per page

    page = request.GET.get('page')

    try:
        articles = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        articles = paginator.page(1)
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
if order == 'newest':
            order_by = '-published_at'
        else:
            order_by = 'published_at'

        context = {
            'order': order,
            'q': query
        }

        if query is not None:

            title = 'Search results for "%s"' % query

            article_list = Article.objects.filter(is_published=True, headline__icontains=query).order_by(order_by)

            paginator = Paginator(article_list, 15) # Show 15 articles per page

            page = request.GET.get('page')

            try:
                articles = paginator.page(page)
            except PageNotAnInteger:
                # If page is not an integer, deliver first page.
                articles = paginator.page(1)
            except EmptyPage:
                # If page is out of range (e.g. 9999), deliver last page of results.
                articles = paginator.page(paginator.num_pages)

            context['articles'] = articles
            context['count'] = paginator.count
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
def author(self, request, slug=None):

        try:
            person = Person.objects.get(slug=slug)
        except:
            raise Http404("Author could not be found.")

        articles = Article.objects.filter(authors=person, is_published=True)[:6]

        context = {
            'meta': self.get_author_meta(person),
            'person': person,
            'articles': articles
        }

        return render(request, 'author/base.html', context)
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
def section(self, request, section):

        section = Section.objects.get(slug=section)
        articles = Article.objects.filter(head=True,section=section)

        context = {
            'section': section,
            'articles': articles,
        }

        return render(request, 'section/base.html', context)
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
def section(self, request, slug=None):

        try:
            section = Section.objects.get(slug=slug)
        except:
            return self.page(request, slug)

        articles = Article.objects.filter(section=section, is_published=True).order_by('-published_at')

        context = {
            'meta': {
                'title': section.name
            },
            'section': section,
            'type': 'section',
            'articles': {
                'first': articles[0],
                'rest': articles[1:9]
            }
        }

        t = loader.select_template(["%s/%s" % (section.slug, 'section.html'), 'section.html'])
        return HttpResponse(t.render(context))