Exemple #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)
Exemple #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/")
Exemple #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/")
Exemple #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/")
Exemple #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/")