Beispiel #1
0
def tag_filter(request):
    tags = ArticlePage.tags.order_by('name')

    # ArticlePage.objects.live().filter(tags__name__in=value['tags'])

    # Tag
    tag = request.GET.get('tag')
    if tag:
        articles = ArticlePage.objects.live().filter(tags__name=tag)
    else:
        articles = ArticlePage.objects.none()

    # Pagination
    page = request.GET.get('page')
    page_size = 10
    if GeneralSettings.for_site(request.site).pagination_count:
        page_size = GeneralSettings.for_site(request.site).pagination_count

    if page_size is not None:
        paginator = Paginator(articles, page_size)
        try:
            articles = paginator.page(page)
        except PageNotAnInteger:
            articles = paginator.page(1)
        except EmptyPage:
            articles = paginator.page(paginator.num_pages)

    return render(request, 'blog/tag_filter.html', {
        'tag_query': tag,
        'tags': tags,
        'filter_results': articles,
    })
Beispiel #2
0
def search(request):
    search_query = request.GET.get('query', None)

    # Search
    if search_query:
        search_results = ArticlePage.objects.live().search(search_query)
        query = Query.get(search_query)

        # Record hit
        query.add_hit()
    else:
        search_results = ArticlePage.objects.none()

    # Pagination
    page = request.GET.get('page')
    page_size = 10
    from home.models import GeneralSettings
    if GeneralSettings.for_site(request.site).pagination_count:
        page_size = GeneralSettings.for_site(request.site).pagination_count

    if page_size is not None:
        paginator = Paginator(search_results, page_size)
        try:
            search_results = paginator.page(page)
        except PageNotAnInteger:
            search_results = paginator.page(1)
        except EmptyPage:
            search_results = paginator.page(paginator.num_pages)

    return render(request, 'search/search.html', {
        'search_query': search_query,
        'search_results': search_results,
    })
Beispiel #3
0
    def get_context(self, request, *args, **kwargs):
        """
        Add recipes to the context for recipe category listings
        """
        context = super(CategoryPage,
                        self).get_context(request, *args, **kwargs)
        recipes = self.get_recipes()

        # Pagination
        page = request.GET.get('page')
        page_size = 10
        from home.models import GeneralSettings
        if GeneralSettings.for_site(request.site).pagination_count:
            page_size = GeneralSettings.for_site(request.site).pagination_count

        if page_size is not None:
            paginator = Paginator(recipes, page_size)
            try:
                recipes = paginator.page(page)
            except PageNotAnInteger:
                recipes = paginator.page(1)
            except EmptyPage:
                recipes = paginator.page(paginator.num_pages)

        context['recipes'] = recipes
        return context
Beispiel #4
0
def articles(request):
    # Show all articles, sorted newest to oldest
    articles = ArticlePage.objects.live().order_by('-date')

    # Pagination
    page = request.GET.get('page')
    page_size = 10
    if GeneralSettings.for_site(request.site).pagination_count:
        page_size = GeneralSettings.for_site(request.site).pagination_count

    if page_size is not None:
        paginator = Paginator(articles, page_size)
        try:
            articles = paginator.page(page)
        except PageNotAnInteger:
            articles = paginator.page(1)
        except EmptyPage:
            articles = paginator.page(paginator.num_pages)

    return render(request, 'blog/articles.html', {
        'articles': articles,
    })
Beispiel #5
0
    def get_context(self, request, *args, **kwargs):
        context = super(ArticleIndexPage, self).get_context(
            request, *args, **kwargs)
        articles = self.articles()

        # Pagination
        page = request.GET.get('page')
        page_size = 10
        from home.models import GeneralSettings
        if GeneralSettings.for_site(request.site).pagination_count:
            page_size = GeneralSettings.for_site(request.site).pagination_count

        if page_size is not None:
            paginator = Paginator(articles, page_size)
            try:
                articles = paginator.page(page)
            except PageNotAnInteger:
                articles = paginator.page(1)
            except EmptyPage:
                articles = paginator.page(paginator.num_pages)

        context['articles'] = articles
        return context
Beispiel #6
0
    def get_context(self, request, *args, **kwargs):
        context = super(AudiencePage,
                        self).get_context(request, *args, **kwargs)
        articles = ArticlePage.objects.live().filter(
            article_audiences__audience=self).order_by('-date')

        # Pagination
        page = request.GET.get('page')
        page_size = 10
        from home.models import GeneralSettings
        if GeneralSettings.for_site(request.site).pagination_count:
            page_size = GeneralSettings.for_site(request.site).pagination_count

        if page_size is not None:
            paginator = Paginator(articles, page_size)
            try:
                articles = paginator.page(page)
            except PageNotAnInteger:
                articles = paginator.page(1)
            except EmptyPage:
                articles = paginator.page(paginator.num_pages)

        context['articles'] = articles
        return context
Beispiel #7
0
def random(request):
    """
    Get a random recipe to make for dinner
    """
    # Get a random recipe
    random_recipe_category = GeneralSettings.for_site(
        request.site).random_recipe_category
    print('CAT:', random_recipe_category)
    if random_recipe_category:
        # Get from a specific category, if one set in settings
        random_recipe = random_recipe_category.get_recipes().order_by(
            '?').first()
    else:
        # Otherwise, pick any random recipe (any category)
        random_recipe = RecipePage.objects.live().order_by('?').first()
    print('RECIPE', random_recipe)

    return render(request, 'search/random.html', {
        'random_recipe': random_recipe,
    })