summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authoreliott <eliott@cactuswax.net>2007-12-29 16:42:55 -0800
committereliott <eliott@cactuswax.net>2007-12-29 16:42:55 -0800
commit3e297efad8e6dbb7622cedd68a2457f00dd09080 (patch)
tree1d66d932fa8e90bfa2c71f92d77a24b823831540 /packages
parentff6d99b054efddb0725b0ddcbc81c58f7c8ce375 (diff)
Massive retab fest.
Also added vim command comment to the end of files.
Diffstat (limited to 'packages')
-rw-r--r--packages/models.py150
-rw-r--r--packages/templatetags/package_extras.py37
-rw-r--r--packages/views.py3
3 files changed, 99 insertions, 91 deletions
diff --git a/packages/models.py b/packages/models.py
index d9de3b14..bce638df 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -3,90 +3,92 @@ from django.contrib.auth.models import User
import re
class PackageManager(models.Manager):
- def get_flag_stats(self):
- results = []
- # first the orphans
- unflagged = self.filter(maintainer=0).count()
- flagged = self.filter(maintainer=0).filter(needupdate=True).count()
- results.append((User(id=0,first_name='Orphans'), unflagged, flagged))
- # now the rest
- for maint in User.objects.all().order_by('first_name'):
- unflagged = self.filter(maintainer=maint.id).count()
- flagged = self.filter(maintainer=maint.id).filter(needupdate=True).count()
- results.append((maint, unflagged, flagged))
- return results
+ def get_flag_stats(self):
+ results = []
+ # first the orphans
+ unflagged = self.filter(maintainer=0).count()
+ flagged = self.filter(maintainer=0).filter(needupdate=True).count()
+ results.append((User(id=0,first_name='Orphans'), unflagged, flagged))
+ # now the rest
+ for maint in User.objects.all().order_by('first_name'):
+ unflagged = self.filter(maintainer=maint.id).count()
+ flagged = self.filter(maintainer=maint.id).filter(needupdate=True).count()
+ results.append((maint, unflagged, flagged))
+ return results
class Category(models.Model):
- id = models.AutoField(primary_key=True)
- category = models.CharField(maxlength=255)
- class Meta:
- db_table = 'categories'
- verbose_name_plural = 'categories'
+ id = models.AutoField(primary_key=True)
+ category = models.CharField(maxlength=255)
+ class Meta:
+ db_table = 'categories'
+ verbose_name_plural = 'categories'
class Repo(models.Model):
- id = models.AutoField(primary_key=True)
- name = models.CharField(maxlength=255)
- class Meta:
- db_table = 'repos'
+ id = models.AutoField(primary_key=True)
+ name = models.CharField(maxlength=255)
+ class Meta:
+ db_table = 'repos'
ordering = ['name']
- def last_update(self):
- try:
- latest = Package.objects.filter(repo__name__exact=self.name).order_by('-last_update')[0]
- return latest.last_update
- except IndexError:
- return "N/A"
+ def last_update(self):
+ try:
+ latest = Package.objects.filter(repo__name__exact=self.name).order_by('-last_update')[0]
+ return latest.last_update
+ except IndexError:
+ return "N/A"
class Package(models.Model):
- id = models.AutoField(primary_key=True)
- repo = models.ForeignKey(Repo)
- maintainer = models.ForeignKey(User)
- category = models.ForeignKey(Category)
- needupdate = models.BooleanField(default=False)
- pkgname = models.CharField(maxlength=255)
- pkgver = models.CharField(maxlength=255)
- pkgrel = models.CharField(maxlength=255)
- pkgdesc = models.CharField(maxlength=255)
- url = models.URLField()
- sources = models.TextField()
- depends = models.TextField()
- last_update = models.DateTimeField(null=True, blank=True)
- objects = PackageManager()
- class Meta:
- db_table = 'packages'
- get_latest_by = 'last_update'
+ id = models.AutoField(primary_key=True)
+ repo = models.ForeignKey(Repo)
+ maintainer = models.ForeignKey(User)
+ category = models.ForeignKey(Category)
+ needupdate = models.BooleanField(default=False)
+ pkgname = models.CharField(maxlength=255)
+ pkgver = models.CharField(maxlength=255)
+ pkgrel = models.CharField(maxlength=255)
+ pkgdesc = models.CharField(maxlength=255)
+ url = models.URLField()
+ sources = models.TextField()
+ depends = models.TextField()
+ last_update = models.DateTimeField(null=True, blank=True)
+ objects = PackageManager()
+ class Meta:
+ db_table = 'packages'
+ get_latest_by = 'last_update'
- def get_absolute_url(self):
- return '/packages/%i/' % self.id
+ def get_absolute_url(self):
+ return '/packages/%i/' % self.id
- def depends_urlize(self):
- urls = ''
- for dep in self.depends.split(' '):
- # shave off any version qualifiers
- nameonly = re.match(r"([a-z0-9-]+)", dep).group(1)
- try:
- p = Package.objects.filter(pkgname=nameonly)[0]
- except IndexError:
- # couldn't find a package in the DB -- it might be a virtual depend
- urls = urls + '<li>' + dep + '</li>'
- continue
- url = '<li><a href="/packages/' + str(p.id) + '">' + dep + '</a></li>'
- urls = urls + url
- return urls
+ def depends_urlize(self):
+ urls = ''
+ for dep in self.depends.split(' '):
+ # shave off any version qualifiers
+ nameonly = re.match(r"([a-z0-9-]+)", dep).group(1)
+ try:
+ p = Package.objects.filter(pkgname=nameonly)[0]
+ except IndexError:
+ # couldn't find a package in the DB -- it might be a virtual depend
+ urls = urls + '<li>' + dep + '</li>'
+ continue
+ url = '<li><a href="/packages/' + str(p.id) + '">' + dep + '</a></li>'
+ urls = urls + url
+ return urls
- def sources_urlize(self):
- urls = ''
- for source in self.sources.split(' '):
- if re.search('://', source):
- url = '<li><a href="' + source + '">' + source + '</a></li>'
- else:
- url = '<li>' + source + '</li>'
- urls = urls + url
- return urls
+ def sources_urlize(self):
+ urls = ''
+ for source in self.sources.split(' '):
+ if re.search('://', source):
+ url = '<li><a href="' + source + '">' + source + '</a></li>'
+ else:
+ url = '<li>' + source + '</li>'
+ urls = urls + url
+ return urls
class PackageFile(models.Model):
- id = models.AutoField(primary_key=True)
- pkg = models.ForeignKey(Package)
- path = models.CharField(maxlength=255)
- class Meta:
- db_table = 'packages_files'
+ id = models.AutoField(primary_key=True)
+ pkg = models.ForeignKey(Package)
+ path = models.CharField(maxlength=255)
+ class Meta:
+ db_table = 'packages_files'
+
+# vim: set ts=4 sw=4 et:
diff --git a/packages/templatetags/package_extras.py b/packages/templatetags/package_extras.py
index 8b55221b..9f165580 100644
--- a/packages/templatetags/package_extras.py
+++ b/packages/templatetags/package_extras.py
@@ -3,26 +3,29 @@ from django import template
register = template.Library()
class BuildQueryStringNode(template.Node):
- def __init__(self, sortfield):
- self.sortfield = sortfield
- def render(self, context):
- qs = context['querystring'].copy()
- if qs.has_key('sort') and qs['sort'] == self.sortfield:
- qs['sort'] = '-' + self.sortfield
- else:
- qs['sort'] = self.sortfield
- return '?' + qs.urlencode()
+ def __init__(self, sortfield):
+ self.sortfield = sortfield
+ def render(self, context):
+ qs = context['querystring'].copy()
+ if qs.has_key('sort') and qs['sort'] == self.sortfield:
+ qs['sort'] = '-' + self.sortfield
+ else:
+ qs['sort'] = self.sortfield
+ return '?' + qs.urlencode()
@register.tag(name='buildsortqs')
def do_buildsortqs(parser, token):
- try:
- tagname, sortfield = token.split_contents()
- except ValueError:
- raise template.TemplateSyntaxError, "%r tag requires a single argument" % tagname
- if not (sortfield[0] == sortfield[-1] and sortfield[0] in ('"', "'")):
- raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tagname
- return BuildQueryStringNode(sortfield[1:-1])
+ try:
+ tagname, sortfield = token.split_contents()
+ except ValueError:
+ raise template.TemplateSyntaxError, "%r tag requires a single argument" % tagname
+ if not (sortfield[0] == sortfield[-1] and sortfield[0] in ('"', "'")):
+ raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tagname
+ return BuildQueryStringNode(sortfield[1:-1])
@register.filter(name='space2br')
def space2br(value):
- return value.replace(' ', '<br />')
+ return value.replace(' ', '<br />')
+
+# vim: set ts=4 sw=4 et:
+
diff --git a/packages/views.py b/packages/views.py
index aaf4deed..ddb2adb6 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -170,3 +170,6 @@ def unflag(request, pkgid):
pkg.needupdate = 0
pkg.save()
return HttpResponseRedirect('/packages/%d/' % (pkg.id))
+
+# vim: set ts=4 sw=4 et:
+