def api(request): user = request.user post_data = json.loads(request.body) if not post_data.has_key("path"): raise Exception("Api post without using path") path = post_data["path"] view = post_data["view"] if post_data["path"].split("/").__len__() != 2: raise Exception("'{0}' is invalid path, path must be */*") view_privileges = quicky.get_settings( ).AUTHORIZATION_ENGINE.get_view_of_user(view_id=view, user_id=user.id) if user.is_superuser: view_privileges = {"is_public": True} if view_privileges == None and not login_info.user.isSysAdmin: return HttpResponse('401 Unauthorized', status=401) module_path = path.split("/")[0] method_path = path.split('/')[1] mdl = None try: mdl = importlib.import_module("hrm.bll." + module_path) except Exception as ex: logger.debug(ex) raise Exception("import '{0}' encountered '{1}'".format( module_path, ex.message)) ret = None if mdl != None: if not hasattr(mdl, method_path): raise (Exception("'{0}' was not found in '{1}'".format( method_path, "hrm.bll." + module_path))) try: if post_data.has_key("data"): ret = getattr(mdl, method_path)({ "privileges": view_privileges, "data": post_data.get("data", {}), "user": user, "view": view }) else: ret = getattr(mdl, method_path)({ "privileges": view_privileges, "user": user, "view": view }) except Exception as ex: raise Exception("Call '{0}' in '{1}' encountered '{2}'".format( method_path, module_path, ex)) ret_data = quicky.serilize.to_json(ret) return HttpResponse(ret_data)
def api(request): user=request.user post_data=json.loads(request.body) if not post_data.has_key("path"): raise Exception("Api post without using path") path=post_data["path"] view=post_data["view"] if post_data["path"].split("/").__len__()!=2: raise Exception("'{0}' is invalid path, path must be */*") view_privileges=quicky.get_settings().AUTHORIZATION_ENGINE.get_view_of_user( view_id=view, user_id=user.id ) if user.is_superuser: view_privileges={"is_public":True} if view_privileges==None and not login_info.user.isSysAdmin: return HttpResponse('401 Unauthorized', status=401) module_path=path.split("/")[0] method_path=path.split('/')[1] mdl=None try: mdl = importlib.import_module("hrm.bll."+module_path) except Exception as ex: logger.debug(ex) raise Exception("import '{0}' encountered '{1}'".format(module_path,ex.message)) ret=None if mdl!=None: if not hasattr(mdl,method_path): raise (Exception("'{0}' was not found in '{1}'".format(method_path,"hrm.bll."+module_path))) try: if post_data.has_key("data"): ret=getattr(mdl,method_path)( { "privileges":view_privileges, "data":post_data.get("data",{}), "user":user, "view":view }) else: ret = getattr(mdl, method_path)( { "privileges":view_privileges, "user":user, "view":view }) except Exception as ex: raise Exception("Call '{0}' in '{1}' encountered '{2}'".format(method_path, module_path, ex)) ret_data=quicky.serilize.to_json(ret) return HttpResponse(ret_data)
def get_app_res(key): language=django.utils.translation.get_language() return quicky.get_settings().LANGUAGE_ENGINE.get_language_item(language,app.name,"-",key,key)