summaryrefslogtreecommitdiff
path: root/app/links/views.py
blob: e95cff43fc4d1f938cd09b835e405a44fb28714e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from django.views.generic.detail import DetailView
from utils.views import PaginatedListView

from .models import Link
from taggit.models import Tag


class LinkListView(PaginatedListView):
    model = Link

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(LinkListView, self).get_context_data(**kwargs)
        context['tags'] = Link.tags.all()
        context['breadcrumbs'] = ('Links',)
        return context


class LinkTagListView(PaginatedListView):
    model = Link

    def get_queryset(self):
        return Link.objects.filter(tags__name__in=[self.kwargs['slug']])

    def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super(LinkTagListView, self).get_context_data(**kwargs)
        context['tag'] = Tag.objects.get(slug__exact=self.kwargs['slug'])
        context['tags'] = Link.tags.all()
        context['breadcrumbs'] = ('Links',)
        return context


class LinkDetailView(DetailView):
    model = Link
    slug_field = "id"