Completed tag database upgrade; additional changes for CLIManager
svn: r23299
This commit is contained in:
parent
2238e0479e
commit
9780abd304
@ -656,6 +656,15 @@ class DbDjango(DbWriteBase, DbReadBase):
|
|||||||
else:
|
else:
|
||||||
return [item.handle for item in self.dji.Note.all()]
|
return [item.handle for item in self.dji.Note.all()]
|
||||||
|
|
||||||
|
def get_media_from_handle(self, handle):
|
||||||
|
if handle in self.import_cache:
|
||||||
|
return self.import_cache[handle]
|
||||||
|
try:
|
||||||
|
media = self.dji.Media.get(handle=handle)
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
return self.make_media(media)
|
||||||
|
|
||||||
def get_event_from_handle(self, handle):
|
def get_event_from_handle(self, handle):
|
||||||
if handle in self.import_cache:
|
if handle in self.import_cache:
|
||||||
return self.import_cache[handle]
|
return self.import_cache[handle]
|
||||||
@ -890,6 +899,10 @@ class DbDjango(DbWriteBase, DbReadBase):
|
|||||||
def iter_tag_handles(self):
|
def iter_tag_handles(self):
|
||||||
return (tag.handle for tag in self.dji.Tag.all())
|
return (tag.handle for tag in self.dji.Tag.all())
|
||||||
|
|
||||||
|
def iter_media_objects(self):
|
||||||
|
return (self.get_media_from_handle(media.handle)
|
||||||
|
for media in self.dji.Media.all())
|
||||||
|
|
||||||
def get_tag_from_name(self, name):
|
def get_tag_from_name(self, name):
|
||||||
try:
|
try:
|
||||||
tag = self.dji.Tag.filter(name=name)
|
tag = self.dji.Tag.filter(name=name)
|
||||||
|
@ -453,6 +453,7 @@ class PrimaryObject(models.Model):
|
|||||||
public = models.BooleanField('public', default=True)
|
public = models.BooleanField('public', default=True)
|
||||||
#attributes = models.ManyToManyField("Attribute", blank=True, null=True)
|
#attributes = models.ManyToManyField("Attribute", blank=True, null=True)
|
||||||
cache = models.TextField(blank=True, null=True)
|
cache = models.TextField(blank=True, null=True)
|
||||||
|
tags = models.ManyToManyField('Tag', blank=True, null=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return cuni("%s: %s") % (self.__class__.__name__,
|
return cuni("%s: %s") % (self.__class__.__name__,
|
||||||
@ -462,6 +463,9 @@ class PrimaryObject(models.Model):
|
|||||||
return cuni("/%s/%s") % (self.__class__.__name__.lower(),
|
return cuni("/%s/%s") % (self.__class__.__name__.lower(),
|
||||||
self.handle)
|
self.handle)
|
||||||
|
|
||||||
|
def get_tag_list(self):
|
||||||
|
return tuple([tag.handle for tag in self.tags.all()])
|
||||||
|
|
||||||
class MyFamilies(models.Model):
|
class MyFamilies(models.Model):
|
||||||
person = models.ForeignKey("Person")
|
person = models.ForeignKey("Person")
|
||||||
family = models.ForeignKey("Family")
|
family = models.ForeignKey("Family")
|
||||||
@ -493,8 +497,6 @@ class Person(PrimaryObject):
|
|||||||
birth_ref_index = models.IntegerField("Birth Reference Index", default=-1)
|
birth_ref_index = models.IntegerField("Birth Reference Index", default=-1)
|
||||||
death_ref_index = models.IntegerField("Death Reference Index", default=-1)
|
death_ref_index = models.IntegerField("Death Reference Index", default=-1)
|
||||||
|
|
||||||
tags = models.ManyToManyField('Tag', blank=True, null=True)
|
|
||||||
|
|
||||||
# Others keys here:
|
# Others keys here:
|
||||||
# .name_set
|
# .name_set
|
||||||
# .address_set
|
# .address_set
|
||||||
@ -513,9 +515,6 @@ class Person(PrimaryObject):
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return cuni("%s [%s]") % (self.get_primary_name(), self.gramps_id)
|
return cuni("%s [%s]") % (self.get_primary_name(), self.gramps_id)
|
||||||
|
|
||||||
def make_tag_list(self):
|
|
||||||
return tuple()
|
|
||||||
|
|
||||||
def get_selection_string(self):
|
def get_selection_string(self):
|
||||||
return self.name_set.get(preferred=True).get_selection_string()
|
return self.name_set.get(preferred=True).get_selection_string()
|
||||||
|
|
||||||
@ -525,10 +524,6 @@ class Family(PrimaryObject):
|
|||||||
mother = models.ForeignKey('Person', related_name="mother_ref",
|
mother = models.ForeignKey('Person', related_name="mother_ref",
|
||||||
null=True, blank=True)
|
null=True, blank=True)
|
||||||
family_rel_type = models.ForeignKey('FamilyRelType', verbose_name="Type")
|
family_rel_type = models.ForeignKey('FamilyRelType', verbose_name="Type")
|
||||||
tags = models.ManyToManyField('Tag', blank=True, null=True)
|
|
||||||
|
|
||||||
def make_tag_list(self):
|
|
||||||
return tuple()
|
|
||||||
|
|
||||||
#lds_list = models.ManyToManyField('Lds', null=True, blank=True)
|
#lds_list = models.ManyToManyField('Lds', null=True, blank=True)
|
||||||
|
|
||||||
@ -633,10 +628,6 @@ class Media(DateObject, PrimaryObject):
|
|||||||
references = generic.GenericRelation('MediaRef', related_name="refs",
|
references = generic.GenericRelation('MediaRef', related_name="refs",
|
||||||
content_type_field="object_type",
|
content_type_field="object_type",
|
||||||
object_id_field="object_id")
|
object_id_field="object_id")
|
||||||
tags = models.ManyToManyField('Tag', blank=True, null=True)
|
|
||||||
|
|
||||||
def make_tag_list(self):
|
|
||||||
return tuple()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return cuni(self.desc)
|
return cuni(self.desc)
|
||||||
@ -648,10 +639,6 @@ class Note(PrimaryObject):
|
|||||||
references = generic.GenericRelation('NoteRef', related_name="refs",
|
references = generic.GenericRelation('NoteRef', related_name="refs",
|
||||||
content_type_field="object_type",
|
content_type_field="object_type",
|
||||||
object_id_field="object_id")
|
object_id_field="object_id")
|
||||||
tags = models.ManyToManyField('Tag', blank=True, null=True)
|
|
||||||
|
|
||||||
def make_tag_list(self):
|
|
||||||
return tuple()
|
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return cuni(self.gramps_id)
|
return cuni(self.gramps_id)
|
||||||
|
@ -189,6 +189,11 @@ class DjangoInterface(object):
|
|||||||
def clear_tables(self, *args):
|
def clear_tables(self, *args):
|
||||||
return models.clear_tables(*args)
|
return models.clear_tables(*args)
|
||||||
|
|
||||||
|
def get_tag_list(self, obj):
|
||||||
|
print(obj)
|
||||||
|
print(dir(obj))
|
||||||
|
return obj.get_tag_list()
|
||||||
|
|
||||||
def get_attribute_list(self, obj):
|
def get_attribute_list(self, obj):
|
||||||
obj_type = ContentType.objects.get_for_model(obj)
|
obj_type = ContentType.objects.get_for_model(obj)
|
||||||
attribute_list = models.Attribute.objects.filter(object_id=obj.id,
|
attribute_list = models.Attribute.objects.filter(object_id=obj.id,
|
||||||
@ -216,10 +221,10 @@ class DjangoInterface(object):
|
|||||||
else:
|
else:
|
||||||
return list(map(self.pack_name, names))
|
return list(map(self.pack_name, names))
|
||||||
|
|
||||||
def get_source_attribute(self, source):
|
def get_source_attribute_list(self, source):
|
||||||
return [(map.private, map.key, map.value) for map in source.sourceattribute_set.all().order_by("order")]
|
return [(map.private, map.key, map.value) for map in source.sourceattribute_set.all().order_by("order")]
|
||||||
|
|
||||||
def get_citation_attribute(self, citation):
|
def get_citation_attribute_list(self, citation):
|
||||||
return [(map.private, map.key, map.value) for map in citation.citationattribute_set.all().order_by("order")]
|
return [(map.private, map.key, map.value) for map in citation.citationattribute_set.all().order_by("order")]
|
||||||
|
|
||||||
def get_media_list(self, obj):
|
def get_media_list(self, obj):
|
||||||
@ -309,9 +314,10 @@ class DjangoInterface(object):
|
|||||||
attribute_list = self.get_attribute_list(event)
|
attribute_list = self.get_attribute_list(event)
|
||||||
date = self.get_date(event)
|
date = self.get_date(event)
|
||||||
place = self.get_place_handle(event)
|
place = self.get_place_handle(event)
|
||||||
|
tag_list = self.get_tag_list(event)
|
||||||
return (str(handle), gid, the_type, date, description, place,
|
return (str(handle), gid, the_type, date, description, place,
|
||||||
citation_list, note_list, media_list, attribute_list,
|
citation_list, note_list, media_list, attribute_list,
|
||||||
change, private)
|
change, tag_list, private)
|
||||||
|
|
||||||
def get_note_markup(self, note):
|
def get_note_markup(self, note):
|
||||||
retval = []
|
retval = []
|
||||||
@ -337,13 +343,14 @@ class DjangoInterface(object):
|
|||||||
def get_note(self, note):
|
def get_note(self, note):
|
||||||
styled_text = [note.text, self.get_note_markup(note)]
|
styled_text = [note.text, self.get_note_markup(note)]
|
||||||
changed = totime(note.last_changed)
|
changed = totime(note.last_changed)
|
||||||
|
tag_list = self.get_tag_list(note)
|
||||||
return (str(note.handle),
|
return (str(note.handle),
|
||||||
note.gramps_id,
|
note.gramps_id,
|
||||||
styled_text,
|
styled_text,
|
||||||
note.preformatted,
|
note.preformatted,
|
||||||
tuple(note.note_type),
|
tuple(note.note_type),
|
||||||
changed,
|
changed,
|
||||||
tuple(note.make_tag_list()),
|
tag_list,
|
||||||
note.private)
|
note.private)
|
||||||
|
|
||||||
def get_family(self, family):
|
def get_family(self, family):
|
||||||
@ -354,6 +361,7 @@ class DjangoInterface(object):
|
|||||||
lds_seal_list = self.get_lds_list(family)
|
lds_seal_list = self.get_lds_list(family)
|
||||||
citation_list = self.get_citation_list(family)
|
citation_list = self.get_citation_list(family)
|
||||||
note_list = self.get_note_list(family)
|
note_list = self.get_note_list(family)
|
||||||
|
tag_list = self.get_tag_list(family)
|
||||||
if family.father:
|
if family.father:
|
||||||
father_handle = family.father.handle
|
father_handle = family.father.handle
|
||||||
else:
|
else:
|
||||||
@ -369,13 +377,14 @@ class DjangoInterface(object):
|
|||||||
attribute_list, lds_seal_list,
|
attribute_list, lds_seal_list,
|
||||||
citation_list, note_list,
|
citation_list, note_list,
|
||||||
totime(family.last_changed),
|
totime(family.last_changed),
|
||||||
tuple(family.make_tag_list()),
|
tag_list,
|
||||||
family.private)
|
family.private)
|
||||||
|
|
||||||
def get_repository(self, repository):
|
def get_repository(self, repository):
|
||||||
note_list = self.get_note_list(repository)
|
note_list = self.get_note_list(repository)
|
||||||
address_list = self.get_address_list(repository, with_parish=False)
|
address_list = self.get_address_list(repository, with_parish=False)
|
||||||
url_list = self.get_url_list(repository)
|
url_list = self.get_url_list(repository)
|
||||||
|
tag_list = self.get_tag_list(repository)
|
||||||
return (str(repository.handle),
|
return (str(repository.handle),
|
||||||
repository.gramps_id,
|
repository.gramps_id,
|
||||||
tuple(repository.repository_type),
|
tuple(repository.repository_type),
|
||||||
@ -384,12 +393,14 @@ class DjangoInterface(object):
|
|||||||
address_list,
|
address_list,
|
||||||
url_list,
|
url_list,
|
||||||
totime(repository.last_changed),
|
totime(repository.last_changed),
|
||||||
|
tag_list,
|
||||||
repository.private)
|
repository.private)
|
||||||
|
|
||||||
def get_citation(self, citation):
|
def get_citation(self, citation):
|
||||||
note_list = self.get_note_list(citation)
|
note_list = self.get_note_list(citation)
|
||||||
media_list = self.get_media_list(citation)
|
media_list = self.get_media_list(citation)
|
||||||
attribute_list = self.get_citation_attribute_list(citation)
|
attribute_list = self.get_citation_attribute_list(citation)
|
||||||
|
tag_list = self.get_tag_list(citation)
|
||||||
date = self.get_date(citation)
|
date = self.get_date(citation)
|
||||||
# I guess citations can have no source
|
# I guess citations can have no source
|
||||||
if citation.source:
|
if citation.source:
|
||||||
@ -406,6 +417,7 @@ class DjangoInterface(object):
|
|||||||
media_list,
|
media_list,
|
||||||
attribute_list,
|
attribute_list,
|
||||||
totime(citation.last_changed),
|
totime(citation.last_changed),
|
||||||
|
tag_list,
|
||||||
citation.private)
|
citation.private)
|
||||||
|
|
||||||
def get_source(self, source):
|
def get_source(self, source):
|
||||||
@ -413,6 +425,7 @@ class DjangoInterface(object):
|
|||||||
media_list = self.get_media_list(source)
|
media_list = self.get_media_list(source)
|
||||||
attribute_list = self.get_source_attribute_list(source)
|
attribute_list = self.get_source_attribute_list(source)
|
||||||
reporef_list = self.get_repository_ref_list(source)
|
reporef_list = self.get_repository_ref_list(source)
|
||||||
|
tag_list = self.get_tag_list(source)
|
||||||
return (str(source.handle),
|
return (str(source.handle),
|
||||||
source.gramps_id,
|
source.gramps_id,
|
||||||
source.title,
|
source.title,
|
||||||
@ -424,24 +437,27 @@ class DjangoInterface(object):
|
|||||||
totime(source.last_changed),
|
totime(source.last_changed),
|
||||||
attribute_list,
|
attribute_list,
|
||||||
reporef_list,
|
reporef_list,
|
||||||
|
tag_list,
|
||||||
source.private)
|
source.private)
|
||||||
|
|
||||||
def get_media(self, media):
|
def get_media(self, media):
|
||||||
attribute_list = self.get_attribute_list(media)
|
attribute_list = self.get_attribute_list(media)
|
||||||
citation_list = self.get_citation_list(media)
|
citation_list = self.get_citation_list(media)
|
||||||
note_list = self.get_note_list(media)
|
note_list = self.get_note_list(media)
|
||||||
|
tag_list = self.get_tag_list(media)
|
||||||
date = self.get_date(media)
|
date = self.get_date(media)
|
||||||
return (str(media.handle),
|
return (str(media.handle),
|
||||||
media.gramps_id,
|
media.gramps_id,
|
||||||
fix_encoding(media.path),
|
fix_encoding(media.path),
|
||||||
str(media.mime),
|
str(media.mime),
|
||||||
fix_encoding(media.desc),
|
fix_encoding(media.desc),
|
||||||
|
int(media.checksum) if media.checksum else 0,
|
||||||
attribute_list,
|
attribute_list,
|
||||||
citation_list,
|
citation_list,
|
||||||
note_list,
|
note_list,
|
||||||
totime(media.last_changed),
|
totime(media.last_changed),
|
||||||
date,
|
date,
|
||||||
tuple(media.make_tag_list()),
|
tag_list,
|
||||||
media.private)
|
media.private)
|
||||||
|
|
||||||
def get_person(self, person):
|
def get_person(self, person):
|
||||||
@ -461,6 +477,7 @@ class DjangoInterface(object):
|
|||||||
# This looks up the events for the first EventType given:
|
# This looks up the events for the first EventType given:
|
||||||
death_ref_index = person.death_ref_index
|
death_ref_index = person.death_ref_index
|
||||||
birth_ref_index = person.birth_ref_index
|
birth_ref_index = person.birth_ref_index
|
||||||
|
tag_list = self.get_tag_list(person)
|
||||||
|
|
||||||
return (str(person.handle),
|
return (str(person.handle),
|
||||||
person.gramps_id,
|
person.gramps_id,
|
||||||
@ -480,7 +497,7 @@ class DjangoInterface(object):
|
|||||||
pcitation_list,
|
pcitation_list,
|
||||||
pnote_list,
|
pnote_list,
|
||||||
totime(person.last_changed),
|
totime(person.last_changed),
|
||||||
tuple(person.make_tag_list()),
|
tag_list,
|
||||||
person.private,
|
person.private,
|
||||||
person_ref_list)
|
person_ref_list)
|
||||||
|
|
||||||
@ -512,6 +529,7 @@ class DjangoInterface(object):
|
|||||||
media_list = self.get_media_list(place)
|
media_list = self.get_media_list(place)
|
||||||
citation_list = self.get_citation_list(place)
|
citation_list = self.get_citation_list(place)
|
||||||
note_list = self.get_note_list(place)
|
note_list = self.get_note_list(place)
|
||||||
|
tag_list = self.get_tag_list(place)
|
||||||
return (str(place.handle),
|
return (str(place.handle),
|
||||||
place.gramps_id,
|
place.gramps_id,
|
||||||
place.title,
|
place.title,
|
||||||
@ -524,6 +542,7 @@ class DjangoInterface(object):
|
|||||||
citation_list,
|
citation_list,
|
||||||
note_list,
|
note_list,
|
||||||
totime(place.last_changed),
|
totime(place.last_changed),
|
||||||
|
tag_list,
|
||||||
place.private)
|
place.private)
|
||||||
|
|
||||||
# ---------------------------------
|
# ---------------------------------
|
||||||
@ -597,8 +616,10 @@ class DjangoInterface(object):
|
|||||||
attribute_list = self.get_citation_attribute_list(citation)
|
attribute_list = self.get_citation_attribute_list(citation)
|
||||||
changed = totime(citation.last_changed)
|
changed = totime(citation.last_changed)
|
||||||
private = citation.private
|
private = citation.private
|
||||||
|
tag_list = self.get_tag_list(citation)
|
||||||
return (handle, gid, date, page, confidence, source_handle,
|
return (handle, gid, date, page, confidence, source_handle,
|
||||||
note_list, media_list, attribute_list, changed, private)
|
note_list, media_list, attribute_list, changed, tag_list,
|
||||||
|
private)
|
||||||
|
|
||||||
def pack_address(self, address, with_parish):
|
def pack_address(self, address, with_parish):
|
||||||
citation_list = self.get_citation_list(address)
|
citation_list = self.get_citation_list(address)
|
||||||
@ -631,6 +652,7 @@ class DjangoInterface(object):
|
|||||||
media_list = self.get_media_list(source)
|
media_list = self.get_media_list(source)
|
||||||
reporef_list = self.get_repository_ref_list(source)
|
reporef_list = self.get_repository_ref_list(source)
|
||||||
attribute_list = self.get_source_attribute_list(source)
|
attribute_list = self.get_source_attribute_list(source)
|
||||||
|
tag_list = self.get_tag_list(source)
|
||||||
return (source.handle, source.gramps_id, source.title,
|
return (source.handle, source.gramps_id, source.title,
|
||||||
source.author, source.pubinfo,
|
source.author, source.pubinfo,
|
||||||
note_list,
|
note_list,
|
||||||
@ -638,6 +660,7 @@ class DjangoInterface(object):
|
|||||||
source.abbrev,
|
source.abbrev,
|
||||||
totime(last_changed), attribute_list,
|
totime(last_changed), attribute_list,
|
||||||
reporef_list,
|
reporef_list,
|
||||||
|
tag_list,
|
||||||
source.private)
|
source.private)
|
||||||
|
|
||||||
def pack_name(self, name):
|
def pack_name(self, name):
|
||||||
|
@ -28,6 +28,8 @@ from __future__ import print_function
|
|||||||
from gramps.gen.dbstate import DbState
|
from gramps.gen.dbstate import DbState
|
||||||
from gramps.cli.grampscli import CLIManager
|
from gramps.cli.grampscli import CLIManager
|
||||||
from gramps.gen.plug import BasePluginManager
|
from gramps.gen.plug import BasePluginManager
|
||||||
|
from gramps.cli.user import User as GUser # gramps user
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -49,7 +51,7 @@ def get_plugin_options(db, pid):
|
|||||||
Get the default options and help for this plugin.
|
Get the default options and help for this plugin.
|
||||||
"""
|
"""
|
||||||
dbstate = DbState()
|
dbstate = DbState()
|
||||||
climanager = CLIManager(dbstate, False) # do not load db_loader
|
climanager = CLIManager(dbstate, setloader=False, user=GUser()) # do not load db_loader
|
||||||
climanager.do_reg_plugins(dbstate, None)
|
climanager.do_reg_plugins(dbstate, None)
|
||||||
pmgr = BasePluginManager.get_instance()
|
pmgr = BasePluginManager.get_instance()
|
||||||
pdata = pmgr.get_plugin(pid)
|
pdata = pmgr.get_plugin(pid)
|
||||||
@ -70,7 +72,7 @@ def import_file(db, filename, user):
|
|||||||
"""
|
"""
|
||||||
from .grampsdb.models import Person
|
from .grampsdb.models import Person
|
||||||
dbstate = DbState()
|
dbstate = DbState()
|
||||||
climanager = CLIManager(dbstate, False) # do not load db_loader
|
climanager = CLIManager(dbstate, setloader=False, user=user) # do not load db_loader
|
||||||
climanager.do_reg_plugins(dbstate, None)
|
climanager.do_reg_plugins(dbstate, None)
|
||||||
pmgr = BasePluginManager.get_instance()
|
pmgr = BasePluginManager.get_instance()
|
||||||
(name, ext) = os.path.splitext(os.path.basename(filename))
|
(name, ext) = os.path.splitext(os.path.basename(filename))
|
||||||
@ -133,7 +135,7 @@ def export_file(db, filename, user):
|
|||||||
>>> export_file(DbDjango(), "/home/user/Untitled_1.ged", User())
|
>>> export_file(DbDjango(), "/home/user/Untitled_1.ged", User())
|
||||||
"""
|
"""
|
||||||
dbstate = DbState()
|
dbstate = DbState()
|
||||||
climanager = CLIManager(dbstate, False) # do not load db_loader
|
climanager = CLIManager(dbstate, setloader=False, user=user) # do not load db_loader
|
||||||
climanager.do_reg_plugins(dbstate, None)
|
climanager.do_reg_plugins(dbstate, None)
|
||||||
pmgr = BasePluginManager.get_instance()
|
pmgr = BasePluginManager.get_instance()
|
||||||
(name, ext) = os.path.splitext(os.path.basename(filename))
|
(name, ext) = os.path.splitext(os.path.basename(filename))
|
||||||
|
1
gramps/webapp/shell.sh
Executable file
1
gramps/webapp/shell.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
PYTHONPATH=../.. python -i shell.py
|
Loading…
Reference in New Issue
Block a user