Example #1
0
def generic_search(request, models, filters={}, form_name="form", page=1):
    context = {}

    if request.method == "GET":
        form = SearchForm(request.GET)
        if form.is_valid():
            query = form.cleaned_data["query"]
            context["query"] = query

            for model in models:
                new_query = query
                model_name = model.__name__.lower()
                filter = filters.get(model_name, {})

                resultset = model.indexer.search(query=query).prefetch()

                result_page = paginate(
                    resultset,
                    page,
                    settings.TURBION_BLOG_POSTS_PER_PAGE
                )

                context["%s_page" % model_name] = result_page
    else:
        form = SearchForm()

    context[form_name] = form

    return context
Example #2
0
def index(request):
    profile = get_profile(request)
    return {
        'profile': profile,
        'comments_page': paginate(
            watchlist.get_subcription_comments(profile),
            request.page,
            settings.TURBION_BLOG_POSTS_PER_PAGE
        ),
        'subscriptions': profile.subscriptions.filter(event__name='new_comment').\
                                        order_by('date').distinct()
    }
Example #3
0
def year(request, year_id):
    post_page = paginate(
        Post.published.filter(published_on__year=year_id),
        request.page,
        settings.TURBION_BLOG_POSTS_PER_PAGE
    )

    return {
        "post_page": post_page,
        "on": "year",
        "year": year_id
    }
Example #4
0
def month(request, year_id, month_id):
    post_page = paginate(
        Post.published.filter(
            published_on__year=int(year_id),
            published_on__month=int(month_id)
        ),
        request.page,
        settings.TURBION_BLOG_POSTS_PER_PAGE
    )

    return {
        "post_page" : post_page,
        "on": "month",
        "year": year_id,
        'month': month_id
    }
Example #5
0
def tag(request, tag_slug):
    _tag = get_object_or_404(Tag.active, slug=tag_slug)
    posts = _tag.posts.all()

    if not get_profile(request).is_trusted():
        posts = posts.filter(showing=Post.show_settings.everybody)

    post_page = paginate(
        posts,
        request.page,
        settings.TURBION_BLOG_POSTS_PER_PAGE
    )

    return {
        "tag": _tag,
        "post_page": post_page
    }
Example #6
0
def blog(request):
    posts = Post.published.all()

    if not get_profile(request).is_trusted():
        posts = posts.filter(showing=Post.show_settings.everybody)

    post_page = paginate(
        posts,
        request.page,
        settings.TURBION_BLOG_POSTS_PER_PAGE
    )

    context = {
        "post_page": post_page
    }

    return context
Example #7
0
def day(request, year_id, month_id, day_id):
    post_page = paginate(
        Post.published.filter(
            published_on__year=year_id,
            published_on__month=month_id,
            published_on__day=day_id
        ),
        request.page,
        settings.TURBION_BLOG_POSTS_PER_PAGE
    )

    return {
        "post_page": post_page,
        "on": "day",
        "year": year_id,
        'month': month_id,
        'day': day_id
    }