From 1113462edcf69b81e93a9545198c1091e3bf6703 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 27 Mar 2010 16:58:02 -0500 Subject: Simplify code now that pkgbase is always defined This allows some of our queries to get a lot simpler as well as removing the pkgbase_safe property added earlier. Signed-off-by: Dan McGee --- devel/views.py | 2 +- main/models.py | 10 ++-------- packages/views.py | 8 ++++---- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/devel/views.py b/devel/views.py index 045e60f7..c202c735 100644 --- a/devel/views.py +++ b/devel/views.py @@ -23,7 +23,7 @@ def index(request): '''the Developer dashboard''' inner_q = PackageRelation.objects.filter(user=request.user).values('pkgbase') packages = Package.objects.select_related('arch', 'repo').filter(needupdate=True) - packages = packages.filter(Q(pkgname__in=inner_q) | Q(pkgbase__in=inner_q)) + packages = packages.filter(pkgbase__in=inner_q) page_dict = { 'todos': Todolist.objects.incomplete(), diff --git a/main/models.py b/main/models.py index 309d6b67..5ec38ceb 100644 --- a/main/models.py +++ b/main/models.py @@ -203,16 +203,10 @@ def get_absolute_url(self): return '/packages/%s/%s/%s/' % (self.repo.name.lower(), self.arch.name, self.pkgname) - @property - def pkgbase_safe(self): - if self.pkgbase: - return self.pkgbase - return self.pkgname - @property def maintainers(self): return User.objects.filter( - package_relations__pkgbase=self.pkgbase_safe, + package_relations__pkgbase=self.pkgbase, package_relations__type=PackageRelation.MAINTAINER) @property @@ -283,7 +277,7 @@ def get_svn_link(self, svnpath): root = 'community' else: root = 'packages' - return linkbase % (root, self.pkgbase_safe, svnpath) + return linkbase % (root, self.pkgbase, svnpath) def get_arch_svn_link(self): repo = self.repo.name.lower() diff --git a/packages/views.py b/packages/views.py index 47ad1d6c..efb64c51 100644 --- a/packages/views.py +++ b/packages/views.py @@ -48,12 +48,12 @@ def update(request): for pkg in pkgs: maints = pkg.maintainers if mode == 'adopt' and request.user not in maints: - pr = PackageRelation(pkgbase=pkg.pkgbase_safe, + pr = PackageRelation(pkgbase=pkg.pkgbase, user=request.user, type=PackageRelation.MAINTAINER) pr.save() elif mode == 'disown' and request.user in maints: - rels = PackageRelation.objects.filter(pkgbase=pkg.pkgbase_safe, + rels = PackageRelation.objects.filter(pkgbase=pkg.pkgbase, user=request.user) rels.delete() @@ -148,10 +148,10 @@ def search(request, page=None): if form.cleaned_data['maintainer'] == 'orphan': inner_q = PackageRelation.objects.all().values('pkgbase') - packages = packages.exclude(Q(pkgname__in=inner_q) | Q(pkgbase__in=inner_q)) + packages = packages.exclude(pkgbase__in=inner_q) elif form.cleaned_data['maintainer']: inner_q = PackageRelation.objects.filter(user__username=form.cleaned_data['maintainer']).values('pkgbase') - packages = packages.filter(Q(pkgname__in=inner_q) | Q(pkgbase__in=inner_q)) + packages = packages.filter(pkgbase__in=inner_q) if form.cleaned_data['flagged'] == 'Flagged': packages=packages.filter(needupdate=True) -- cgit v1.2.3-54-g00ecf