Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f91740997e
Fetching contributors…

Cannot retrieve contributors at this time

85 lines (65 sloc) 2.879 kb
# richard -- video index system
# Copyright (C) 2012, 2013 richard contributors. See AUTHORS.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <>.
from django.conf import settings
from django.db.models import Count
from django.shortcuts import render
from richard.videos.models import Video, Category, Speaker, Tag
from richard.sitenews.models import SiteNews
from richard.suggestions.models import Suggestion
def home(request):
latest_categories = Category.objects.order_by('-start_date')[:10]
latest_videos ='-added')[:10]
news_list = SiteNews.objects.all()[:5]
video_count =
ret = render(
request, 'home.html',
{'title': settings.SITE_TITLE,
'news': news_list,
'latest_categories': latest_categories,
'latest_videos': latest_videos,
'video_count': video_count})
return ret
def login_failure(request):
return render(request, 'login_failure.html')
def stats(request):
"""List statistics about the collection.
E.g. number of videos, top 5 categories.
# Retrieve objects of model `m`, ordered by the number of videos they have
most_videos = lambda m: (m.objects.filter(video__state=Video.STATE_LIVE)
video_count =
category_count = Category.objects.count()
category_top5 = most_videos(Category)[:5]
speaker_count = Speaker.objects.count()
speaker_top5 = most_videos(Speaker)[:5]
tag_count = Tag.objects.count()
tag_top5 = most_videos(Tag)[:5]
open_states = (Suggestion.STATE_NEW, Suggestion.STATE_IN_PROGRESS)
suggestions = (Suggestion.objects.filter(state__in=open_states)
ret = render(
request, 'stats.html',
{'video_count': video_count,
'category_count': category_count,
'category_top5': category_top5,
'speaker_count': speaker_count,
'speaker_top5': speaker_top5,
'tag_count': tag_count,
'tag_top5': tag_top5,
'suggestions': suggestions})
return ret
Jump to Line
Something went wrong with that request. Please try again.