コード例 #1
0
ファイル: views.py プロジェクト: Ximpia/ximpia
def execActionMsg(request, appSlug, actionSlug, actionAttrs, **args):
    """
    Executes an action and shows a message of result of action.
    """
    logger.debug("execActionMsg :: appslug: %s actionslug: %s actionAttrs: %s" % (appSlug, actionSlug, actionAttrs))
    dbApplication = ApplicationDAO(args["ctx"])
    application = dbApplication.get(slug=appSlug)
    db = ActionDAO(args["ctx"])
    action = db.get(application=application, slug=actionSlug)
    impl = action.implementation
    implFields = impl.split(".")
    method = implFields[len(implFields) - 1]
    classPath = ".".join(implFields[:-1])
    args["ctx"].path = "/apps/" + application.slug + "/" + action.slug
    if actionAttrs.find("/") != -1:
        actionAttrTuple = actionAttrs.split("/")
    else:
        if len(actionAttrs) == 0:
            actionAttrTuple = []
        else:
            actionAttrTuple = [actionAttrs]
    # Instance and call method for view, get result
    if method.find("_") == -1 or method.find("__") == -1:
        cls = get_class(classPath)
        obj = cls(args["ctx"])
        super(cls, obj).__init__(args["ctx"])
        obj.request = request
        if len(actionAttrTuple) == 0:
            result = eval("obj." + method)()
        else:
            result = eval("obj." + method)(*actionAttrTuple)
    else:
        logger.debug("xpcore :: execAction :: private methods...")
        raise Http404
    return result
コード例 #2
0
ファイル: views.py プロジェクト: Ximpia/ximpia
def jxService(request, **args):
    """Excutes the business class: bsClass, method {bsClass: '', method: ''}
    @param request: Request
    @param result: Result"""
    logger.debug("jxService...")
    # raw_input('Continue???')
    # time.sleep(1.5)
    logger.debug(json.dumps(request.REQUEST.items()))
    request.session.set_test_cookie()
    request.session.delete_test_cookie()
    # logger.debug( 'session: %s' % (json.dumps(request.session.items())) )
    # logger.debug( 'session: %s' % json.dumps(request.session.items()) + ' ' + json.dumps(request.session.session_key) )
    if (request.REQUEST.has_key("view") or request.REQUEST.has_key("action")) and request.is_ajax() is True:
        viewAttrs = {}
        dbApplication = ApplicationDAO(args["ctx"])
        app = request.REQUEST["app"]
        application = dbApplication.get(name=app)
        if request.REQUEST.has_key("view"):
            view = request.REQUEST["view"]
            logger.debug("view: %s" % (view))
            dbView = ViewDAO(args["ctx"])
            viewObj = dbView.get(application__name=app, name=view)
            args["ctx"].viewAuth = viewObj.hasAuth
            impl = viewObj.implementation
            # view attributes
            viewAttrs = json.loads(request.REQUEST["params"]) if "params" in request.REQUEST else {}
            args["ctx"].viewNameSource = view
            args["ctx"].path = "/apps/" + application.slug + "/" + viewObj.slug
        elif request.REQUEST.has_key("action"):
            action = request.REQUEST["action"]
            logger.debug("action: %s" % (action))
            dbAction = ActionDAO(args["ctx"])
            dbView = ViewDAO(args["ctx"])
            actionObj = dbAction.get(application__name=app, name=action)
            # if args['ctx'].has_key('viewNameSource') and len(args['ctx']['viewNameSource']) != 0:
            if len(args["ctx"].viewNameSource) != 0:
                # Get view name and check its application code with application code of action
                logger.debug("viewNameSource: %s" % (args["ctx"].viewNameSource))
                viewObj = dbView.get(application__name=app, name=args["ctx"].viewNameSource)
                if actionObj.application.name != viewObj.application.name:
                    raise XpMsgException(None, _("Action is not in same application as view source"))
            impl = actionObj.implementation
            args["ctx"].path = "/apps/" + application.slug + "/do/" + actionObj.slug
        implFields = impl.split(".")
        method = implFields[len(implFields) - 1]
        classPath = ".".join(implFields[:-1])
        logger.debug("classPath: %s" % (classPath))
        if method.find("_") == -1 or method.find("__") == -1:
            cls = get_class(classPath)
            obj = cls(args["ctx"])
            super(cls, obj).__init__(args["ctx"])
            obj.request = request
            if len(viewAttrs) == 0:
                result = getattr(obj, method)()
            else:
                result = getattr(obj, method)(**viewAttrs)
        else:
            logger.debug("private methods...")
            raise Http404
    else:
        logger.debug("Unvalid business request")
        raise Http404
    return result