def mobile_template(template):
    """
    Mark a function as mobile-ready and pass a mobile template if MOBILE.

    For example::

        @mobile_template('a/{mobile/}b.html')
        def view(template=None):
            ...


    if ``request.MOBILE=True`` the template will be `a/mobile/b.html`.
    if ``request.MOBILE=False`` the template will be `a/b.html`.

    This function is useful if the mobile view uses the same context but a
    different template.

    """
    def decorator(f):
        @functools.wraps(f)
        def wrapper(*args, **kwargs):
            ctx = stack.top
            if ctx is not None and hasattr(ctx, 'request'):
                request = ctx.request
                is_mobile = getattr(request, 'MOBILE', None)
                kwargs['template'] = re.sub(r'{(.+?)}',
                                            r'\1' if is_mobile else '',
                                            template)
            return f(*args, **kwargs)
        return wrapper
    return decorator
def mobile_template ( template ) : def decorator ( f ) : @ functools . wraps ( f ) def wrapper ( * args , ** kwargs ) : ctx = stack . top if ctx is not None and hasattr ( ctx , 'request' ) : request = ctx . request is_mobile = getattr ( request , 'MOBILE' , None ) kwargs [ 'template' ] = re . sub ( r'{(.+?)}' , r'\1' if is_mobile else '' , template ) return f ( * args , ** kwargs ) return wrapper return decorator
Mark a function as mobile-ready and pass a mobile template if MOBILE.

    For example::

        @mobile_template('a/{mobile/}b.html')
        def view(template=None):
            ...


    if ``request.MOBILE=True`` the template will be `a/mobile/b.html`.
    if ``request.MOBILE=False`` the template will be `a/b.html`.

    This function is useful if the mobile view uses the same context but a
    different template.