Beispiel #1
0
def short_url(context, obj, server=None):
    """Construct the absolute, shortened URL for the given ShortenedUrl object or slug.

        {% shorturl short %}

    By default, the protocol and host of the shortened URL are copied from the request.
    To configure a default location for the routing service, either set `CHAPO_SERVER`
    in your Django settings file or pass the `server` argument; (the latter overrides
    the former).

        {% shorturl short server='https://edgefl.ip' %}

    """
    server = server_fallback(context, server)
    return utils.short_url(obj, server)
Beispiel #2
0
 def test_slug(self):
     """short_url returns the shortened URL for a ShortenedUrl slug"""
     out = utils.short_url('ooga-booga')
     self.assertEqual(out, "/r/ooga-booga/")
Beispiel #3
0
 def test_server(self):
     """short_url constructs absolute URLs from the server argument"""
     short = models.ShortenedUrl.objects.create(slug='ooga-booga', url=URL)
     out = utils.short_url(short, server='//app.edgeflip.com')
     self.assertEqual(out, "//app.edgeflip.com/r/ooga-booga/")
Beispiel #4
0
 def test_server_setting(self):
     """short_url constructs absolute URLs from the CHAPO_SERVER setting"""
     short = models.ShortenedUrl.objects.create(slug='ooga-booga', url=URL)
     out = utils.short_url(short)
     self.assertEqual(out, "http://edgefl.ip/r/ooga-booga/")
Beispiel #5
0
 def test_short_url(self):
     """short_url returns the shortened URL of a ShortenedUrl object"""
     short = models.ShortenedUrl.objects.create(slug='ooga-booga', url=URL)
     out = utils.short_url(short)
     self.assertEqual(out, "/r/ooga-booga/")