Merge branch 'master' into peter
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
commit
0b8d47824a
4 changed files with 45 additions and 15 deletions
|
|
@ -576,7 +576,9 @@ class Database:
|
|||
|
||||
def upgrade(self, txntype=None, notify=None, version=None):
|
||||
if notify is None:
|
||||
notify = lambda x: x
|
||||
|
||||
def notify(x):
|
||||
x
|
||||
if txntype is None:
|
||||
txntype = list(self._schema.transaction_types())
|
||||
elif isinstance(txntype, str):
|
||||
|
|
|
|||
|
|
@ -249,8 +249,9 @@ class HashHook(Hook):
|
|||
line)
|
||||
except (IOError, FileNotFoundError):
|
||||
if not self._options["forgiving"]:
|
||||
raise newfol.exception.UpgradeNeededError("dtb is missing"
|
||||
+ " checksum")
|
||||
raise newfol.exception.UpgradeNeededError("dtb is " +
|
||||
"missing " +
|
||||
"checksum")
|
||||
|
||||
def commit_close(self):
|
||||
if "w" in self._mode:
|
||||
|
|
|
|||
|
|
@ -375,13 +375,14 @@ class AboutView(StandardView):
|
|||
|
||||
|
||||
class RecordView(StandardView):
|
||||
def __init__(self, button, record=None):
|
||||
def __init__(self, title, button, record=None):
|
||||
dbd = DatabaseData()
|
||||
if record is None:
|
||||
self.rec = filemanip.Record([None] * dbd.schema().nfields())
|
||||
else:
|
||||
self.rec = record
|
||||
self.button_name = button
|
||||
self.title = title
|
||||
|
||||
def _compute_titles_from_table(self, table):
|
||||
titles = []
|
||||
|
|
@ -462,14 +463,18 @@ class RecordView(StandardView):
|
|||
|
||||
def _render_standard(self, loop):
|
||||
self.loop = loop
|
||||
head = self.text(self.title, "header")
|
||||
# We need a box widget for the frame, but GridFlow is a flow widget.
|
||||
pile = urwid.Pile([self._render_record(self.rec)])
|
||||
return urwid.Filler(pile, valign="top")
|
||||
filler = urwid.Filler(pile, valign="top")
|
||||
return urwid.Frame(filler, head)
|
||||
|
||||
|
||||
class DisplayRecordView(RecordView):
|
||||
def __init__(self, record=None):
|
||||
super().__init__(_("Commit"), record)
|
||||
def __init__(self, title=None, record=None):
|
||||
if title is None:
|
||||
title = _("Add Record")
|
||||
super().__init__(title, _("Commit"), record)
|
||||
|
||||
def _build_record(self):
|
||||
fields = [i.widget_list[1].get_edit_text() for i in self.cells]
|
||||
|
|
@ -537,7 +542,8 @@ class DisplayRecordView(RecordView):
|
|||
|
||||
class SearchRecordView(RecordView):
|
||||
def __init__(self, record=None):
|
||||
super().__init__(_("Select Display Template"), record)
|
||||
super().__init__(_("Search Records"), _("Select Display Template"),
|
||||
record)
|
||||
|
||||
def _get_fields(self):
|
||||
return [i.widget_list[1].get_edit_text() for i in self.cells]
|
||||
|
|
@ -585,7 +591,7 @@ class SearchRecordView(RecordView):
|
|||
|
||||
class DisplayTemplateRecordView(RecordView):
|
||||
def __init__(self, table, records):
|
||||
super().__init__(_("Search"))
|
||||
super().__init__(_("Display Template"), _("Search"))
|
||||
self.records = records
|
||||
self.table = table
|
||||
|
||||
|
|
@ -646,7 +652,7 @@ class DisplayTemplateRecordView(RecordView):
|
|||
|
||||
class SortingTemplateRecordView(RecordView):
|
||||
def __init__(self, table, records, selected):
|
||||
super().__init__(_("Search"))
|
||||
super().__init__(_("Sorting Template"), _("Search"))
|
||||
self.records = records
|
||||
self.table = table
|
||||
self.selected = selected
|
||||
|
|
@ -862,7 +868,7 @@ class RecordListView(ListView):
|
|||
cur = self._current_item()
|
||||
if cur is None:
|
||||
return
|
||||
self.session.render_view(DisplayRecordView(cur))
|
||||
self.session.render_view(DisplayRecordView(_("Current Record"), cur))
|
||||
|
||||
|
||||
class TableContentsListView(RecordListView):
|
||||
|
|
@ -1148,12 +1154,16 @@ def import_into(db, dtbname, dbtype, minfields=0, strict=False,
|
|||
|
||||
def export_from(db, table, dbtype):
|
||||
vault = filemanip.FileStorage(dbtype, sys.stdout)
|
||||
f = lambda x: True
|
||||
|
||||
def f(x):
|
||||
return True
|
||||
|
||||
def g(x):
|
||||
return x.table == table
|
||||
if table is None and dbtype == "csv":
|
||||
raise newfol.exception.NewfolError(_("A table is required for csv"))
|
||||
if table is not None:
|
||||
f = lambda x: x.table == table
|
||||
vault.store(db.records(f))
|
||||
func = f if table is None else g
|
||||
vault.store(db.records(func))
|
||||
|
||||
|
||||
def parse_args(args):
|
||||
|
|
|
|||
|
|
@ -253,6 +253,10 @@ class ExampleFile(newfol.filemanip.FileFormat):
|
|||
return [Record(['a', 'b'])]
|
||||
|
||||
|
||||
class ExampleHook(newfol.filemanip.Hook):
|
||||
pass
|
||||
|
||||
|
||||
class PluggableBackendsTest(unittest.TestCase):
|
||||
def test_adding_backend(self):
|
||||
FileStorage.register_backend('example', ExampleFile)
|
||||
|
|
@ -269,5 +273,18 @@ class PluggableBackendsTest(unittest.TestCase):
|
|||
with self.assertRaises(KeyError):
|
||||
FileStorage.BACKENDS['example']
|
||||
|
||||
|
||||
class PluggableHooksTest(unittest.TestCase):
|
||||
def test_adding_hook(self):
|
||||
FileStorage.register_hook('example', ExampleHook)
|
||||
self.assertEqual(FileStorage.HOOKS['example'], ExampleHook)
|
||||
|
||||
def test_removing_hook(self):
|
||||
FileStorage.register_hook('example', ExampleFile)
|
||||
self.assertEqual(FileStorage.HOOKS['example'], ExampleFile)
|
||||
FileStorage.unregister_hook('example')
|
||||
with self.assertRaises(KeyError):
|
||||
FileStorage.HOOKS['example']
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue