예제 #1
0
 def post(self, name):
     session = Session()
     Schema = make_table_model("system_chartschema")
     schema = session.query(Schema).filter(Schema.name == name).one()
     schema.name = self.request.arguments.get("name")[0]
     schema.schema = self.request.arguments.get("schema")[0]
     session.commit()
     session.close()
     return self.redirect("/chart/schema/")
예제 #2
0
 def post(self,):
     if not self.request.arguments:
         self.render("chart/schema_insert.html")
     else:
         session = Session()
         M = make_table_model("system_chartschema")
         m = M()
         for k, v in self.request.arguments.items():
             setattr(m, k, v[0])
         session.add(m)
         session.commit()
         session.close()
         return self.redirect("/chart/schema/")
예제 #3
0
    def get(self, tablename):
        session = Session()
        M = make_table_model(tablename.encode("utf-8"))
        filter_args = []
        filter_args = [getattr(M, k) == v[0] for k, v in self.request.arguments.items()]
        if filter_args:
            models = session.query(M).filter(*filter_args).order_by(desc("id")).limit(100)
        else:
            models = session.query(M).order_by(desc("id")).limit(100)

        models = [[getattr(model, c.name) for c in M.__table__._columns] for model in models]
        session.close()
        self.render("chart/model.html", tablename=tablename, models=models, columns=M.__table__._columns)
예제 #4
0
def make_query(name, params={}, default_conf={}):
    session = Session()
    Schema = make_table_model("system_chartschema")
    schema = session.query(Schema).filter(Schema.name == name).one()
    schema = yaml.load(schema.schema)

    XModel, xfield = get_field(schema[name]["X"])
    y = schema[name]["Y"]
    time_interval = schema[name]["interval"] if schema[name].has_key("interval") else 12

    field_query = []
    filter_args = []
    group_by = []

    for table_field, options in y.items():
        if options is None:
            options = {}
        Model, field = get_field(table_field)
        filter_args = get_filter_args(Model, params, time_interval)
        if options and options.get("func"):
            function = getattr(func, options["func"])
            field = function(field)

        field_query.append(field)
    field_query.append(xfield)
    query = session.query(*field_query)
    filter_function = getattr(query, "filter")

    query = filter_function(*filter_args)
    if schema[name].get("group"):
        fields = get_group_fields(schema[name]["group"])
        query = query.group_by(*fields)
    query = query.order_by(asc("datetime"))
    logger.debug(str(query))
    option = schema[name].get("option", {})
    option.update(default_conf)
    result = _parse_query(query, field_query, option)
    session.close()
    return json.dumps(result)
예제 #5
0
 def get(self, name):
     session = Session()
     Schema = make_table_model("system_chartschema")
     schema = session.query(Schema).filter(Schema.name == name).one()
     session.close()
     self.render("chart/schema_edit.html", schema=schema)
예제 #6
0
 def get(self):
     session = Session()
     Schema = make_table_model("system_chartschema")
     query = session.query(Schema).order_by(desc("id"))
     session.close()
     self.render("chart/schema.html", query=query)