1 from django
.db
import models
2 from django
.contrib
.auth
.models
import User
5 class PackageManager(models
.Manager
):
6 def get_flag_stats(self
):
9 unflagged
= self
.filter(maintainer
=0).count()
10 flagged
= self
.filter(maintainer
=0).filter(needupdate
=True).count()
11 results
.append((User(id=0,first_name
='Orphans'), unflagged
, flagged
))
13 for maint
in User
.objects
.all().order_by('first_name'):
14 unflagged
= self
.filter(maintainer
=maint
.id).count()
15 flagged
= self
.filter(maintainer
=maint
.id).filter(needupdate
=True).count()
16 results
.append((maint
, unflagged
, flagged
))
19 class Category(models
.Model
):
20 id = models
.AutoField(primary_key
=True)
21 category
= models
.CharField(maxlength
=255)
23 db_table
= 'categories'
24 verbose_name_plural
= 'categories'
26 class Repo(models
.Model
):
27 id = models
.AutoField(primary_key
=True)
28 name
= models
.CharField(maxlength
=255)
31 def last_update(self
):
33 latest
= Package
.objects
.filter(repo__name__exact
=self
.name
).order_by('-last_update')[0]
34 return latest
.last_update
38 class Package(models
.Model
):
39 id = models
.AutoField(primary_key
=True)
40 repo
= models
.ForeignKey(Repo
)
41 maintainer
= models
.ForeignKey(User
)
42 category
= models
.ForeignKey(Category
)
43 needupdate
= models
.BooleanField(default
=False)
44 pkgname
= models
.CharField(maxlength
=255)
45 pkgver
= models
.CharField(maxlength
=255)
46 pkgrel
= models
.CharField(maxlength
=255)
47 pkgdesc
= models
.CharField(maxlength
=255)
48 url
= models
.URLField()
49 sources
= models
.TextField()
50 depends
= models
.TextField()
51 last_update
= models
.DateTimeField(null
=True, blank
=True)
52 objects
= PackageManager()
55 get_latest_by
= 'last_update'
57 def get_absolute_url(self
):
58 return '/packages/%i/' % self
.id
60 def depends_urlize(self
):
62 for dep
in self
.depends
.split(' '):
63 # shave off any version qualifiers
64 nameonly
= re
.match(r
"([a-z0-9-]+)", dep
).group(1)
66 p
= Package
.objects
.filter(pkgname
=nameonly
)[0]
68 # couldn't find a package in the DB -- it might be a virtual depend
69 urls
= urls
+ '<li>' + dep
+ '</li>'
71 url
= '<li><a href="/packages/' + str(p
.id) + '">' + dep
+ '</a></li>'
75 def sources_urlize(self
):
77 for source
in self
.sources
.split(' '):
78 if re
.search('://', source
):
79 url
= '<li><a href="' + source
+ '">' + source
+ '</a></li>'
81 url
= '<li>' + source
+ '</li>'
85 class PackageFile(models
.Model
):
86 id = models
.AutoField(primary_key
=True)
87 pkg
= models
.ForeignKey(Package
)
88 path
= models
.CharField(maxlength
=255)
90 db_table
= 'packages_files'