summaryrefslogtreecommitdiff
path: root/main/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'main/models.py')
-rw-r--r--main/models.py55
1 files changed, 28 insertions, 27 deletions
diff --git a/main/models.py b/main/models.py
index 4370fa24..59dc154b 100644
--- a/main/models.py
+++ b/main/models.py
@@ -5,6 +5,7 @@ from django.contrib.sites.models import Site
from main.utils import cache_function, make_choice
from packages.models import PackageRelation
+from datetime import datetime
from itertools import groupby
import pytz
@@ -88,6 +89,8 @@ class Repo(models.Model):
help_text="Is this repo meant for package staging?")
bugs_project = models.SmallIntegerField(default=1,
help_text="Flyspray project ID for this repository.")
+ bugs_category = models.SmallIntegerField(default=0,
+ help_text="Flyspray category ID for this repository.")
svn_root = models.CharField(max_length=64,
help_text="SVN root (e.g. path) for this repository.")
@@ -103,8 +106,10 @@ class Repo(models.Model):
verbose_name_plural = 'repos'
class Package(models.Model):
- repo = models.ForeignKey(Repo, related_name="packages")
- arch = models.ForeignKey(Arch, related_name="packages")
+ repo = models.ForeignKey(Repo, related_name="packages",
+ on_delete=models.PROTECT)
+ arch = models.ForeignKey(Arch, related_name="packages",
+ on_delete=models.PROTECT)
pkgname = models.CharField(max_length=255, db_index=True)
pkgbase = models.CharField(max_length=255, db_index=True)
pkgver = models.CharField(max_length=255)
@@ -120,15 +125,15 @@ class Package(models.Model):
last_update = models.DateTimeField(null=True, blank=True)
files_last_update = models.DateTimeField(null=True, blank=True)
packager_str = models.CharField(max_length=255)
- packager = models.ForeignKey(User, null=True)
+ packager = models.ForeignKey(User, null=True,
+ on_delete=models.SET_NULL)
flag_date = models.DateTimeField(null=True)
objects = PackageManager()
class Meta:
db_table = 'packages'
ordering = ('pkgname',)
- #get_latest_by = 'last_update'
- #ordering = ('-last_update',)
+ get_latest_by = 'last_update'
def __unicode__(self):
return self.pkgname
@@ -183,9 +188,12 @@ class Package(models.Model):
"""
requiredby = PackageDepend.objects.select_related('pkg',
'pkg__arch', 'pkg__repo').filter(
- pkg__arch__in=self.applicable_arches(),
depname=self.pkgname).order_by(
- 'pkg__pkgname', 'pkg__id')
+ 'pkg__pkgname', 'pkg__arch__name', 'pkg__repo__name')
+ if not self.arch.agnostic:
+ # make sure we match architectures if possible
+ requiredby = requiredby.filter(
+ pkg__arch__in=self.applicable_arches())
# sort out duplicate packages; this happens if something has a double
# versioned dep such as a kernel module
requiredby = [list(vals)[0] for k, vals in
@@ -276,21 +284,6 @@ class Package(models.Model):
return Package.objects.filter(arch__in=self.applicable_arches(),
repo__testing=self.repo.testing, pkgbase=self.pkgbase).exclude(id=self.id)
- def get_svn_link(self, svnpath):
- linkbase = "http://projects.archlinux.org/svntogit/%s.git/tree/%s/%s/"
- return linkbase % (self.repo.svn_root, self.pkgbase, svnpath)
-
- def get_arch_svn_link(self):
- repo = self.repo.name.lower()
- return self.get_svn_link("repos/%s-%s" % (repo, self.arch.name))
-
- def get_trunk_svn_link(self):
- return self.get_svn_link("trunk")
-
- def get_bugs_link(self):
- return "https://bugs.archlinux.org/?project=%d&string=%s" % \
- (self.repo.bugs_project, self.pkgname)
-
def is_same_version(self, other):
'is this package similar, name and version-wise, to another'
return self.pkgname == other.pkgname \
@@ -348,10 +341,10 @@ class PackageDepend(models.Model):
db_table = 'package_depends'
class Todolist(models.Model):
- creator = models.ForeignKey(User)
+ creator = models.ForeignKey(User, on_delete=models.PROTECT)
name = models.CharField(max_length=255)
description = models.TextField()
- date_added = models.DateTimeField(auto_now_add=True, db_index=True)
+ date_added = models.DateTimeField(db_index=True)
objects = TodolistManager()
def __unicode__(self):
@@ -383,10 +376,18 @@ class TodolistPkg(models.Model):
db_table = 'todolist_pkgs'
unique_together = (('list','pkg'),)
+def set_todolist_fields(sender, **kwargs):
+ todolist = kwargs['instance']
+ if not todolist.date_added:
+ todolist.date_added = datetime.utcnow()
+
# connect signals needed to keep cache in line with reality
-from main.utils import refresh_package_latest
-from django.db.models.signals import post_save
-post_save.connect(refresh_package_latest, sender=Package,
+from main.utils import refresh_latest
+from django.db.models.signals import pre_save, post_save
+
+post_save.connect(refresh_latest, sender=Package,
+ dispatch_uid="main.models")
+pre_save.connect(set_todolist_fields, sender=Todolist,
dispatch_uid="main.models")
# vim: set ts=4 sw=4 et: