Exemple #1
0
def search(request):
    letters = [chr(num) for num in range(ord('A'), ord('Z') + 1)]
    form = SearchForm(request.GET or None)
    form.fields['genre'].choices = empty_choice + [
        (g.id, g.title) for g in Genre.objects.all().order_by('title')
    ]
    form.fields['label'].choices = empty_choice + [
        (tag.id, tag.title) for tag in Tags.objects.all().order_by('title')
    ]
    if request.GET:
        if form.is_valid():
            sql, values = build_query(request.GET)
            hits = list(Article.objects.raw(sql, values))
            if len(hits) == 1:
                return redirect(hits[0])
            paginator = Paginator(hits, 20)
            data = dict(request.GET)
            if 'page' in data:
                data.pop('page')
            data = dict((k, v[0]) for k, v in data.items() if v[0])
            return render(request, "search/list.html", {
                'hits': page(request, paginator),
                'qs': "&" + urlencode(data)
            })
    return render(request, "search/search.html", {
        'letters': letters,
        'form': form
    })
Exemple #2
0
def review_index(request):
    paginator = Paginator(Article.reviews.all().order_by("-dt"), 20)
    return render(
        request, "article/archive.html", {
            'articles': page(request, paginator),
            'blurb': "Reviews index",
            'title': 'Reviews'
        })
Exemple #3
0
def blog_index(request):
    paginator = Paginator(Article.posts.all().order_by("-dt"), 20)
    return render(
        request, "article/archive.html", {
            'articles': page(request, paginator),
            'blurb': "Blog index",
            'title': 'Blog'
        })
Exemple #4
0
def recent(request):
    """
    Recent page - all the things.
    """
    streams = [iter(Article.objects.filter(display=True).exclude(feature=True).order_by("-dt")[:100]),
               iter(MailBag.objects.filter(display=True).order_by("-dt")[:100])]
    mixed = sorta(streams, key=lambda obj: obj.dt, order=max, total=100)
    paginator = Paginator(list(mixed), 30)
    return render(request, "article/archive.html", {'articles': page(request, paginator),
                                                    'title': 'Recent',
                                                    'blurb': 'Recently added content'})
Exemple #5
0
def index(request):
    """
    View for the front page /
    """
    streams = [iter(Article.objects.filter(display=True).exclude(feature=True).order_by("-dt")[:50]),
               iter(MailBag.objects.filter(display=True).order_by("-dt")[:50])]
    mixed = sorta(streams, key=lambda obj: obj.dt, order=max, total=50)
    paginator = Paginator(list(mixed), 10)
    return render(request, "index.html", {'objects': page(request, paginator),
                                          'featured': Article.objects.filter(feature=True)[:1],
                                          'og_image': 'static/_theme/img/df-masthead.jpg',
                                          'title': ""
                                        })
Exemple #6
0
def recent(request):
    """
    Recent page - all the things.
    """
    streams = [
        iter(
            Article.objects.filter(display=True).exclude(
                feature=True).order_by("-dt")[:100]),
        iter(MailBag.objects.filter(display=True).order_by("-dt")[:100])
    ]
    mixed = sorta(streams, key=lambda obj: obj.dt, order=max, total=100)
    paginator = Paginator(list(mixed), 30)
    return render(
        request, "article/archive.html", {
            'articles': page(request, paginator),
            'title': 'Recent',
            'blurb': 'Recently added content'
        })
Exemple #7
0
def index(request):
    """
    View for the front page /
    """
    streams = [
        iter(
            Article.objects.filter(display=True).exclude(
                feature=True).order_by("-dt")[:50]),
        iter(MailBag.objects.filter(display=True).order_by("-dt")[:50])
    ]
    mixed = sorta(streams, key=lambda obj: obj.dt, order=max, total=50)
    paginator = Paginator(list(mixed), 10)
    return render(
        request, "index.html", {
            'objects': page(request, paginator),
            'featured': Article.objects.filter(feature=True)[:1],
            'og_image': 'static/_theme/img/df-masthead.jpg',
            'title': ""
        })
Exemple #8
0
def review_index(request):
    paginator = Paginator(Article.reviews.all().order_by("-dt"), 20)
    return render(request, "article/archive.html", {'articles': page(request, paginator),
                                                    'blurb': "Reviews index",
                                                    'title': 'Reviews'})
Exemple #9
0
def blog_index(request):
    paginator = Paginator(Article.posts.all().order_by("-dt"), 20)
    return render(request, "article/archive.html", {'articles': page(request, paginator),
                                                    'blurb': "Blog index",
                                                    'title': 'Blog'})