From fb9158dec8b1b735fa653c98d07f78ca14eb425c Mon Sep 17 00:00:00 2001 From: Dusty Phillips Date: Tue, 7 Oct 2008 11:48:58 -0400 Subject: fairly invasive refactor to developer dashboard to be more django friendly --- devel/views.py | 27 +++++---------------------- main/models.py | 24 +++++------------------- templates/devel/index.html | 16 ++++++++-------- 3 files changed, 18 insertions(+), 49 deletions(-) diff --git a/devel/views.py b/devel/views.py index 002d2b52..77d4054b 100644 --- a/devel/views.py +++ b/devel/views.py @@ -13,7 +13,6 @@ def index(request): # get a list of incomplete package todo lists todos = Todolist.objects.get_incomplete() # get flagged-package stats for all maintainers - stats = Package.objects.get_flag_stats() if thismaint: # get list of flagged packages for this maintainer pkgs = Package.objects.filter( @@ -22,29 +21,13 @@ def index(request): else: pkgs = None - arch_stats = [] - for xarch in Arch.objects.all(): - arch_stats.append({ - 'name': xarch.name, - 'count': Package.objects.filter(arch=xarch).count(), - 'flagged': Package.objects.filter(arch=xarch).filter( - needupdate=True).exclude( - repo__name__iexact='testing').count() - }) - - repo_stats = [] - for xrepo in Repo.objects.all(): - repo_stats.append({ - 'name': xrepo.name, - 'count': Package.objects.filter(repo=xrepo).count(), - 'flagged': Package.objects.filter( - repo=xrepo).filter(needupdate=True).count() - }) - return render_response( request, 'devel/index.html', - {'stats': stats, 'pkgs': pkgs, 'todos': todos, 'maint': thismaint, - 'repos': repo_stats, 'arches': arch_stats}) + {'pkgs': pkgs, 'todos': todos, 'maint': thismaint, + 'repos': Repo.objects.all(), 'arches': Arch.objects.all(), + 'maintainers': + [User(id=0, first_name="Orphans")] + list(User.objects.all()) + }) #@is_maintainer def change_notify(request): diff --git a/main/models.py b/main/models.py index e7566c35..a2323c62 100644 --- a/main/models.py +++ b/main/models.py @@ -49,23 +49,9 @@ def get_incomplete(self): return results class PackageManager(models.Manager): - def get_flag_stats(self): - results = [] - # first the orphans - noflag = self.filter(maintainer=0) - flagged = noflag.filter( - needupdate=True).exclude( - repo__name__iexact='testing') - results.append( - (User(id=0,first_name='Orphans'), noflag.count(), flagged.count())) - # now the rest - for maint in User.objects.all().order_by('first_name'): - noflag = self.filter(maintainer=maint.id) - flagged = noflag.filter(needupdate=True).exclude( - repo__name__iexact='testing') - results.append((maint, noflag.count(), flagged.count())) - return results + def flagged(self): + return self.get_query_set().filter(needupdate=True) ############################# ### General Model Classes ### @@ -151,9 +137,9 @@ class Meta: class Package(models.Model): id = models.AutoField(primary_key=True) - repo = models.ForeignKey(Repo) - arch = models.ForeignKey(Arch) - maintainer = models.ForeignKey(User, related_name='package_maintainer') + repo = models.ForeignKey(Repo, related_name="packages") + arch = models.ForeignKey(Arch, related_name="packages") + maintainer = models.ForeignKey(User, related_name="maintained_packages") needupdate = models.BooleanField(default=False) pkgname = models.CharField(max_length=255) pkgver = models.CharField(max_length=255) diff --git a/templates/devel/index.html b/templates/devel/index.html index 33db1bf1..88794964 100644 --- a/templates/devel/index.html +++ b/templates/devel/index.html @@ -33,8 +33,8 @@

Stats by Architecture

{% for arch in arches %} {{ arch.name }} - {{ arch.count }} packages - {{ arch.flagged }} packages + {{ arch.packages.count }} packages + {{ arch.packages.flagged.count }} packages {% endfor %} @@ -51,8 +51,8 @@

Stats by Repository

{% for repo in repos %} {{ repo.name }} - {{ repo.count }} packages - {{ repo.flagged }} packages + {{ repo.packages.count }} packages + {{ repo.packages.flagged.count }} packages {% endfor %} @@ -67,11 +67,11 @@

Stats by Maintainer

# Packages # Flagged - {% for maint in stats %} + {% for maint in maintainers %} - {{ maint.0.get_full_name }} - {{ maint.1 }} packages - {{ maint.2 }} packages + {{ maint.get_full_name }} + {{ maint.maintained_packages.count }} packages + {{ maint.maintained_packages.flagged.count }} packages {% endfor %} -- cgit v1.2.3-54-g00ecf