VersionLog manager
This commit is contained in:
parent
050c210f40
commit
52fc4a5df4
@ -127,7 +127,7 @@ class PackageHandler(AnonymousBaseHandler):
|
|||||||
order_by('-datetime')[:1]
|
order_by('-datetime')[:1]
|
||||||
log = log[0] if log else None
|
log = log[0] if log else None
|
||||||
|
|
||||||
vlog = VersionLog.objects.filter(package=package).order_by('-id')
|
vlog = VersionLog.objects.for_package(package, order=True)
|
||||||
|
|
||||||
herds = []
|
herds = []
|
||||||
for herd in package.herds.all():
|
for herd in package.herds.all():
|
||||||
|
@ -77,7 +77,7 @@ class PackageFeed(BaseFeed):
|
|||||||
return package.description
|
return package.description
|
||||||
|
|
||||||
def items(self, package):
|
def items(self, package):
|
||||||
return VersionLog.objects.filter(package=package).order_by('-id')[:30]
|
return VersionLog.objects.for_package(package, order=True)[:30]
|
||||||
|
|
||||||
def item_description(self, vlog):
|
def item_description(self, vlog):
|
||||||
return ''
|
return ''
|
||||||
@ -100,8 +100,7 @@ class MaintainerFeed(BaseFeed):
|
|||||||
kwargs={'maintainer_id': maintainer.id})
|
kwargs={'maintainer_id': maintainer.id})
|
||||||
|
|
||||||
def items(self, maintainer):
|
def items(self, maintainer):
|
||||||
q = VersionLog.objects.filter(package__maintainers__id=maintainer.id)
|
return VersionLog.objects.for_maintainer(maintainer, order=True)[:50]
|
||||||
return q.order_by('-id')[:50]
|
|
||||||
|
|
||||||
|
|
||||||
class HerdFeed(BaseFeed):
|
class HerdFeed(BaseFeed):
|
||||||
@ -120,8 +119,7 @@ class HerdFeed(BaseFeed):
|
|||||||
return reverse('djeuscan.views.herd', kwargs={'herd': herd.herd})
|
return reverse('djeuscan.views.herd', kwargs={'herd': herd.herd})
|
||||||
|
|
||||||
def items(self, herd):
|
def items(self, herd):
|
||||||
q = VersionLog.objects.filter(package__herds__id=herd.id)
|
return VersionLog.objects.for_herd(herd, order=True)[:100]
|
||||||
return q.order_by('-id')[:100]
|
|
||||||
|
|
||||||
|
|
||||||
class CategoryFeed(BaseFeed):
|
class CategoryFeed(BaseFeed):
|
||||||
@ -142,5 +140,4 @@ class CategoryFeed(BaseFeed):
|
|||||||
return reverse('djeuscan.views.category', args=[category])
|
return reverse('djeuscan.views.category', args=[category])
|
||||||
|
|
||||||
def items(self, category):
|
def items(self, category):
|
||||||
q = VersionLog.objects.filter(package__category=category)
|
return VersionLog.objects.for_category(category, order=True)[:100]
|
||||||
return q.order_by('-id')[:100]
|
|
||||||
|
@ -131,3 +131,32 @@ class PackageQuerySet(models.query.QuerySet, PackageMixin):
|
|||||||
class PackageManager(models.Manager, PackageMixin):
|
class PackageManager(models.Manager, PackageMixin):
|
||||||
def get_query_set(self):
|
def get_query_set(self):
|
||||||
return PackageQuerySet(self.model, using=self._db)
|
return PackageQuerySet(self.model, using=self._db)
|
||||||
|
|
||||||
|
|
||||||
|
class VersionLogMixin(object):
|
||||||
|
def for_package(self, package, order=False):
|
||||||
|
res = filter(package=package)
|
||||||
|
if order:
|
||||||
|
res = res.order_by('-id')
|
||||||
|
return res
|
||||||
|
|
||||||
|
def for_maintainer(self, maintainer, order=False):
|
||||||
|
res = self.filter(package__maintainers__id=maintainer.id)
|
||||||
|
if order:
|
||||||
|
res = res.order_by('-id')
|
||||||
|
return res
|
||||||
|
|
||||||
|
def for_category(self, category, order=False):
|
||||||
|
res = self.filter(package__category=category)
|
||||||
|
if order:
|
||||||
|
res = res.order_by('-id')
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
class VersionLogQuerySet(models.query.QuerySet, VersionLogMixin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class VersionLogManager(models.Manager, VersionLogMixin):
|
||||||
|
def get_query_set(self):
|
||||||
|
return VersionLogQuerySet(self.model, using=self._db)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from djeuscan.managers import PackageManager
|
from djeuscan.managers import PackageManager, VersionLogManager
|
||||||
|
|
||||||
|
|
||||||
class Herd(models.Model):
|
class Herd(models.Model):
|
||||||
@ -114,6 +114,8 @@ class VersionLog(models.Model):
|
|||||||
overlay = models.CharField(max_length=128, default='gentoo')
|
overlay = models.CharField(max_length=128, default='gentoo')
|
||||||
action = models.IntegerField(choices=VERSION_ACTIONS)
|
action = models.IntegerField(choices=VERSION_ACTIONS)
|
||||||
|
|
||||||
|
objects = VersionLogManager()
|
||||||
|
|
||||||
def tag(self):
|
def tag(self):
|
||||||
return '%s-%s:%s-[%s]' % (self.version, self.revision, self.slot,
|
return '%s-%s:%s-[%s]' % (self.version, self.revision, self.slot,
|
||||||
self.overlay)
|
self.overlay)
|
||||||
|
@ -102,7 +102,7 @@ def package(request, category, package):
|
|||||||
log = EuscanResult.objects.filter(package=package).\
|
log = EuscanResult.objects.filter(package=package).\
|
||||||
order_by('-datetime')[:1]
|
order_by('-datetime')[:1]
|
||||||
log = log[0] if log else None
|
log = log[0] if log else None
|
||||||
vlog = VersionLog.objects.filter(package=package).order_by('-id')
|
vlog = VersionLog.objects.for_package(package, order=True)
|
||||||
|
|
||||||
return {'package': package, 'packaged': packaged,
|
return {'package': package, 'packaged': packaged,
|
||||||
'upstream': upstream, 'log': log, 'vlog': vlog}
|
'upstream': upstream, 'log': log, 'vlog': vlog}
|
||||||
|
Loading…
Reference in New Issue
Block a user