2011-04-13 08:50:24 +02:00
|
|
|
from annoying.decorators import render_to
|
|
|
|
from django.http import Http404
|
2011-04-15 00:24:45 +02:00
|
|
|
from django.shortcuts import get_object_or_404
|
2011-04-14 19:28:38 +02:00
|
|
|
from django.db.models import Sum, Max
|
|
|
|
|
|
|
|
from euscan.models import Version, Package, Herd, Maintainer, EuscanResult
|
2011-04-15 19:28:37 +02:00
|
|
|
from euscan.forms import WorldForm, WorldFileForm
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/index.html')
|
|
|
|
def index(request):
|
2011-04-14 19:28:38 +02:00
|
|
|
ctx = {}
|
|
|
|
ctx['n_packaged'] = Package.objects.aggregate(Sum('n_packaged'))['n_packaged__sum']
|
|
|
|
ctx['n_versions'] = Package.objects.aggregate(Sum('n_versions'))['n_versions__sum']
|
2011-04-15 19:28:37 +02:00
|
|
|
if ctx['n_versions'] is not None and ctx['n_packaged'] is not None:
|
2011-04-15 00:24:45 +02:00
|
|
|
ctx['n_upstream'] = ctx['n_versions'] - ctx['n_packaged']
|
2011-04-14 19:28:38 +02:00
|
|
|
ctx['n_packages'] = Package.objects.count()
|
|
|
|
ctx['n_herds'] = Herd.objects.count()
|
|
|
|
ctx['n_maintainers'] = Maintainer.objects.count()
|
|
|
|
ctx['last_scan'] = EuscanResult.objects.aggregate(Max('datetime'))['datetime__max']
|
|
|
|
return ctx
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/logs.html')
|
|
|
|
def logs(request):
|
|
|
|
return {}
|
|
|
|
|
|
|
|
@render_to('euscan/categories.html')
|
|
|
|
def categories(request):
|
2011-04-14 19:28:38 +02:00
|
|
|
categories = Package.objects.values('category').annotate(n_packaged=Sum('n_packaged'), n_versions=Sum('n_versions'))
|
|
|
|
return { 'categories' : categories }
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/category.html')
|
|
|
|
def category(request, category):
|
2011-04-15 00:24:45 +02:00
|
|
|
packages = Package.objects.filter(category=category)
|
|
|
|
if not packages:
|
|
|
|
raise Http404
|
|
|
|
return { 'category' : category, 'packages' : packages }
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/herds.html')
|
|
|
|
def herds(request):
|
2011-04-15 19:28:37 +02:00
|
|
|
# FIXME: optimize the query, it uses 'LEFT OUTER JOIN' instead of 'INNER JOIN'
|
|
|
|
herds = Package.objects.filter(herds__isnull=False).values('herds__herd').annotate(n_packaged=Sum('n_packaged'), n_versions=Sum('n_versions'))
|
|
|
|
return { 'herds' : herds }
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/herd.html')
|
|
|
|
def herd(request, herd):
|
2011-04-15 19:28:37 +02:00
|
|
|
herd = get_object_or_404(Herd, herd=herd)
|
|
|
|
packages = Package.objects.filter(herds__id=herd.id)
|
|
|
|
return { 'herd' : herd, 'packages' : packages }
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/maintainers.html')
|
|
|
|
def maintainers(request):
|
2011-04-15 19:28:37 +02:00
|
|
|
maintainers = Package.objects.filter(maintainers__isnull=False).values('maintainers__id', 'maintainers__name').annotate(n_packaged=Sum('n_packaged'), n_versions=Sum('n_versions'))
|
|
|
|
return { 'maintainers' : maintainers }
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/maintainer.html')
|
|
|
|
def maintainer(request, maintainer_id):
|
2011-04-15 19:28:37 +02:00
|
|
|
maintainer = get_object_or_404(Maintainer, id=maintainer_id)
|
|
|
|
packages = Package.objects.filter(maintainers__id=maintainer.id)
|
|
|
|
return { 'maintainer' : maintainer, 'packages' : packages }
|
2011-04-13 08:50:24 +02:00
|
|
|
|
|
|
|
@render_to('euscan/package.html')
|
|
|
|
def package(request, category, package):
|
2011-04-15 00:24:45 +02:00
|
|
|
package = get_object_or_404(Package, category=category, name=package)
|
|
|
|
packaged = Version.objects.filter(package=package, packaged=True)
|
|
|
|
upstream = Version.objects.filter(package=package, packaged=False)
|
|
|
|
return { 'package' : package, 'packaged' : packaged, 'upstream' : upstream }
|
2011-04-15 19:28:37 +02:00
|
|
|
|
|
|
|
@render_to('euscan/world.html')
|
|
|
|
def world(request):
|
|
|
|
form = WorldForm()
|
|
|
|
file_form = WorldFileForm()
|
|
|
|
|
|
|
|
return { 'form' : form , 'file_form' : file_form }
|
|
|
|
|
|
|
|
@render_to('euscan/world_scan.html')
|
|
|
|
def world_scan(request):
|
|
|
|
packages = []
|
|
|
|
|
|
|
|
# FIXME
|
|
|
|
if 'world_file' in request.FILES:
|
|
|
|
data = request.FILES['world_file'].read()
|
|
|
|
elif 'world' in request.POST:
|
|
|
|
data = request.POST['world']
|
|
|
|
else:
|
|
|
|
data = ""
|
|
|
|
|
|
|
|
for pkg in data.split('\n'):
|
|
|
|
try:
|
|
|
|
cat, pkg = pkg.split('/')
|
|
|
|
packages.append(Package.objects.get(category=cat, name=pkg))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return { 'packages' : packages }
|
|
|
|
|
|
|
|
|