Beispiel #1
0
def view_rdbtable_json(context, request):
    form = request.params
    limit = int(form.get('rp', 15))
    page = int(form.get('page', 1))
    start = max(0, (page - 1) * limit)
    sortorder = form.get('sortorder', None)
    sortname = form.get('sortname', None)
    sort = None
    searchfor = form.get('query', None)
    searchcol = form.get('qtype', None)
    search = None
    result = {'page': page, 'rows': []}
    columns = []
    try:
        columns, is_spatial = define_table_columnns(context)
        try:
            my_table = Table(context.table_name,
                             metadata,
                             *columns,
                             autoload=True)
        except InvalidRequestError:
            my_table = Table(context.table_name, metadata, autoload=True)
        tablen = my_table.count().execute()
        result['total'] = tablen.fetchone()[0]
        cols = []
        for item in my_table.columns.items():
            if type(item[1].type) in [
                    Boolean, Date, DateTime, Integer, Unicode
            ]:
                cols.append(item[0])
        result['columns'] = cols
        pk = my_table.primary_key
        result['primary_key'] = pk.columns.keys()
        if sortname:
            if my_table.columns.get(sortname) is not None:
                if sortorder == 'desc':
                    sort = desc(my_table.columns.get(sortname))
                else:
                    sort = asc(my_table.columns.get(sortname))
        if searchcol and searchfor:
            if my_table.columns.get(searchcol) is not None:
                search = my_table.columns.get(searchcol) == searchfor
        query = my_table.select(whereclause=search,
                                offset=start,
                                limit=limit,
                                order_by=sort)
        rp = query.execute()
        for row in rp:
            cell = []
            ids = []
            for c in cols:
                cell.append(row[c])
            for c in pk.columns.keys():
                ids.append(row[c])
            #id = ':'.join(str(ids))
            result['rows'].append({"id": ids, "cell": cell})
        return Response(json.dumps(result))
    except NoSuchTableError:
        return Response('[]')
Beispiel #2
0
def view_rdbtable_json(context, request):
    form = request.params
    limit = int(form.get('rp', 15))
    page = int(form.get('page', 1))
    start = max(0, (page - 1) * limit)
    sortorder = form.get('sortorder',None)
    sortname = form.get('sortname',None)
    sort = None
    searchfor = form.get('query',None)
    searchcol = form.get('qtype',None)
    search = None
    result={'page': page, 'rows':[]}
    columns =[]
    try:
        columns, is_spatial = define_table_columnns(context)
        try:
            my_table = Table(context.table_name, metadata,
                *columns,  autoload=True)
        except InvalidRequestError:
            my_table = Table(context.table_name, metadata, autoload=True)
        tablen = my_table.count().execute()
        result['total'] = tablen.fetchone()[0]
        cols =[]
        for item in my_table.columns.items():
            if type(item[1].type) in [Boolean, Date,
                                DateTime, Integer, Unicode]:
                cols.append(item[0])
        result['columns'] = cols
        pk = my_table.primary_key
        result['primary_key'] = pk.columns.keys()
        if sortname:
            if my_table.columns.get(sortname) is not None:
                if sortorder == 'desc':
                    sort = desc(my_table.columns.get(sortname))
                else:
                    sort = asc(my_table.columns.get(sortname))
        if searchcol and searchfor:
            if my_table.columns.get(searchcol) is not None:
                search = my_table.columns.get(searchcol) == searchfor
        query = my_table.select(whereclause=search, offset=start, limit=limit, order_by=sort)
        rp = query.execute()
        for row in rp:
            cell = []
            ids = []
            for c in cols:
                cell.append(row[c])
            for c in pk.columns.keys():
                 ids.append(row[c])
            #id = ':'.join(str(ids))
            result['rows'].append(
                {"id":ids,"cell":cell})
        return Response(json.dumps(result))
    except NoSuchTableError:
        return Response('[]')
Beispiel #3
0
def view_rdb_table(context, request):
    js_template = """
    $("#flexitable").flexigrid(
            {
            url: '%(url)s',
            dataType: 'json',
            colModel : [
                %(col_model)s
                ],
            searchitems : [
                %(search)s
                ],
            usepager: true,
            title: '%(title)s',
            useRp: true,
            rp: 20,
            showTableToggleBtn: true,
            width: 700,
            height: 200
            }
        );
        """
    col_t = "{display: '%s', name : '%s', width : %i, sortable : %s, align: 'left', hide: false}"
    search_t = "{display: '%s', name : '%s'}"
    tl = []
    ts = []
    kotti_rdbt_resources.need()
    if request.POST.get('create-columns') == 'extract-columns':
        create_columns(context, request)
    elif request.POST.get("create-table") == "create-and-populate":
        create_rdb_table(context, request)
        populate_rdb_table(context, request)
    result = {'columns': [], 'values': [], 'js':'/*--*/'}
    url = request.resource_url(context)
    if context.is_created:
        try:
            columns, is_spatial = define_table_columnns(context)
            try:
                my_table = Table(context.table_name, metadata,
                    *columns,  autoload=True)
            except InvalidRequestError:
                my_table = Table(context.table_name, metadata, autoload=True)
            for item in my_table.columns.items():
                if type(item[1].type) in [Boolean, Date,
                                    DateTime, Integer, Unicode]:
                    result['columns'].append(item[0])
                    tl.append( col_t %(item[0], item[0], 80, 'true'))
                    ts.append( search_t %(item[0], item[0]))
            js = js_template % {
                'url':url +'@@json',
                'col_model': ',\n'.join(tl),
                'search': ',\n'.join(ts),
                'title': context.table_name,
            }
            result['js'] = js
            rp = my_table.select(limit=10).execute()
            for row in rp:
                values = []
                for c in result['columns']:
                    values.append(row[c])
                result['values'].append(values)
        except NoSuchTableError:
            context.is_created = False
            request.session.flash(u'Table not found, marked as not created')
    return result
Beispiel #4
0
def view_rdb_table(context, request):
    js_template = """
    $("#flexitable").flexigrid(
            {
            url: '%(url)s',
            dataType: 'json',
            colModel : [
                %(col_model)s
                ],
            searchitems : [
                %(search)s
                ],
            usepager: true,
            title: '%(title)s',
            useRp: true,
            rp: 20,
            showTableToggleBtn: true,
            width: 700,
            height: 200
            }
        );
        """
    col_t = "{display: '%s', name : '%s', width : %i, sortable : %s, align: 'left', hide: false}"
    search_t = "{display: '%s', name : '%s'}"
    tl = []
    ts = []
    kotti_rdbt_resources.need()
    if request.POST.get('create-columns') == 'extract-columns':
        create_columns(context, request)
    elif request.POST.get("create-table") == "create-and-populate":
        create_rdb_table(context, request)
        populate_rdb_table(context, request)
    result = {'columns': [], 'values': [], 'js': '/*--*/'}
    url = request.resource_url(context)
    if context.is_created:
        try:
            columns, is_spatial = define_table_columnns(context)
            try:
                my_table = Table(context.table_name,
                                 metadata,
                                 *columns,
                                 autoload=True)
            except InvalidRequestError:
                my_table = Table(context.table_name, metadata, autoload=True)
            for item in my_table.columns.items():
                if type(item[1].type) in [
                        Boolean, Date, DateTime, Integer, Unicode
                ]:
                    result['columns'].append(item[0])
                    tl.append(col_t % (item[0], item[0], 80, 'true'))
                    ts.append(search_t % (item[0], item[0]))
            js = js_template % {
                'url': url + '@@json',
                'col_model': ',\n'.join(tl),
                'search': ',\n'.join(ts),
                'title': context.table_name,
            }
            result['js'] = js
            rp = my_table.select(limit=10).execute()
            for row in rp:
                values = []
                for c in result['columns']:
                    values.append(row[c])
                result['values'].append(values)
        except NoSuchTableError:
            context.is_created = False
            request.session.flash(u'Table not found, marked as not created')
    return result