From de0ad4b210bf0b1463ded4e3f08e12e4d0589c2c Mon Sep 17 00:00:00 2001 From: volpino Date: Sun, 13 May 2012 16:42:29 +0200 Subject: [PATCH] issue #13 fixed --- euscanwww/djeuscan/managers.py | 23 +++++++ euscanwww/djeuscan/models.py | 5 +- euscanwww/djeuscan/templates/_base.html | 9 +++ euscanwww/djeuscan/views.py | 84 ++++++++++++++++++++++--- 4 files changed, 110 insertions(+), 11 deletions(-) diff --git a/euscanwww/djeuscan/managers.py b/euscanwww/djeuscan/managers.py index d36071d..2172602 100644 --- a/euscanwww/djeuscan/managers.py +++ b/euscanwww/djeuscan/managers.py @@ -145,3 +145,26 @@ class VersionLogQuerySet(models.query.QuerySet, VersionLogMixin): class VersionLogManager(models.Manager, VersionLogMixin): def get_query_set(self): return VersionLogQuerySet(self.model, using=self._db) + + +class EuscanResultMixin(object): + def for_package(self, package): + return self.filter(package=package) + + def for_maintainer(self, maintainer): + return self.filter(package__maintainers__id=maintainer.id) + + def for_category(self, category): + return self.filter(package__category=category) + + def for_herd(self, herd): + return self.filter(package__herds__id=herd.id) + + +class EuscanResultQuerySet(models.query.QuerySet, EuscanResultMixin): + pass + + +class EuscanResultManager(models.Manager, EuscanResultMixin): + def get_query_set(self): + return EuscanResultQuerySet(self.model, using=self._db) diff --git a/euscanwww/djeuscan/models.py b/euscanwww/djeuscan/models.py index 45a618b..afedef2 100644 --- a/euscanwww/djeuscan/models.py +++ b/euscanwww/djeuscan/models.py @@ -1,6 +1,7 @@ from django.db import models -from djeuscan.managers import PackageManager, VersionLogManager +from djeuscan.managers import PackageManager, VersionLogManager, \ + EuscanResultManager class Herd(models.Model): @@ -135,6 +136,8 @@ class EuscanResult(models.Model): datetime = models.DateTimeField() result = models.TextField(blank=True) + objects = EuscanResultManager() + class Meta: get_latest_by = "datetime" diff --git a/euscanwww/djeuscan/templates/_base.html b/euscanwww/djeuscan/templates/_base.html index 59fce7d..e2bcd44 100644 --- a/euscanwww/djeuscan/templates/_base.html +++ b/euscanwww/djeuscan/templates/_base.html @@ -1,4 +1,5 @@ {% load url from future %} +{% load timedelta %} @@ -57,6 +58,14 @@ {% endblock %}