summaryrefslogtreecommitdiff
path: root/main/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'main/models.py')
-rw-r--r--main/models.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/main/models.py b/main/models.py
index a561f4f6..2f4d3520 100644
--- a/main/models.py
+++ b/main/models.py
@@ -7,10 +7,9 @@ from django.db import models
from django.db.models import Q
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
-from django.utils.timezone import now
from .fields import PositiveBigIntegerField
-from .utils import cache_function, set_created_field
+from .utils import set_created_field
from devel.models import DeveloperKey
from packages.alpm import AlpmAPI
@@ -140,7 +139,7 @@ class Package(models.Model):
@property
def signature(self):
try:
- data = b64decode(self.pgp_signature)
+ data = b64decode(self.pgp_signature.encode('utf-8'))
except TypeError:
return None
if not data:
@@ -187,7 +186,6 @@ class Package(models.Model):
self._applicable_arches = list(arches)
return self._applicable_arches
- #@cache_function(119)
def get_requiredby(self):
"""
Returns a list of package objects. An attempt will be made to keep this
@@ -195,14 +193,22 @@ class Package(models.Model):
category as this package if that check makes sense.
"""
from packages.models import Depend
+ sorttype = '''(CASE deptype
+ WHEN 'D' THEN 0
+ WHEN 'O' THEN 1
+ WHEN 'M' THEN 2
+ WHEN 'C' THEN 3
+ ELSE 1000 END)'''
name_clause = '''packages_depend.name IN (
SELECT %s UNION ALL
SELECT z.name FROM packages_provision z WHERE z.pkg_id = %s
)'''
requiredby = Depend.objects.select_related('pkg',
'pkg__arch', 'pkg__repo').extra(
- where=[name_clause], params=[self.pkgname, self.id]).order_by(
- 'pkg__pkgname', 'pkg__arch__name', 'pkg__repo__name')
+ select={'sorttype': sorttype},
+ where=[name_clause], params=[self.pkgname, self.id]).order_by(
+ 'sorttype', 'pkg__pkgname',
+ 'pkg__arch__name', 'pkg__repo__name')
if not self.arch.agnostic:
# make sure we match architectures if possible
requiredby = requiredby.filter(
@@ -265,7 +271,6 @@ class Package(models.Model):
trimmed.append(dep)
return trimmed
- #@cache_function(121)
def get_depends(self):
"""
Returns a list of dicts. Each dict contains ('dep', 'pkg', and
@@ -276,7 +281,6 @@ class Package(models.Model):
Packages will match the testing status of this package if possible.
"""
deps = []
- arches = None
# TODO: we can use list comprehension and an 'in' query to make this
# more effective
for dep in self.depends.all():
@@ -293,7 +297,6 @@ class Package(models.Model):
return (sort_order.get(dep.deptype, 1000), dep.name)
return sorted(deps, key=sort_key)
- #@cache_function(123)
def reverse_conflicts(self):
"""
Returns a list of packages with conflicts against this package.
@@ -403,13 +406,13 @@ class Package(models.Model):
'''attempt to locate this package anywhere else, regardless of
architecture or repository. Excludes this package from the list.'''
names = [self.pkgname]
- if self.pkgname.startswith('lib32-'):
+ if self.pkgname.startswith(u'lib32-'):
names.append(self.pkgname[6:])
- elif self.pkgname.endswith('-multilib'):
+ elif self.pkgname.endswith(u'-multilib'):
names.append(self.pkgname[:-9])
else:
- names.append('lib32-' + self.pkgname)
- names.append(self.pkgname + '-multilib')
+ names.append(u'lib32-' + self.pkgname)
+ names.append(self.pkgname + u'-multilib')
return Package.objects.normal().filter(
pkgname__in=names).exclude(id=self.id).order_by(
'arch__name', 'repo__name')