From 895531c2e3a5103b6c21ba3e0316315e1e982cf3 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 30 Dec 2015 11:03:40 -0500 Subject: [PATCH] Having a method used by instance or class is a bad idea --- gramps/gen/lib/struct.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gramps/gen/lib/struct.py b/gramps/gen/lib/struct.py index a1e81de10..47a2852d9 100644 --- a/gramps/gen/lib/struct.py +++ b/gramps/gen/lib/struct.py @@ -20,6 +20,9 @@ from gramps.gen.lib.handle import HandleClass +def from_struct(struct): + return Struct.instance_from_struct(struct) + class Struct(object): """ Class for getting and setting parts of a struct by dotted path. @@ -288,7 +291,7 @@ class Struct(object): if self.db: if trans is None: with self.transaction("Struct Update", self.db, batch=True) as trans: - new_obj = self.from_struct(struct) + new_obj = Struct.instance_from_struct(struct) name, handle = struct["_class"], struct["handle"] old_obj = self.db.get_from_name_and_handle(name, handle) if old_obj: @@ -298,7 +301,7 @@ class Struct(object): add_func = self.db._tables[name]["add_func"] add_func(new_obj, trans) else: - new_obj = self.from_struct(struct) + new_obj = Struct.instance_from_struct(struct) name, handle = struct["_class"], struct["handle"] old_obj = self.db.get_from_name_and_handle(name, handle) if old_obj: @@ -308,8 +311,11 @@ class Struct(object): add_func = self.db._tables[name]["add_func"] add_func(new_obj, trans) + def from_struct(self): + return Struct.instance_from_struct(self.struct) + @classmethod - def from_struct(self, struct=None): + def instance_from_struct(cls, struct): """ Given a struct with metadata, create a Gramps object. @@ -317,8 +323,6 @@ class Struct(object): """ from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation, Repository, MediaObject, Note, Tag, Date) - if struct is None: - struct = self.struct if isinstance(struct, dict): if "_class" in struct.keys(): if struct["_class"] == "Person":