From 8bf0bfeac7f1cdfee19432b3eb77c48f4fedef08 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 24 May 2010 21:07:09 -0500 Subject: Use Sites framework instead of hardcoded domain name Instead of putting 'www.archlinux.org' all over the place, use the Django sites framework to pull the site name out of the database. Now these amazing things will work if you are running locally and decide to change the site! Signed-off-by: Dan McGee --- main/models.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'main') diff --git a/main/models.py b/main/models.py index 7ccb924..e106313 100644 --- a/main/models.py +++ b/main/models.py @@ -1,6 +1,7 @@ from django.db import models from django.db.models import Q from django.contrib.auth.models import User +from django.contrib.sites.models import Site from main.middleware import get_user from packages.models import PackageRelation @@ -176,6 +177,7 @@ class Package(models.Model): last_update = models.DateTimeField(null=True, blank=True) files_last_update = models.DateTimeField(null=True, blank=True) license = models.CharField(max_length=255, null=True) + objects = PackageManager() class Meta: db_table = 'packages' @@ -190,6 +192,11 @@ class Package(models.Model): return '/packages/%s/%s/%s/' % (self.repo.name.lower(), self.arch.name, self.pkgname) + def get_full_url(self, proto='http'): + '''get a URL suitable for things like email including the domain''' + domain = Site.objects.get_current().domain + return '%s://%s%s' % (proto, domain, self.get_absolute_url()) + @property def maintainers(self): return User.objects.filter( -- cgit v1.2.3-24-g4f1b