Exemple #1
0
 def url(self, name):
     request = get_current_request()
     if request and hasattr(request, 'kbsite'):
         site_base = request.kbsite.base_url()
         media_base = urlparse.urljoin(site_base, self.base_url)
         self.base_url = media_base
     return super(KegbotFileSystemStorage, self).url(name)
    def get_base_url(self):
        """Returns the base URL of the site without a trailing slash.

        Result is used primarily in constructing absolute links back to the
        site, eg in notifications.
        """
        static_url = getattr(settings, 'KEGBOT_BASE_URL', None)
        if static_url:
            return static_url.rstrip('/')
        r = get_current_request()
        if not r:
            raise UnknownBaseUrlException('Cannot determine current request')
        return r.build_absolute_uri('/').rstrip('/')
Exemple #3
0
def _getCallingContext():
    """
    Utility function for the RedisLogRecord.

    Returns the module, function, and lineno of the function
    that called the logger.

    We look way up in the stack.  The stack at this point is:
    [0] logger.py _getCallingContext (hey, that's me!)
    [1] logger.py __init__
    [2] logger.py makeRecord
    [3] _log
    [4] <logging method>
    [5] caller of logging method
    """
    frames = inspect.stack()

    if len(frames) > 4:
        context = frames[5]
    else:
        context = frames[0]

    modname = context[1]
    lineno = context[2]

    if context[3]:
        funcname = context[3]
    else:
        funcname = ""

    request = get_current_request()

    # python docs say you don't want references to
    # frames lying around.  Bad things can happen.
    del context
    del frames

    return modname, funcname, lineno, request
Exemple #4
0
def _getCallingContext():
    """
    Utility function for the RedisLogRecord.

    Returns the module, function, and lineno of the function
    that called the logger.

    We look way up in the stack.  The stack at this point is:
    [0] logger.py _getCallingContext (hey, that's me!)
    [1] logger.py __init__
    [2] logger.py makeRecord
    [3] _log
    [4] <logging method>
    [5] caller of logging method
    """
    frames = inspect.stack()

    if len(frames) > 4:
        context = frames[5]
    else:
        context = frames[0]

    modname = context[1]
    lineno = context[2]

    if context[3]:
        funcname = context[3]
    else:
        funcname = ""

    request = get_current_request()

    # python docs say you don't want references to
    # frames lying around.  Bad things can happen.
    del context
    del frames

    return modname, funcname, lineno, request