(f)
return _safe_download
Makes a download safe, by trapping any app errors and redirecting
    to a default landing page.
    Assumes that the first 2 arguments to the function after request are
    domain and app_id, or there are keyword arguments with those names
Makes a download safe, by trapping any app errors and redirecting
    to a default landing page.
    Assumes that the first 2 arguments to the function after request are
    domain and app_id, or there are keyword arguments with those names
Makes a download safe by trapping any app errors and redirecting to a default landing page . Assumes that the first 2 arguments to the function after request are domain and app_id or there are keyword arguments with those names
def safe_download(f):
    """
    Makes a download safe, by trapping any app errors and redirecting
    to a default landing page.
    Assumes that the first 2 arguments to the function after request are
    domain and app_id, or there are keyword arguments with those names
    """
    @wraps(f)
    def _safe_download(request, *args, **kwargs):
        domain = args[0] if len(args) > 0 else kwargs["domain"]
        app_id = args[1] if len(args) > 1 else kwargs["app_id"]
        latest = True if request.GET.get('latest') == 'true' else False
        target = request.GET.get('target') or None

        try:
            request.app = get_app(domain, app_id, latest=latest, target=target)
            if not request.app.doc_type.endswith(DELETED_SUFFIX):
                return f(request, *args, **kwargs)
            else:
                message = 'User attempted to install deleted application: {}'.format(app_id)
        except (AppEditingError, CaseError, ValueError) as e:
            message = e
        logging.exception(message)
        messages.error(request, "Problem downloading file: %s" % message)
        return HttpResponseRedirect(reverse("view_app", args=[domain, app_id]))

    return _safe_download
def safe_download ( f ) : @ wraps ( f ) def _safe_download ( request , * args , * * kwargs ) : domain = args [ 0 ] if len ( args ) > 0 else kwargs [ "domain" ] app_id = args [ 1 ] if len ( args ) > 1 else kwargs [ "app_id" ] latest = True if request . GET . get ( 'latest' ) == 'true' else False target = request . GET . get ( 'target' ) or None try : request . app = get_app ( domain , app_id , latest = latest , target = target ) if not request . app . doc_type . endswith ( DELETED_SUFFIX ) : return f ( request , * args , * * kwargs ) else : message = 'User attempted to install deleted application: {}' . format ( app_id ) except ( AppEditingError , CaseError , ValueError ) as e : message = e logging . exception ( message ) messages . error ( request , "Problem downloading file: %s" % message ) return HttpResponseRedirect ( reverse ( "view_app" , args = [ domain , app_id ] ) ) return _safe_download