import re


REGISTRY = {}
hotlink_with_arg = re.compile(r"(\w+.\w+).(\d+):(\w+):(.*)")
hotlink_with_attr = re.compile(r"(\w+.\w+).(\d+):(\w+)")
hotlink_base = re.compile(r"(\w+.\w+).(\d+)")


class RegistrationError(Exception):

    def __init__(self, value):
        self.value = value

    def __str__(self):
        return repr(self.value)


def register(model, attr='get_absolute_url'):
    if not hasattr(model, attr):
        raise RegistrationError('No such function for the model %s: %s' % (
            unicode(model), attr))


    model_name = "%s.%s" % (model._meta.app_label, model._meta.module_name)
    key = "%s.%s" % (model_name, attr)
    REGISTRY[key] = (model, attr)


def reverse_hotlink(hotlink):
    try:
        model_name, pk, attr, arg = hotlink_with_arg.match(hotlink).groups()
    except AttributeError:
        try:
            model_name, pk, attr = hotlink_with_attr.match(hotlink).groups()
            arg = None
        except AttributeError:
            try:
                model_name, pk = hotlink_base.match(hotlink).groups()
                attr = 'get_absolute_url'
                arg = None
            except AttributeError:
                return None

    key = "%s.%s" % (model_name, attr)
    try:
        model, attr = REGISTRY[key]
        try:
            instance = model.objects.get(pk=pk)
            func_or_prop = getattr(instance, attr)
            if arg:
                try:
                    return func_or_prop(int(arg))
                except ValueError:
                    return func_or_prop(arg)
            else:
                if hasattr(func_or_prop, '__call__'):
                    return func_or_prop()
                else:
                    return func_or_prop
        except model.DoesNotExist:
            return None
    except KeyError:
        return None



@@ -381,16 +381,27 @@
 ute_url'
+, prefix=''
 ):%0A    i
@@ -688,16 +688,24 @@
 el, attr
+, prefix
 )%0A%0A%0Adef 
@@ -1274,16 +1274,24 @@
 el, attr
+, prefix
  = REGIS
@@ -1471,32 +1471,49 @@
          return 
+prefix + unicode(
 func_or_prop(int
@@ -1518,16 +1518,17 @@
 nt(arg))
+)
 %0A       
@@ -1574,32 +1574,49 @@
          return 
+prefix + unicode(
 func_or_prop(arg
@@ -1616,16 +1616,17 @@
 rop(arg)
+)
 %0A       
@@ -1709,32 +1709,49 @@
          return 
+prefix + unicode(
 func_or_prop()%0A 
@@ -1748,16 +1748,17 @@
 r_prop()
+)
 %0A       
@@ -1799,16 +1799,33 @@
  return 
+prefix + unicode(
 func_or_
@@ -1828,16 +1828,17 @@
 _or_prop
+)
 %0A       

Add the possibility to add a prefix to urls.