From 9b7b5122544283fc32d81d785e94c5f4aacc0109 Mon Sep 17 00:00:00 2001 From: eliott Date: Sat, 8 Mar 2008 00:13:41 -0800 Subject: Moved models around --- packages/models.py | 94 ------------------------------------------------------ packages/views.py | 4 +-- 2 files changed, 2 insertions(+), 96 deletions(-) delete mode 100644 packages/models.py (limited to 'packages') diff --git a/packages/models.py b/packages/models.py deleted file mode 100644 index bce638d..0000000 --- a/packages/models.py +++ /dev/null @@ -1,94 +0,0 @@ -from django.db import models -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 - -class Category(models.Model): - 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' - 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" - -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' - - 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 + '
  • ' + dep + '
  • ' - continue - url = '
  • ' + dep + '
  • ' - urls = urls + url - return urls - - def sources_urlize(self): - urls = '' - for source in self.sources.split(' '): - if re.search('://', source): - url = '
  • ' + source + '
  • ' - else: - url = '
  • ' + source + '
  • ' - 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' - -# vim: set ts=4 sw=4 et: - diff --git a/packages/views.py b/packages/views.py index 2b8f8b2..25bb342 100644 --- a/packages/views.py +++ b/packages/views.py @@ -5,9 +5,9 @@ from django.template import Context, loader from django.core import validators from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User -from archweb_dev.lib.utils import validate, render_response from datetime import datetime -from archweb_dev.packages.models import Package, PackageFile, Repo, Category +from archweb_dev.main.utils import validate, render_response +from archweb_dev.main.models import Package, PackageFile, Repo, Category from django.core.exceptions import ObjectDoesNotExist -- cgit v1.2.3-24-g4f1b