First stage to bringing gramps-connect back into sync: surnames, locality in places, and marker/tag changes

svn: r16670
This commit is contained in:
Doug Blank 2011-02-18 23:58:10 +00:00
parent b31486025c
commit 90aaf57238
5 changed files with 106 additions and 75 deletions

View File

@ -27,11 +27,10 @@ docs:
python manage.py graph_models grampsdb -i Family -o docs/family-table.png
python manage.py graph_models grampsdb -i Person -o docs/person-table.png
python manage.py graph_models grampsdb -o docs/all-tables.png
python manage.py graph_models grampsdb -i Attribute,Datamap,Name,Lds,Markup,Address,Location,Url -o docs/secondary-tables.png
python manage.py graph_models grampsdb -i Person,Family,Source,Event,Repository,Place,Media,Note,Attribute,Datamap,Name,Lds,Markup,Address,Location,Url -o docs/prim-sec-tables.png
python manage.py graph_models grampsdb -i Person,Family,Source,Event,Repository,Place,Media,Note,Attribute,Datamap,Name,Lds,Markup,Address,Location,Url -o docs/prim-sec-tables.png
python manage.py graph_models grampsdb -i Person,Family,Source,Event,Repository,Place,Media,Note,Attribute,Datamap,Name,Lds,Markup,Address,Location,Url,NoteRef,SourceRef,EventRef,RepositoryRef,PersonRef,ChildRef,MediaRef -o docs/prim-sec-ref-tables.png
python manage.py graph_models grampsdb -i Attribute,Datamap,Name,Lds,Tag,Address,Location,Url -o docs/secondary-tables.png
python manage.py graph_models grampsdb -i Person,Family,Source,Event,Repository,Place,Media,Note,Attribute,Datamap,Name,Lds,Tag,Address,Location,Url -o docs/prim-sec-tables.png
python manage.py graph_models grampsdb -i Person,Family,Source,Event,Repository,Place,Media,Note,Attribute,Datamap,Name,Lds,Tag,Address,Location,Url -o docs/prim-sec-tables.png
python manage.py graph_models grampsdb -i Person,Family,Source,Event,Repository,Place,Media,Note,Attribute,Datamap,Name,Lds,Tag,Address,Location,Url,NoteRef,SourceRef,EventRef,RepositoryRef,PersonRef,ChildRef,MediaRef -o docs/prim-sec-ref-tables.png
clean:
rm -f sqlite.db

View File

@ -110,13 +110,6 @@ class mGrampsType(models.Model):
else:
raise IndexError("type index is out of range (use 0 or 1)")
class MarkerType(mGrampsType):
from gen.lib.markertype import MarkerType
_DATAMAP = get_datamap(MarkerType)
_CUSTOM = MarkerType._CUSTOM
_DEFAULT = _DATAMAP[MarkerType._DEFAULT]
val = models.IntegerField('marker', choices=_DATAMAP, blank=False)
class NameType(mGrampsType):
from gen.lib.nametype import NameType
_DATAMAP = get_datamap(NameType)
@ -124,6 +117,13 @@ class NameType(mGrampsType):
_DEFAULT = _DATAMAP[NameType._DEFAULT]
val = models.IntegerField('name type', choices=_DATAMAP, blank=False)
class NameOriginType(mGrampsType):
from gen.lib.nameorigintype import NameOriginType
_DATAMAP = get_datamap(NameOriginType)
_CUSTOM = NameOriginType._CUSTOM
_DEFAULT = _DATAMAP[NameOriginType._DEFAULT]
val = models.IntegerField('name origin type', choices=_DATAMAP, blank=False)
class AttributeType(mGrampsType):
from gen.lib.attrtype import AttributeType
_DATAMAP = get_datamap(AttributeType)
@ -381,6 +381,22 @@ class Config(models.Model):
value_type = models.CharField('type of value', max_length=25)
value = models.TextField('value')
class Tag(models.Model):
handle = models.CharField(max_length=19, unique=True)
last_saved = models.DateTimeField('last changed', auto_now=True)
last_changed = models.DateTimeField('last changed', null=True,
blank=True) # user edits
name = models.TextField('name')
color = models.CharField(max_length=13) # "#000000000000" # Black
priority = models.IntegerField('priority', blank=False)
# Just the following have tag lists:
# ---------------------------------
#src/gen/lib/family.py
#src/gen/lib/mediaobj.py
#src/gen/lib/note.py
#src/gen/lib/person.py
class PrimaryObject(models.Model):
"""
Common attribute of all primary objects with key on the handle
@ -397,9 +413,6 @@ class PrimaryObject(models.Model):
private = models.BooleanField('private')
#attributes = models.ManyToManyField("Attribute", blank=True, null=True)
## Keys:
marker_type = models.ForeignKey('MarkerType')
def __unicode__(self): return "%s: %s" % (self.__class__.__name__,
self.gramps_id)
@ -420,6 +433,8 @@ class Person(PrimaryObject):
birth = models.ForeignKey("Event", related_name="birth", blank=True, null=True)
death = models.ForeignKey("Event", related_name="death", blank=True, null=True)
tags = models.ManyToManyField('Tag', blank=True, null=True)
# Others keys here:
# .name_set
# .address_set
@ -438,6 +453,8 @@ class Family(PrimaryObject):
mother = models.ForeignKey('Person', related_name="mother_ref",
null=True, blank=True)
family_rel_type = models.ForeignKey('FamilyRelType')
tags = models.ManyToManyField('Tag', blank=True, null=True)
#lds_list = models.ManyToManyField('Lds', null=True, blank=True)
# Others keys here:
@ -494,6 +511,7 @@ class Media(DateObject, PrimaryObject):
references = generic.GenericRelation('MediaRef', related_name="refs",
content_type_field="object_type",
object_id_field="object_id")
tags = models.ManyToManyField('Tag', blank=True, null=True)
class Note(PrimaryObject):
note_type = models.ForeignKey('NoteType')
@ -502,6 +520,7 @@ class Note(PrimaryObject):
references = generic.GenericRelation('NoteRef', related_name="refs",
content_type_field="object_type",
object_id_field="object_id")
tags = models.ManyToManyField('Tag', blank=True, null=True)
#---------------------------------------------------------------------------
#
@ -522,13 +541,26 @@ class SecondaryObject(models.Model):
blank=True) # user edits
order = models.PositiveIntegerField(default=1)
class Surname(models.Model):
"""
Surname table, which links to name.
"""
name_origin_type = models.ForeignKey('NameOriginType',
related_name="name_origin_code",
default=2)
surname = models.TextField(blank=True)
prefix = models.TextField(blank=True)
primary = models.BooleanField('Primary surname?')
origintype = NameOriginType()
connector = models.TextField(blank=True)
name = models.ForeignKey("Name")
class Name(DateObject, SecondaryObject):
name_type = models.ForeignKey('NameType',
related_name="name_code",
default=2)
preferred = models.BooleanField('Preferred name?')
first_name = models.TextField(blank=True)
surname = models.TextField(blank=True)
suffix = models.TextField(blank=True)
title = models.TextField(blank=True)
prefix = models.TextField(blank=True)
@ -625,6 +657,7 @@ class Address(DateObject, SecondaryObject):
class Location(models.Model):
street = models.TextField(blank=True)
locality = models.TextField(blank=True)
city = models.TextField(blank=True)
county = models.TextField(blank=True)
state = models.TextField(blank=True)
@ -737,9 +770,8 @@ class MediaRef(BaseRef):
TABLES = [
("abstract", mGrampsType),
("type", MarkerType),
("type", MarkupType),
("type", NameType),
("type", NameOriginType),
("type", NameFormatType),
("type", AttributeType),
("type", UrlType),

View File

@ -31,8 +31,8 @@ import os
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
import settings
from gen.lib.markertype import MarkerType
from gen.lib.nametype import NameType
from gen.lib.nameorigintype import NameOriginType
from gen.lib.attrtype import AttributeType
from gen.lib.urltype import UrlType
from gen.lib.childreftype import ChildRefType
@ -44,7 +44,7 @@ from gen.lib.eventroletype import EventRoleType
from gen.lib.notetype import NoteType
from grampsdb.models import (GenderType, LdsType, LdsStatus,
NameFormatType, ThemeType)
NameFormatType, NameOriginType, ThemeType)
def get_datamap(x):
"""
@ -85,7 +85,7 @@ for table, entries in [("grampsdb.config",
## Add the data for the type models:
type_models = [MarkerType, NameType, AttributeType, UrlType, ChildRefType,
type_models = [NameType, NameOriginType, AttributeType, UrlType, ChildRefType,
RepositoryType, EventType, FamilyRelType, SourceMediaType,
EventRoleType, NoteType, GenderType, LdsType, LdsStatus,
NameFormatType]

View File

@ -253,7 +253,6 @@ class DjangoInterface(object):
the_type = tuple(event.event_type)
description = event.description
change = totime(event.last_changed)
marker = tuple(event.marker_type)
private = event.private
note_list = self.get_note_list(event)
source_list = self.get_source_ref_list(event)
@ -263,7 +262,7 @@ class DjangoInterface(object):
place = self.get_place_handle(event)
return (str(handle), gid, the_type, date, description, place,
source_list, note_list, media_list, attribute_list,
change, marker, private)
change, private)
def get_note(self, note):
styled_text = [note.text, []]
@ -281,7 +280,7 @@ class DjangoInterface(object):
note.preformatted,
tuple(note.note_type),
changed,
tuple(note.marker_type),
tuple(note.tag_list),
note.private)
def get_family(self, family):
@ -307,7 +306,7 @@ class DjangoInterface(object):
attribute_list, lds_seal_list,
source_list, note_list,
totime(family.last_changed),
tuple(family.marker_type),
tuple(family.tag_list),
family.private)
def get_repository(self, repository):
@ -322,7 +321,6 @@ class DjangoInterface(object):
address_list,
url_list,
totime(repository.last_changed),
tuple(repository.marker_type),
repository.private)
def get_source(self, source):
@ -341,7 +339,6 @@ class DjangoInterface(object):
totime(source.last_changed),
datamap,
reporef_list,
tuple(source.marker_type),
source.private)
def get_media(self, media):
@ -359,7 +356,7 @@ class DjangoInterface(object):
note_list,
totime(media.last_changed),
date,
tuple(media.marker_type),
tuple(media.tag_list),
media.private)
def get_person(self, person):
@ -399,7 +396,7 @@ class DjangoInterface(object):
psource_list,
pnote_list,
totime(person.last_changed),
tuple(person.marker_type),
tuple(person.tag_list),
person.private,
person_ref_list)
@ -443,7 +440,6 @@ class DjangoInterface(object):
source_list,
note_list,
totime(place.last_changed),
tuple(place.marker_type),
place.private)
# ---------------------------------
@ -552,23 +548,25 @@ class DjangoInterface(object):
source.abbrev,
totime(last_changed), datamap,
reporef_list,
tuple(source.marker_type), source.private)
source.private)
def pack_name(self, name):
source_list = self.get_source_ref_list(name)
note_list = self.get_note_list(name)
date = self.get_date(name)
return (name.private, source_list, note_list, date,
name.first_name, name.surname, name.suffix, name.title,
tuple(name.name_type), name.prefix, name.patronymic,
name.group_as, name.sort_as.val, name.display_as.val, name.call)
name.first_name, name.surname_list, name.suffix,
name.title, tuple(name.name_type),
name.group_as, name.sort_as.val,
name.display_as.val, name.call, name.nick,
name.famnick)
def pack_location(self, loc, with_parish):
if with_parish:
return ((loc.street, loc.city, loc.county, loc.state, loc.country,
return ((loc.street, loc.locality, loc.city, loc.county, loc.state, loc.country,
loc.postal, loc.phone), loc.parish)
else:
return (loc.street, loc.city, loc.county, loc.state, loc.country,
return (loc.street, loc.locality, loc.city, loc.county, loc.state, loc.country,
loc.postal, loc.phone)
def pack_url(self, url):
@ -966,9 +964,9 @@ class DjangoInterface(object):
def add_name(self, person, data, preferred):
if data:
(private, source_list, note_list, date,
first_name, surname, suffix, title,
name_type, prefix, patronymic,
group_as, sort_as, display_as, call) = data
first_name, surname_list, suffix, title,
name_type, group_as, sort_as,
display_as, call, nick, famnick) = data
count = person.name_set.count()
name = models.Name()
@ -976,16 +974,16 @@ class DjangoInterface(object):
name.preferred = preferred
name.private = private
name.first_name = first_name
name.surname = surname
#name.surname_list = surname_list FIXME
name.suffix = suffix
name.title = title
name.name_type = models.get_type(models.NameType, name_type)
name.prefix = prefix
name.patronymic = patronymic
name.group_as = group_as
name.sort_as = models.get_type(models.NameFormatType, sort_as)
name.display_as = models.get_type(models.NameFormatType, display_as)
name.call = call
name.nick = nick
name.famnick = famnick
# we know person exists
# needs to have an ID for key
name.person = person
@ -1017,7 +1015,7 @@ class DjangoInterface(object):
psource_list, # 15
pnote_list, # 16
change, # 17
marker, # 18
tag_list, # 18
private, # 19
person_ref_list, # 20
) = data
@ -1026,8 +1024,7 @@ class DjangoInterface(object):
gramps_id=gid,
last_changed=todate(change),
private=private,
marker_type = models.get_type(models.MarkerType, marker),
gender_type = models.get_type(models.GenderType, gender))
gender_type=models.get_type(models.GenderType, gender))
person.save()
def add_person_detail(self, data):
@ -1050,7 +1047,7 @@ class DjangoInterface(object):
psource_list, # 15
pnote_list, # 16
change, # 17
marker, # 18
tag_list, # 18
private, # 19
person_ref_list, # 20
) = data
@ -1102,7 +1099,7 @@ class DjangoInterface(object):
def add_note(self, data):
# Unpack from the BSDDB:
(handle, gid, styled_text, format, note_type,
change, marker, private) = data
change, tag_list, private) = data
text, markup_list = styled_text
n = models.Note(handle=handle,
gramps_id=gid,
@ -1110,8 +1107,7 @@ class DjangoInterface(object):
private=private,
preformatted=format,
text=text,
marker_type = models.get_type(models.MarkerType, marker),
note_type = models.get_type(models.NoteType, note_type))
note_type=models.get_type(models.NoteType, note_type))
n.save()
count = 1
for markup in markup_list:
@ -1129,12 +1125,11 @@ class DjangoInterface(object):
(handle, gid, father_handle, mother_handle,
child_ref_list, the_type, event_ref_list, media_list,
attribute_list, lds_seal_list, source_list, note_list,
change, marker, private) = data
change, tag_list, private) = data
family = models.Family(handle=handle, gramps_id=gid,
family_rel_type = models.get_type(models.FamilyRelType, the_type),
last_changed=todate(change),
marker_type = models.get_type(models.MarkerType, marker),
private=private)
family.save()
@ -1143,7 +1138,7 @@ class DjangoInterface(object):
(handle, gid, father_handle, mother_handle,
child_ref_list, the_type, event_ref_list, media_list,
attribute_list, lds_seal_list, source_list, note_list,
change, marker, private) = data
change, tag_list, private) = data
try:
family = models.Family.objects.get(handle=handle)
@ -1183,11 +1178,10 @@ class DjangoInterface(object):
abbrev,
change, datamap,
reporef_list,
marker, private) = data
private) = data
source = models.Source(handle=handle, gramps_id=gid, title=title,
author=author, pubinfo=pubinfo, abbrev=abbrev,
last_changed=todate(change), private=private)
source.marker_type = models.get_type(models.MarkerType, marker)
source.save()
def add_source_detail(self, data):
@ -1198,7 +1192,7 @@ class DjangoInterface(object):
abbrev,
change, datamap,
reporef_list,
marker, private) = data
private) = data
try:
source = models.Source.objects.get(handle=handle)
except:
@ -1212,11 +1206,10 @@ class DjangoInterface(object):
def add_repository(self, data):
(handle, gid, the_type, name, note_list,
address_list, url_list, change, marker, private) = data
address_list, url_list, change, private) = data
repository = models.Repository(handle=handle,
gramps_id=gid,
marker_type=models.get_type(models.MarkerType, marker),
last_changed=todate(change),
private=private,
repository_type=models.get_type(models.RepositoryType, the_type),
@ -1225,7 +1218,7 @@ class DjangoInterface(object):
def add_repository_detail(self, data):
(handle, gid, the_type, name, note_list,
address_list, url_list, change, marker, private) = data
address_list, url_list, change, private) = data
try:
repository = models.Repository.objects.get(handle=handle)
except:
@ -1237,18 +1230,23 @@ class DjangoInterface(object):
self.add_address_list("repository", repository, address_list)
def add_location(self, field, obj, location_data, order):
# location now has 8 items
# street, locality, city, county, state,
# country, postal, phone, parish
if location_data == None: return
if len(location_data) == 7:
(street, city, county, state, country, postal, phone) = location_data
if len(location_data) == 8:
(street, locality, city, county, state, country, postal, phone) = location_data
parish = None
elif len(location_data) == 2:
((street, city, county, state, country, postal, phone), parish) = location_data
((street, locality, city, county, state, country, postal, phone), parish) = location_data
else:
print >> sys.stderr, ("ERROR: unknown location: '%s'" %
location_data)
(street, city, county, state, country, postal, phone, parish) = \
("", "", "", "", "", "", "", "")
(street, locality, city, county, state, country, postal, phone, parish) = \
("", "", "", "", "", "", "", "", "")
location = models.Location(street = street,
locality = locality,
city = city,
county = county,
state = state,
@ -1275,10 +1273,9 @@ class DjangoInterface(object):
media_list,
source_list,
note_list,
change, marker, private) = data
change, private) = data
place = models.Place(handle=handle, gramps_id=gid, title=title,
long=long, lat=lat, last_changed=todate(change),
marker_type=models.get_type(models.MarkerType, marker),
private=private)
place.save()
@ -1289,7 +1286,7 @@ class DjangoInterface(object):
media_list,
source_list,
note_list,
change, marker, private) = data
change, private) = data
try:
place = models.Place.objects.get(handle=handle)
except:
@ -1313,12 +1310,11 @@ class DjangoInterface(object):
note_list,
change,
date,
marker,
tag_list,
private) = data
media = models.Media(handle=handle, gramps_id=gid,
path=path, mime=mime,
desc=desc, last_changed=todate(change),
marker_type=models.get_type(models.MarkerType, marker),
private=private)
self.add_date(media, date)
media.save()
@ -1330,7 +1326,7 @@ class DjangoInterface(object):
note_list,
change,
date,
marker,
tag_list,
private) = data
try:
media = models.Media.objects.get(handle=handle)
@ -1345,12 +1341,11 @@ class DjangoInterface(object):
def add_event(self, data):
(handle, gid, the_type, date, description, place_handle,
source_list, note_list, media_list, attribute_list,
change, marker, private) = data
change, private) = data
event = models.Event(handle=handle,
gramps_id=gid,
event_type=models.get_type(models.EventType, the_type),
private=private,
marker_type=models.get_type(models.MarkerType, marker),
description=description,
last_changed=todate(change))
self.add_date(event, date)
@ -1359,7 +1354,7 @@ class DjangoInterface(object):
def add_event_detail(self, data):
(handle, gid, the_type, date, description, place_handle,
source_list, note_list, media_list, attribute_list,
change, marker, private) = data
change, private) = data
try:
event = models.Event.objects.get(handle=handle)
except:

View File

@ -537,11 +537,15 @@ def render_name(name, user):
if isinstance(name, models.Name):
if not user.is_authenticated():
name.sanitize()
return "%s, %s" % (name.surname, name.first_name)
# FIXME: get primary surname
#return "%s, %s" % (name.surname, name.first_name)
return "%s, %s" % ("FIXME", name.first_name)
elif isinstance(name, forms.NameForm):
if not user.is_authenticated():
name.model.sanitize()
return "%s, %s" % (name.model.surname, name.model.first_name)
# FIXME: get primary surname
#return "%s, %s" % (name.model.surname, name.model.first_name)
return "%s, %s" % ("FIXME", name.model.first_name)
elif isinstance(name, gen.lib.Person): # name is a gen.lib.Person
person = name
try:
@ -552,7 +556,8 @@ def render_name(name, user):
return "[No preferred name]"
if not user.is_authenticated():
name.sanitize()
return "%s, %s" % (name.surname, name.first_name)
#return "%s, %s" % (name.surname, name.first_name)
return "%s, %s" % ("FIXME", name.first_name)
elif isinstance(name, models.Person): # django person
person = name
try: