-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
45 lines (42 loc) · 1.96 KB
/
views.py
File metadata and controls
45 lines (42 loc) · 1.96 KB
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
37
38
39
40
41
42
43
44
45
from tagging.models import Tag, TaggedItem
from rewinder.lib.stateful_paginator import DiggPaginator
from rewinder.lib.shortcuts import render_response
from rewinder.apps.blog.models import Article
from rewinder.apps.delicious.models import Bookmark
from rewinder.apps.video.models import Video
from rewinder.apps.flickr.models import Photo
from rewinder.apps.twitter.models import Tweet
from rewinder.apps.generic.models import Quote
def list(request, app, model, ordering='-pub_date'):
ctx = None
items = model.objects.all().order_by('%s' % ordering)
if model.__name__.lower() == "tumblelogitem":
links = Bookmark.objects.count()
photos = Photo.sixminutes.all().count()
videos = Video.objects.count()
tweets = Tweet.objects.count()
quotes = Quote.objects.count()
ctx = {'total': items.count(), 'links': links, 'photos': photos, 'videos': videos, 'tweets': tweets, 'quotes': quotes}
page = request.GET.get('page', 1)
paginator = DiggPaginator(items, 10, page=page, body=7, tail=2, padding=3)
template_name = '%s/%s_list.html' % (app.lower(), model.__name__.lower())
return render_response(request, template_name, {'page': page, 'paginator': paginator, 'extra': ctx})
def all_tags(request):
return render_response(request, 'tag/tag_list.html')
def tag_detail(request, tag):
articles = TaggedItem.objects.get_by_model(Article, tag)
links = TaggedItem.objects.get_by_model(Bookmark, tag)
videos = TaggedItem.objects.get_by_model(Video, tag)
photos = TaggedItem.objects.get_by_model(Photo, tag)
quotes = TaggedItem.objects.get_by_model(Quote, tag)
count = articles.count() + links.count() + videos.count() + photos.count() + quotes.count()
tag_dict = {
'tag': tag,
'total': count,
'articles': articles,
'links': links,
'videos': videos,
'photos': photos,
'quotes': quotes,
}
return render_response(request, 'tag/tag_detail.html', tag_dict)