[csw-devel] SF.net SVN: gar:[12977] csw/mgar/gar/v2/lib/python/models.py
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Mon Jan 17 10:29:03 CET 2011
Revision: 12977
http://gar.svn.sourceforge.net/gar/?rev=12977&view=rev
Author: wahwah
Date: 2011-01-17 09:29:03 +0000 (Mon, 17 Jan 2011)
Log Message:
-----------
pkgdb: Add __unicode__ methods to models
The __unicode__ methods define the way an object should be presented in text.
When displaying objects in HTML templates, simply saying $obj will use
__unicode__ to display the object.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/python/models.py
Modified: csw/mgar/gar/v2/lib/python/models.py
===================================================================
--- csw/mgar/gar/v2/lib/python/models.py 2011-01-17 09:28:43 UTC (rev 12976)
+++ csw/mgar/gar/v2/lib/python/models.py 2011-01-17 09:29:03 UTC (rev 12977)
@@ -24,20 +24,39 @@
name = sqlobject.UnicodeCol(length=255, unique=True, notNone=True)
type = sqlobject.ForeignKey('CatalogReleaseType', notNone=True)
+ def __unicode__(self):
+ return u"Catalog release: %s" % self.name
+
class OsRelease(sqlobject.SQLObject):
"Short name: SunOS5.9, long name: Solaris 9"
short_name = sqlobject.UnicodeCol(length=40, unique=True, notNone=True)
full_name = sqlobject.UnicodeCol(length=255, unique=True, notNone=True)
+ def __unicode__(self):
+ return u"OS release: %s" % self.full_name
+
class Architecture(sqlobject.SQLObject):
"One of: 'sparc', 'x86'."
name = sqlobject.UnicodeCol(length=40, unique=True, notNone=True)
+ def __unicode__(self):
+ return u"Architecture: %s" % self.name
+
class Maintainer(sqlobject.SQLObject):
"""The maintainer of the package, identified by the e-mail address."""
email = sqlobject.UnicodeCol(length=255, unique=True, notNone=True)
full_name = sqlobject.UnicodeCol(length=255, default=None)
+ def ObfuscatedEmail(self):
+ username, domain = self.email.split("@")
+ username = username[:-3] + "..."
+ return "@".join((username, domain))
+
+ def __unicode__(self):
+ return u"%s <%s>" % (
+ self.full_name or "Maintainer full name unknown",
+ self.ObfuscatedEmail())
+
class Host(sqlobject.SQLObject):
"Hostname, as returned by socket.getfqdn()"
fqdn = sqlobject.UnicodeCol(length=255, unique=True, notNone=True)
@@ -176,7 +195,12 @@
CheckpkgOverride.sqlmeta.table,
CheckpkgOverride.q.srv4_file==self)))
+ def __unicode__(self):
+ return (
+ u"Package: %s-%s, %s"
+ % (self.catalogname, self.version_string, self.arch.name))
+
class CheckpkgErrorTagMixin(object):
def ToGarSyntax(self):
@@ -214,7 +238,10 @@
arch = sqlobject.ForeignKey('Architecture', notNone=True)
catrel = sqlobject.ForeignKey('CatalogRelease', notNone=True)
+ def __unicode__(self):
+ return u"Error: %s %s %s" % (self.pkgname, self.tag_name, self.tag_info)
+
class CheckpkgOverride(sqlobject.SQLObject):
# Overrides don't need to contain catalog parameters.
srv4_file = sqlobject.ForeignKey('Srv4FileStats', notNone=True)
@@ -257,7 +284,15 @@
'arch', 'osrel', 'catrel', 'srv4file',
unique=True)
+ def __unicode__(self):
+ return (
+ u"%s is in catalog %s %s %s"
+ % (self.srv4file,
+ self.arch.name,
+ self.osrel.full_name,
+ self.catrel.name))
+
class Srv4DependsOn(sqlobject.SQLObject):
"""Models dependencies."""
srv4_file = sqlobject.ForeignKey('Srv4FileStats', notNone=True)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list