예제 #1
0
    def index(path):

        js_bundle_path = os.path.join(
            app.config["STATIC_DIR"], "js", "dist", "main.bundle.js"
        )
        css_bundle_path = os.path.join(
            app.config["STATIC_DIR"], "css", "dist", "main.css"
        )

        front_end_config = [
            "FLASK_ENV",
            "TELEMETRY_DISABLED",
            "ENVIRONMENT_DEFAULTS",
            "ORCHEST_WEB_URLS",
        ]

        front_end_config_internal = [
            "ORCHEST_SOCKETIO_ENV_BUILDING_NAMESPACE",
            "ORCHEST_SOCKETIO_JUPYTER_BUILDING_NAMESPACE",
            "PIPELINE_PARAMETERS_RESERVED_KEY",
        ]

        return render_template(
            "index.html",
            javascript_bundle_hash=get_hash(js_bundle_path),
            css_bundle_hash=get_hash(css_bundle_path),
            user_config=flask_json.htmlsafe_dumps(get_user_conf()),
            config_json=flask_json.htmlsafe_dumps(
                {
                    **{key: app.config[key] for key in front_end_config},
                    **{key: getattr(_config, key) for key in front_end_config_internal},
                }
            ),
        )
def main():
    html_tag_regex = '<[a-zA-Z]+.*>'
    contributions = (Contribution.query
                     .filter(Contribution.description.op('~')(html_tag_regex))
                     .options(load_only('id', 'description'))
                     .all())
    subcontributions = (SubContribution.query
                        .filter(SubContribution.description.op('~')(html_tag_regex))
                        .options(load_only('id', 'description'))
                        .all())
    categories = (Category.query
                  .filter(Category.description.op('~')(html_tag_regex))
                  .options(load_only('id', 'description'))
                  .all())

    def as_dict(objs):
        return {x.id: x.description for x in objs}

    def format_table(model):
        return model.__table__.fullname

    object_descriptions = {
        format_table(Contribution): as_dict(contributions),
        format_table(SubContribution): as_dict(subcontributions),
        format_table(Category): as_dict(categories)
    }

    env = Environment(loader=FileSystemLoader(os.path.dirname(__file__)))

    template = env.get_template('fix_descriptions_template.html')
    print(template.render(object_descriptions=htmlsafe_dumps(object_descriptions)))
def main():
    html_tag_regex = '<[a-zA-Z]+.*>'
    contributions = (Contribution.query.filter(
        Contribution.description.op('~')(html_tag_regex)).options(
            load_only('id', 'description')).all())
    subcontributions = (SubContribution.query.filter(
        SubContribution.description.op('~')(html_tag_regex)).options(
            load_only('id', 'description')).all())
    categories = (Category.query.filter(
        Category.description.op('~')(html_tag_regex)).options(
            load_only('id', 'description')).all())

    def as_dict(objs):
        return {x.id: x.description for x in objs}

    def format_table(model):
        return model.__table__.fullname

    object_descriptions = {
        format_table(Contribution): as_dict(contributions),
        format_table(SubContribution): as_dict(subcontributions),
        format_table(Category): as_dict(categories)
    }

    env = Environment(loader=FileSystemLoader(os.path.dirname(__file__)))

    template = env.get_template('fix_descriptions_template.html')
    print template.render(
        object_descriptions=htmlsafe_dumps(object_descriptions))
예제 #4
0
 def process_formdata(self, valuelist):
     if valuelist:    
         self.data = valuelist[0]
         try:
             data = yaml.safe_load(self.data)
             json_string = json.htmlsafe_dumps(data, indent='  ')
         except yaml.YAMLError as e: #to do: json error here
             self.json_string = None
             raise ValidationError(str(e))
         else:
             self.json_string = json_string
     else:
         self.data = None
         self.json_string = None
예제 #5
0
 def get(self, access_hash):
     """
     Get a representaion of the group
     """
     if access_hash in groups:
         ret_format = request.args.get("format", "html")
         if ret_format == "html":
             error = request.args.get("error", None)
             success = request.args.get("success", None)
             q = quiz.get_active_question()
             return make_response(
                 render_template(
                     "group.html",
                     group=groups[access_hash],
                     question=q[0] if len(q) > 0 else None,
                     error=error,
                     success=success,
                     get_new_data_url=api.url_for(
                         Group, access_hash=access_hash, format="json"
                     ),
                 ),
                 200,
             )
         elif ret_format == "json":
             q = quiz.get_active_question()
             question_to_send = deepcopy(q[0].__dict__ if len(q) > 0 else None)
             current_answer = None
             if question_to_send is not None:
                 del question_to_send["correct"]
                 del question_to_send["status"]
                 if q[0].access_hash in groups[access_hash].answers:
                     current_answer = groups[access_hash].answers[q[0].access_hash]
             return jsonify(
                 **json.loads(
                     json.htmlsafe_dumps(
                         {
                             "question": question_to_send,
                             "group_name": groups[access_hash].name,
                             "answer": current_answer
                             if len(q) > 0
                             else None,
                         }
                     )
                 )
             )
     return make_response("Invalid access hash", 403)
예제 #6
0
파일: views.py 프로젝트: dingens/zwl
def js_variables():
    vars = {
        'SCRIPT_ROOT': request.script_root,
        'DEFAULT_VIEWCONFIG': 'gt/ring-xwf,.01,.99',
        'ALL_LINECONFIGS': {l.id: l.name
                            for l in lineconfigs.values()},
        'REFRESH_INTERVAL':
        app.config['REFRESH_INTERVAL'] * 1000,  # milliseconds
        'EPOCH': time2js(time(4, 0, 0)),
    }

    for v in ('TIMETABLE_URL_TEMPLATE', ):
        vars[v] = app.config[v]

    return Response(('%s = %s;\n' % (k, json.htmlsafe_dumps(v))
                     for (k, v) in vars.items()),
                    mimetype='text/javascript')
예제 #7
0
 def to_json(self):
     return json.htmlsafe_dumps(self.columnitems)
예제 #8
0
def _to_json(obj):
    obj['permalink'] = '/{}/json'.format(obj.get('permalink'))
    return jsonify(**json.loads(json.htmlsafe_dumps(obj)))
예제 #9
0
def json_unicode(obj):
    return json.htmlsafe_dumps(obj).decode('unicode-escape')
예제 #10
0
 def to_json(self):
     return json.htmlsafe_dumps(self.columnitems)
예제 #11
0
def get_all():
    return json.htmlsafe_dumps(get_all_todo())
예제 #12
0
def get_todo():
    id = request.args['id']
    return json.htmlsafe_dumps(get_todo_by_id_controler({"_id": int(id)}))
예제 #13
0
def server():
    query = request.args

    t = {}
    if 'action' in query:
        action = query['action']
        if 'dblist' == action:
            # return list of databases the user can see

            t["database"] = []
            t["database"].append({
                "name":
                "mit-bit",
                "desc":
                "static database with only one static file as record"
            })
            t["success"] = True
        else:
            if 'record' in query:
                record = query["record"]
            if 'db' in query:
                db = query["db"]
                if 'alist' == action:
                    # return list of annotators

                    t["annotator"] = []
                    t["annotator"].append({
                        "name":
                        "atr",
                        "desc":
                        "reference beat, rhythm, and signal quality annotations"
                    })
                    t["success"] = True
                elif 'rlist' == action:
                    # return list of records for db

                    t["record"] = []
                    t["record"].append("207")
                    t["success"] = True
                elif 'fetch' == action and len(record) > 0:
                    if 'dt' in query:
                        dt = int(query["dt"])
                    fetch = {}
                    if 'annotator' in query:
                        annotator = query["annotator"]
                        fetch["annotator"] = []
                        ta = {"name": annotator}
                        ta["annotation"] = []
                        # loop through beat info appending to annotation
                        for time, symbolAnnotation in lightwave_io.Annotations(
                                record, db):
                            # for time, symbolAnnotation in zip(x,y):
                            ta["annotation"].append({
                                "t":
                                time,
                                "a":
                                lightwave_io.symbolLetter(symbolAnnotation),
                                "s":
                                0,
                                "c":
                                0,
                                "n":
                                0,
                                "x":
                                None
                            })
                        ta["description"] = ""  # get description from somewhere?
                        fetch["annotator"].append(ta)
                    elif 'signal' in query:
                        if 't0' in query:
                            t0 = int(float(query["t0"]))
                        else:
                            t0 = 0
                        tfreq = int(lightwave_io.RecordFreq(record, db)[0])
                        t0 = t0 * tfreq
                        tf = dt * tfreq + t0
                        print(type(t0), type(tf))
                        samp = lightwave_io.RecordSample(record, db)[t0:tf]
                        samp.insert(0, 0)
                        signal = {}
                        signal["name"] = "Unspecified"
                        signal["units"] = "mV"
                        signal["t0"] = t0
                        signal["tf"] = tf
                        signal["gain"] = 1
                        signal["base"] = 1024
                        signal["tps"] = 1
                        signal["scale"] = 1
                        signal["samp"] = [
                            samp[x] - samp[x - 1] for x in range(1, len(samp))
                        ]
                        fetch["signal"] = [signal]
                    else:
                        t["success"] = False
                    if 'success' not in t:
                        t["fetch"] = fetch
                        t["success"] = True
                else:
                    info = {
                        "db": db,
                        "record": record,
                        "start": None,
                        "end": None
                    }
                    info["db"] = db
                    info["record"] = record
                    tfreq, duration = lightwave_io.RecordInfo(record, db)
                    info["tfreq"] = tfreq[0]
                    duration = duration / tfreq[0]
                    dmin = int(duration / 60)
                    dsec = int(duration - dmin * 60)
                    dmsec = round((duration - dmin * 60 - dsec) * 1000)
                    info["duration"] = "%d:%02d.%d" % (dmin, dsec, dmsec)
                    info["signal"] = [{
                        "name": "Unspecified",
                        "tps": 1,
                        "units": None,
                        "gain": 1,
                        "adcres": 11,
                        "adczero": 1024,
                        "baseline": 1024
                    }]
                    info["note"] = []
                    t["info"] = info
                    t["success"] = True
            else:
                t["success"] = False
                t["error"] = "Your request did not specify a database"
        if 'success' in t and t["success"]: t["version"] = "0.68"
    else:
        t["success"] = False
        t["error"] = "Your request did not specify a database"
    return Response(json.htmlsafe_dumps(t),
                    mimetype='application/javascript; charset=uft-8')
예제 #14
0
def get_by_id_todo():
    id = request.args['_id']
    return json.htmlsafe_dumps(get_by_id(id))
예제 #15
0
def get_all():
    print(get_all_CTL())
    return json.htmlsafe_dumps(get_all_CTL())