diff options
author | eliott <eliott@cactuswax.net> | 2008-04-12 06:35:29 +0200 |
---|---|---|
committer | eliott <eliott@cactuswax.net> | 2008-04-12 06:35:29 +0200 |
commit | 7e27644c8e67e3b9f4cd521f86cef25223ba6d0e (patch) | |
tree | 5657284e222a29f4749fb1e16b4d4b3eb53ee3c9 /main | |
parent | 2f7ebf85587640387e1cdc4168e30ef16f00f6b8 (diff) | |
download | archweb-7e27644c8e67e3b9f4cd521f86cef25223ba6d0e.tar.gz archweb-7e27644c8e67e3b9f4cd521f86cef25223ba6d0e.tar.xz |
Refactored the urlize sections to remove display/view data from the model.
Renamed methods, and methods now return raw data to the view layer.
Diffstat (limited to 'main')
-rw-r--r-- | main/models.py | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/main/models.py b/main/models.py index 62f230c..83f4fe8 100644 --- a/main/models.py +++ b/main/models.py @@ -192,18 +192,31 @@ class Package(models.Model): def get_absolute_url(self): return '/packages/%i/' % self.id - def required_by_urlize(self): - urls = [] + def get_requiredby(self): + """ + Returns a list of tuples(2). + + Each tuple in the list is as follows: (packageid, packagename) + """ + reqs = [] requiredby = PackageDepend.objects.filter(depname=self.pkgname).filter( Q(pkg__arch=self.arch) | Q(pkg__arch__name__iexact='any') ).order_by('depname') for req in requiredby: - urls.append('<li><a href="/packages/%d/">%s</a></li>' % \ - (req.pkg.id,req.pkg.pkgname)) - return ''.join(urls) + reqs.append((req.pkg.id,req.pkg.pkgname)) + return reqs + + def get_depends(self): + """ + Returns a list of tuples(3). - def depends_urlize(self): - urls = [] + Each tuple in the list is one of: + - (packageid, dependname, depend compare string) if a matching + package is found. + - (None, dependname, None) if no matching package is found, eg + it is a virtual dep. + """ + deps = [] for dep in self.packagedepend_set.order_by('depname'): try: # we only need depend on same-arch-packages @@ -212,13 +225,11 @@ class Package(models.Model): pkgname=dep.depname) except Package.DoesNotExist, IndexError: # couldn't find a package in the DB - # it might be a virtual depend - urls.append('<li>%s</li>' % dep.depname) + # it should be a virtual depend (or a removed package) + deps.append((None, dep.depname, None)) continue - urls.append( - '<li><a href="/packages/%d/">%s</a>%s</li>' % \ - (p.id,dep.depname,dep.depvcmp)) - return ''.join(urls) + deps.append((p.id,dep.depname,dep.depvcmp)) + return deps class PackageFile(models.Model): id = models.AutoField(primary_key=True) |