コード例 #1
0
        private string Generate()
        {
            var m = new PythonScriptModel(CurrentDatabase);

            m.PrepareHttpPost();
            m.pythonModel.DictionaryAdd("HTMLContent", HTMLContent.Body);
            if (SQLContent != null)
            {
                m.pythonModel.DictionaryAdd("SQLContent", SQLContent.Body);
            }
            m.pythonModel.DictionaryAdd("CurrentUser", CurrentDatabase.CurrentUser);
            m.pythonModel.DictionaryAdd("CurrentPerson", CurrentDatabase.CurrentUserPerson);
            m.pythonModel.DictionaryAdd("WidgetId", "widget_" + Id);
            m.pythonModel.DictionaryAdd("WidgetName", Name);
            if (PythonContent == null)
            {
                return(m.RunPythonScript("print model.RenderTemplate(Data.HTMLContent)"));
            }
            return(m.RunPythonScript(PythonContent.Body));
        }
コード例 #2
0
        public object PythonAPI(string name)
        {
            var model  = new PythonScriptModel(CurrentDatabase);
            var script = model.FetchScript(name);

            if (!CanRunScript(script))
            {
                throw new Exception("Not Authorized to run this script");
            }
            model.PrepareHttpPost();
            var query = Request.RequestUri.ParseQueryString();

            foreach (var key in query.AllKeys)
            {
                model.pythonModel.DictionaryAdd(key, query.Get(key));
            }

            var ret = model.RunPythonScript(script);

            return(new { output = ret, data = model.pythonModel.Data });
        }
コード例 #3
0
        public ActionResult PyScriptForm(string name = null)
        {
            try
            {
                var model  = new PythonScriptModel(CurrentDatabase);
                var script = model.FetchScript(Request.Form["pyscript"] ?? name);
                model.PrepareHttpPost();

                var ret = model.RunPythonScript(script);
                if (ret.StartsWith("REDIRECT="))
                {
                    return(Redirect(ret.Substring(9).Trim()));
                }
                if (model.pythonModel.Output.HasValue() && !model.pythonModel.Form.HasValue())
                {
                    return(View("PyScript", model.pythonModel));
                }
                return(Content(ret));
            }
            catch (Exception ex)
            {
                return(Content($@"<div class='alert alert-danger' style='font-family: monospace; white-space: pre;'>{ex.Message}</div></div>"));
            }
        }