Ticket #10944: site_url.diff
File site_url.diff, 2.1 KB (added by , 14 years ago) |
---|
-
django/contrib/sites/tests.py
3 3 from django.core.exceptions import ObjectDoesNotExist 4 4 from django.http import HttpRequest 5 5 from django.test import TestCase 6 from django.template import Template, Context 6 7 7 8 8 9 class SitesFrameworkTests(TestCase): … … 54 55 site = get_current_site(request) 55 56 self.assert_(isinstance(site, RequestSite)) 56 57 self.assertEqual(site.name, u"example.com") 58 59 def test_get_url(self): 60 # Test absolute URLs builder using relative path 61 site = Site.objects.get_current() 62 self.assertEqual(u"example.com/test", site.get_url("/test")) 63 64 def test_get_site_url_tag(self): 65 out = Template( 66 "{% load sites %}" 67 "{% site_url '/test' %}" 68 ).render(Context()) 69 self.assertEquals(out, "example.com/test") 70 -
django/contrib/sites/models.py
61 61 except KeyError: 62 62 pass 63 63 64 def get_url(self, path): 65 """Returns absolute URLs based on a given relative path""" 66 return self.domain + path 64 67 65 68 class RequestSite(object): 66 69 """ -
django/contrib/sites/templatetags/sites.py
1 from django import template 2 from django.contrib.sites.models import Site 3 from django.conf import settings 4 5 register = template.Library() 6 7 def site_url(path): 8 site = Site.objects.get_current() 9 return site.get_url(path) 10 11 register.simple_tag(site_url)