From 7e27644c8e67e3b9f4cd521f86cef25223ba6d0e Mon Sep 17 00:00:00 2001 From: eliott Date: Fri, 11 Apr 2008 21:35:29 -0700 Subject: Refactored the urlize sections to remove display/view data from the model. Renamed methods, and methods now return raw data to the view layer. --- main/models.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'main') diff --git a/main/models.py b/main/models.py index 62f230c9..83f4fe83 100644 --- a/main/models.py +++ b/main/models.py @@ -192,18 +192,31 @@ def __str__(self): 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('
  • %s
  • ' % \ - (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 @@ def depends_urlize(self): pkgname=dep.depname) except Package.DoesNotExist, IndexError: # couldn't find a package in the DB - # it might be a virtual depend - urls.append('
  • %s
  • ' % dep.depname) + # it should be a virtual depend (or a removed package) + deps.append((None, dep.depname, None)) continue - urls.append( - '
  • %s%s
  • ' % \ - (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) -- cgit v1.2.3-54-g00ecf