Commits

Anonymous committed 2eaad31

fix: on no pkey, give read-only view, check for id before attempting to sort by it.

Comments (0)

Files changed (2)

                 childclass = LeafNode
             return childclass(childdata, parent=self, key=key, depth=childdepth)
 
+    class mutable_list(list): pass  # in order to attach attribs
+
     class _StatusBarHandler(logging.Handler):
         'Log to Statusbar.'
         def __init__(self, statusbar, level=logging.NOTSET):
         if legend:
             log.debug('Using cached legend: %s' % legend)
         else:
-            class mutable_list(list): pass  # in order to attach attribs
             try: # get table legend
                 q = self.config['dbtype']['query_tablecols'] % tablename
                 results = self.db.query(dbname, q)
             dbsection = 'db_' + config[appname]['db']
             config['db'] = config.get(dbsection)
             if config['db']:
-                config['db']['tablefilters'] = convert_type(config['db']['tablefilters'])  # :/
+                if 'tablefilters' in config['db']:
+                    config['db']['tablefilters'] = (
+                        convert_type(config['db']['tablefilters']) )
                 dbtypesect = 'dbtype_' + config['db'].pop('type', '')
                 config['dbtype'] = config.get(dbtypesect)
                 if config['dbtype']:
                 if legend.pkeys:
                     pkeys = ','.join( (str(x[1]) for x in legend.pkeys ) )
                     orderby = 'order by %s' % pkeys
+                elif legend.pkeys and ('id' in [ x[1] for x in legend.pkeys ]):
+                    orderby = 'order by id'
                 else:
-                    orderby = 'order by id'
+                    orderby = ''
 
                 q = self.config['dbtype']['query_table'] % (currname, orderby)
                 results = self.db.query(dbname, q)
                 self.populate_cont(results or [], dbname, currname, legend)
         else:
             if type(item) is LeafWidget:
-                legend = [[1, 'col01', 'character varying', None, 'YES', 255, None]]
+                legend = mutable_list(
+                    [[1, 'id', 'character varying', None, 'YES', 255, None]] )
+                legend.pkeys = ((1, 'id'),)
                 for i in range(2,10):
                     dummytype = legend[0][:]  # copy
                     dummytype[0] = i
             if hasattr(legend, 'pkeys') and legend.pkeys:
                 pkeys = legend.pkeys
             else:
-                pkeys = ((1,'id'),)
+                pkeys = None
             log.debug('pkeys:' + repr(pkeys))
             # figure which col is which field, could be more efficient
             nmfromi = dict(( (i,leg[1]) for i,leg in enumerate(legend) ))
 
             for row in data:
                 try:
+                    if not pkeys:  raise KeyError
                     newrow = []
                     # save primary key for later inside edit cell
                     where = ''  #  pkstr = val, ...
 password =
 host =
 ; don't show the following
-tablefilters = pg_, sql_
+;~ tablefilters = pg_, sql_
 ; main db
 dbname = django
 
 module = psycopg2
 query_databases = select datname from pg_database;
 query_table = select * from %s %s;
-query_tables = select tablename from pg_tables;
+query_tables = select tablename from pg_tables
+    where tablename not like 'pg_%' and tablename not like 'sql_%';
 query_tablecols = select
         ordinal_position,
         column_name,