コード例 #1
0
ファイル: web.py プロジェクト: maurergroup/ase_local
    def create_table(self, db: Database, uid_key: str,
                     keys: List[str]) -> Table:
        query = self.query
        if self.nrows is None:
            try:
                self.nrows = db.count(query)
            except (ValueError, KeyError) as e:
                error = ', '.join(['Bad query'] + list(e.args))
                from flask import flash
                flash(error)
                query = 'id=0'  # this will return no rows
                self.nrows = 0

        table = Table(db, uid_key)
        table.select(query,
                     self.columns,
                     self.sort,
                     self.limit,
                     offset=self.page * self.limit,
                     show_empty_columns=True)
        table.format()
        assert self.columns is not None
        table.addcolumns = sorted(column for column in all_columns + keys
                                  if column not in self.columns)
        return table
コード例 #2
0
def index():
    global next_table_id
    table_id = int(request.args.get('x', '0'))
    if table_id not in tables:
        table_id = next_table_id
        next_table_id += 1
        query = ''
        columns = list(all_columns)
        sort = 'id'
        limit = 100
        opened = set()
    else:
        query, columns, sort, limit, opened = tables[table_id]

    if 'toggle' in request.args:
        column = request.args['toggle']
        if column in columns:
            columns.remove(column)
            if column == sort.lstrip('-'):
                sort = 'id'
        else:
            columns.append(column)
    elif 'sort' in request.args:
        column = request.args['sort']
        if column == sort:
            sort = '-' + column
        elif '-' + column == sort:
            sort = 'id'
        else:
            sort = column
    elif 'query' in request.args:
        query = request.args['query'].encode()
        limit = int(request.args.get('limit', '0'))
        columns = list(all_columns)
        sort = 'id'
        opened = set()

    table = Table(connection)
    table.select(query, columns, sort, limit)
    tables[table_id] = query, table.columns, sort, limit, opened
    table.format(SUBSCRIPT)
    return render_template('table.html',
                           t=table,
                           query=query,
                           sort=sort,
                           limit=limit,
                           tid=table_id,
                           opened=opened,
                           home=home)
コード例 #3
0
ファイル: app.py プロジェクト: PHOTOX/fuase
def index():
    global next_table_id
    table_id = int(request.args.get('x', '0'))
    if table_id not in tables:
        table_id = next_table_id
        next_table_id += 1
        query = ''
        columns = list(all_columns)
        sort = 'id'
        limit = 100
        opened = set()
    else:
        query, columns, sort, limit, opened = tables[table_id]

    if 'toggle' in request.args:
        column = request.args['toggle']
        if column in columns:
            columns.remove(column)
            if column == sort.lstrip('-'):
                sort = 'id'
        else:
            columns.append(column)
    elif 'sort' in request.args:
        column = request.args['sort']
        if column == sort:
            sort = '-' + column
        elif '-' + column == sort:
            sort = 'id'
        else:
            sort = column
    elif 'query' in request.args:
        query = request.args['query'].encode()
        limit = int(request.args.get('limit', '0'))
        columns = list(all_columns)
        sort = 'id'
        opened = set()
        
    table = Table(connection)
    table.select(query, columns, sort, limit)
    tables[table_id] = query, table.columns, sort, limit, opened
    table.format(SUBSCRIPT)
    return render_template('table.html', t=table, query=query, sort=sort,
                           limit=limit, tid=table_id, opened=opened)
コード例 #4
0
ファイル: web.py プロジェクト: martin-stoehr/ase-devel
    def create_table(self, db: Database, uid_key: str) -> Table:
        query = self.query
        if self.nrows is None:
            try:
                self.nrows = db.count(query)
            except (ValueError, KeyError) as e:
                error = ', '.join(['Bad query'] + list(e.args))
                flash(error)
                query = 'id=0'  # this will return no rows
                self.nrows = 0

        table = Table(db, uid_key)
        table.select(query, self.columns, self.sort,
                     self.limit, offset=self.page * self.limit)
        table.format()
        table.addcolumns = sorted(column for column in
                                  all_columns + table.keys
                                  if column not in table.columns)
        return table
コード例 #5
0
ファイル: app.py プロジェクト: essil1/ase-laser
def index(project):
    global next_con_id

    # Backwards compatibility:
    project = request.args.get('project') or project

    if not projects:
        # First time: initialize list of projects
        for proj, db in sorted(databases.items()):
            meta = ase.db.web.process_metadata(db)
            db.meta = meta
            nrows = len(db)
            projects.append((proj, db.meta.get('title', proj), nrows))
            print('Initialized {proj}: {nrows} rows'.format(proj=proj,
                                                            nrows=nrows))

    if project is None and len(projects) > 1:
        return render_template('projects.html',
                               projects=projects,
                               home=home,
                               md=None,
                               ase_db_footer=ase_db_footer)

    if project is None:
        project = list(databases)[0]

    con_id = int(request.args.get('x', '0'))
    if con_id in connections:
        query, nrows, page, columns, sort, limit = connections[con_id]

    if con_id not in connections:
        # Give this connetion a new id:
        con_id = next_con_id
        next_con_id += 1
        query = ['', {}, '']
        nrows = None
        page = 0
        columns = None
        sort = 'id'
        limit = 25

    db = databases.get(project)
    if db is None:
        return 'No such project: ' + project

    meta = db.meta

    if columns is None:
        columns = meta.get('default_columns')[:] or list(all_columns)

    if 'sort' in request.args:
        column = request.args['sort']
        if column == sort:
            sort = '-' + column
        elif '-' + column == sort:
            sort = 'id'
        else:
            sort = column
        page = 0
    elif 'query' in request.args:
        dct = {}
        query = [request.args['query']]
        q = query[0]
        for special in meta['special_keys']:
            kind, key = special[:2]
            if kind == 'SELECT':
                value = request.args['select_' + key]
                dct[key] = convert_str_to_int_float_or_str(value)
                if value:
                    q += ',{}={}'.format(key, value)
            elif kind == 'BOOL':
                value = request.args['bool_' + key]
                dct[key] = convert_str_to_int_float_or_str(value)
                if value:
                    q += ',{}={}'.format(key, value)
            else:
                v1 = request.args['from_' + key]
                v2 = request.args['to_' + key]
                var = request.args['range_' + key]
                dct[key] = (v1, v2, var)
                if v1 or v2:
                    var = request.args['range_' + key]
                    if v1:
                        q += ',{}>={}'.format(var, v1)
                    if v2:
                        q += ',{}<={}'.format(var, v2)
        q = q.lstrip(',')
        query += [dct, q]
        sort = 'id'
        page = 0
        nrows = None
    elif 'limit' in request.args:
        limit = int(request.args['limit'])
        page = 0
    elif 'page' in request.args:
        page = int(request.args['page'])

    if 'toggle' in request.args:
        column = request.args['toggle']
        if column == 'reset':
            columns = meta.get('default_columns')[:] or list(all_columns)
        else:
            if column in columns:
                columns.remove(column)
                if column == sort.lstrip('-'):
                    sort = 'id'
                    page = 0
            else:
                columns.append(column)

    okquery = query

    if nrows is None:
        try:
            nrows = db.count(query[2])
        except (ValueError, KeyError) as e:
            flash(', '.join(['Bad query'] + list(e.args)))
            okquery = ('', {}, 'id=0')  # this will return no rows
            nrows = 0

    table = Table(db, meta.get('unique_key', 'id'))
    table.select(okquery[2], columns, sort, limit, offset=page * limit)

    con = Connection(query, nrows, page, columns, sort, limit)
    connections[con_id] = con

    if len(connections) > 1000:
        # Forget old connections:
        for cid in sorted(connections)[:200]:
            del connections[cid]

    table.format(SUBSCRIPT)

    addcolumns = [
        column for column in all_columns + table.keys
        if column not in table.columns
    ]

    return render_template('table.html',
                           project=project,
                           t=table,
                           md=meta,
                           con=con,
                           x=con_id,
                           home=home,
                           ase_db_footer=ase_db_footer,
                           pages=pages(page, nrows, limit),
                           nrows=nrows,
                           addcolumns=addcolumns,
                           row1=page * limit + 1,
                           row2=min((page + 1) * limit, nrows),
                           download_button=download_button)
コード例 #6
0
ファイル: app.py プロジェクト: jboes/ase
def index():
    global next_con_id
    con_id = int(request.args.get('x', '0'))
    if con_id not in connections:
        con_id = next_con_id
        next_con_id += 1
        query = ''
        columns = list(all_columns)
        sort = 'id'
        limit = 25
        opened = set()
        nrows = None
        page = 0
    else:
        query, nrows, page, columns, sort, limit, opened = connections[con_id]

    if 'sort' in request.args:
        column = request.args['sort']
        if column == sort:
            sort = '-' + column
        elif '-' + column == sort:
            sort = 'id'
        else:
            sort = column
        page = 0
    elif 'query' in request.args:
        query = request.args['query'].encode()
        try:
            limit = max(1, min(int(request.args.get('limit', limit)), 200))
        except ValueError:
            pass
        sort = 'id'
        opened = set()
        page = 0
        nrows = None
    elif 'page' in request.args:
        page = int(request.args['page'])

    if 'toggle' in request.args:
        tcolumns = request.args['toggle'].split(',')
        if tcolumns == ['reset']:
            columns = list(all_columns)
        else:
            for column in tcolumns:
                if column in columns:
                    columns.remove(column)
                    if column == sort.lstrip('-'):
                        sort = 'id'
                        page = 0
                else:
                    columns.append(column)
        
    if nrows is None:
        nrows = db.count(query)
        
    table = Table(db)
    table.select(query, columns, sort, limit, offset=page * limit)
    con = Connection(query, nrows, page, columns, sort, limit, opened)
    connections[con_id] = con
    table.format(SUBSCRIPT)
    addcolumns = [column for column in all_columns + table.keys
                  if column not in table.columns]

    return render_template('table.html', t=table, con=con, cid=con_id,
                           home=home, pages=pages(page, nrows, limit),
                           nrows=nrows,
                           addcolumns=addcolumns,
                           row1=page * limit + 1,
                           row2=min((page + 1) * limit, nrows))
コード例 #7
0
ファイル: app.py プロジェクト: rchiechi/QuantumParse
def index():
    global next_con_id

    if not projects:
        # First time: initialize list of projects
        projects[:] = [(proj, d.metadata.get('title', proj))
                       for proj, d in sorted(databases.items())]

    con_id = int(request.args.get('x', '0'))
    if con_id in connections:
        project, query, nrows, page, columns, sort, limit = connections[con_id]
        newproject = request.args.get('project')
        if newproject is not None and newproject != project:
            con_id = 0

    if con_id not in connections:
        # Give this connetion a new id:
        con_id = next_con_id
        next_con_id += 1
        project = request.args.get('project', projects[0][0])
        query = ['', {}, '']
        nrows = None
        page = 0
        columns = None
        sort = 'id'
        limit = 25

    db = databases[project]

    if not hasattr(db, 'meta'):
        meta = ase.db.web.process_metadata(db)
        db.meta = meta
    else:
        meta = db.meta

    if columns is None:
        columns = meta.get('default_columns')[:] or list(all_columns)

    if 'sort' in request.args:
        column = request.args['sort']
        if column == sort:
            sort = '-' + column
        elif '-' + column == sort:
            sort = 'id'
        else:
            sort = column
        page = 0
    elif 'query' in request.args:
        dct = {}
        query = [request.args['query']]
        q = query[0]
        for special in meta['special_keys']:
            kind, key = special[:2]
            if kind == 'SELECT':
                value = request.args['select_' + key]
                dct[key] = value
                if value:
                    q += ',{}={}'.format(key, value)
            elif kind == 'BOOL':
                value = request.args['bool_' + key]
                dct[key] = value
                if value:
                    q += ',{}={}'.format(key, value)
            else:
                v1 = request.args['from_' + key]
                v2 = request.args['to_' + key]
                var = request.args['range_' + key]
                dct[key] = (v1, v2, var)
                if v1 or v2:
                    var = request.args['range_' + key]
                    if v1:
                        q += ',{}>={}'.format(var, v1)
                    if v2:
                        q += ',{}<={}'.format(var, v2)
        q = q.lstrip(',')
        query += [dct, q]
        sort = 'id'
        page = 0
        nrows = None
    elif 'limit' in request.args:
        limit = int(request.args['limit'])
        page = 0
    elif 'page' in request.args:
        page = int(request.args['page'])

    if 'toggle' in request.args:
        column = request.args['toggle']
        if column == 'reset':
            columns = meta.get('default_columns')[:] or list(all_columns)
        else:
            if column in columns:
                columns.remove(column)
                if column == sort.lstrip('-'):
                    sort = 'id'
                    page = 0
            else:
                columns.append(column)

    okquery = query

    if nrows is None:
        try:
            nrows = db.count(query[2])
        except (ValueError, KeyError) as e:
            flash(', '.join(['Bad query'] + list(e.args)))
            okquery = ('', {}, 'id=0')  # this will return no rows
            nrows = 0

    table = Table(db)
    table.select(okquery[2], columns, sort, limit, offset=page * limit)

    con = Connection(project, query, nrows, page, columns, sort, limit)
    connections[con_id] = con

    if len(connections) > 1000:
        # Forget old connections:
        for cid in sorted(connections)[:200]:
            del connections[cid]

    table.format(SUBSCRIPT)

    addcolumns = [column for column in all_columns + table.keys
                  if column not in table.columns]

    return render_template('table.html',
                           project=project,
                           projects=projects,
                           t=table,
                           md=meta,
                           con=con,
                           x=con_id,
                           home=home,
                           pages=pages(page, nrows, limit),
                           nrows=nrows,
                           addcolumns=addcolumns,
                           row1=page * limit + 1,
                           row2=min((page + 1) * limit, nrows))
コード例 #8
0
ファイル: app.py プロジェクト: Xu-Kai/lotsofcoresbook2code
def index():
    global next_con_id
    con_id = int(request.args.get('x', '0'))
    if con_id not in connections:
        con_id = next_con_id
        next_con_id += 1
        query = ''
        columns = list(all_columns)
        sort = 'id'
        limit = 25
        opened = set()
        nrows = None
        page = 0
    else:
        query, nrows, page, columns, sort, limit, opened = connections[con_id]

    if 'sort' in request.args:
        column = request.args['sort']
        if column == sort:
            sort = '-' + column
        elif '-' + column == sort:
            sort = 'id'
        else:
            sort = column
        page = 0
    elif 'query' in request.args:
        query = request.args['query'].encode()
        try:
            limit = max(1, min(int(request.args.get('limit', limit)), 200))
        except ValueError:
            pass
        sort = 'id'
        opened = set()
        page = 0
        nrows = None
    elif 'page' in request.args:
        page = int(request.args['page'])

    if 'toggle' in request.args:
        tcolumns = request.args['toggle'].split(',')
        if tcolumns == ['reset']:
            columns = list(all_columns)
        else:
            for column in tcolumns:
                if column in columns:
                    columns.remove(column)
                    if column == sort.lstrip('-'):
                        sort = 'id'
                        page = 0
                else:
                    columns.append(column)

    if nrows is None:
        nrows = db.count(query)

    table = Table(db)
    table.select(query, columns, sort, limit, offset=page * limit)
    con = Connection(query, nrows, page, columns, sort, limit, opened)
    connections[con_id] = con
    table.format(SUBSCRIPT)
    addcolumns = [
        column for column in all_columns + table.keys
        if column not in table.columns
    ]

    return render_template('table.html',
                           t=table,
                           con=con,
                           cid=con_id,
                           home=home,
                           pages=pages(page, nrows, limit),
                           nrows=nrows,
                           addcolumns=addcolumns,
                           row1=page * limit + 1,
                           row2=min((page + 1) * limit, nrows))
コード例 #9
0
def index():
    global next_con_id
    con_id = int(request.args.get("x", "0"))
    if con_id not in connections:
        con_id = next_con_id
        next_con_id += 1
        query = ""
        columns = list(all_columns)
        sort = "id"
        limit = 25
        opened = set()
        nrows = None
        page = 0
    else:
        query, nrows, page, columns, sort, limit, opened = connections[con_id]

    if "sort" in request.args:
        column = request.args["sort"]
        if column == sort:
            sort = "-" + column
        elif "-" + column == sort:
            sort = "id"
        else:
            sort = column
        page = 0
    elif "query" in request.args:
        query = request.args["query"].encode()
        try:
            limit = max(1, min(int(request.args.get("limit", limit)), 200))
        except ValueError:
            pass
        sort = "id"
        opened = set()
        page = 0
        nrows = None
    elif "page" in request.args:
        page = int(request.args["page"])

    if "toggle" in request.args:
        tcolumns = request.args["toggle"].split(",")
        if tcolumns == ["reset"]:
            columns = list(all_columns)
        else:
            for column in tcolumns:
                if column in columns:
                    columns.remove(column)
                    if column == sort.lstrip("-"):
                        sort = "id"
                        page = 0
                else:
                    columns.append(column)

    if nrows is None:
        nrows = db.count(query)

    table = Table(db)
    table.select(query, columns, sort, limit, offset=page * limit)
    con = Connection(query, nrows, page, columns, sort, limit, opened)
    connections[con_id] = con
    table.format(SUBSCRIPT)
    addcolumns = [column for column in all_columns + table.keys if column not in table.columns]

    return render_template(
        "table.html",
        t=table,
        con=con,
        cid=con_id,
        home=home,
        pages=pages(page, nrows, limit),
        nrows=nrows,
        addcolumns=addcolumns,
        row1=page * limit + 1,
        row2=min((page + 1) * limit, nrows),
    )