Fix dbdjango to be up to date with bsddb of gramps40: added checksum for Media; SourceAttribute and CitationAttribute gained a private flag; all primary objects got tags

svn: r22944
This commit is contained in:
Doug Blank 2013-08-29 19:11:30 +00:00
parent 3d30663a5c
commit eab69c44ac
4 changed files with 67 additions and 49 deletions

View File

@ -628,6 +628,7 @@ class Media(DateObject, PrimaryObject):
path = models.TextField(blank=True) path = models.TextField(blank=True)
mime = models.TextField(blank=True, null=True) mime = models.TextField(blank=True, null=True)
desc = models.TextField("Title", blank=True) desc = models.TextField("Title", blank=True)
checksum = models.TextField(blank=True)
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")
@ -803,16 +804,18 @@ class Markup(models.Model):
string = models.TextField(blank=True, null=True) string = models.TextField(blank=True, null=True)
start_stop_list = models.TextField(default="[]") start_stop_list = models.TextField(default="[]")
class SourceDatamap(models.Model): class SourceAttribute(models.Model):
key = models.CharField(max_length=80, blank=True) key = models.CharField(max_length=80, blank=True)
value = models.CharField(max_length=80, blank=True) value = models.CharField(max_length=80, blank=True)
source = models.ForeignKey("Source") source = models.ForeignKey("Source")
private = models.BooleanField()
order = models.PositiveIntegerField() order = models.PositiveIntegerField()
class CitationDatamap(models.Model): class CitationAttribute(models.Model):
key = models.CharField(max_length=80, blank=True) key = models.CharField(max_length=80, blank=True)
value = models.CharField(max_length=80, blank=True) value = models.CharField(max_length=80, blank=True)
citation = models.ForeignKey("Citation") citation = models.ForeignKey("Citation")
private = models.BooleanField()
order = models.PositiveIntegerField() order = models.PositiveIntegerField()
class Address(DateObject, SecondaryObject): class Address(DateObject, SecondaryObject):
@ -1043,8 +1046,8 @@ TABLES = [
("primary", Tag), ("primary", Tag),
("abstract", SecondaryObject), ("abstract", SecondaryObject),
("secondary", Attribute), ("secondary", Attribute),
("secondary", SourceDatamap), ("secondary", SourceAttribute),
("secondary", CitationDatamap), ("secondary", CitationAttribute),
("secondary", Name), ("secondary", Name),
("secondary", Surname), ("secondary", Surname),
("secondary", Lds), ("secondary", Lds),

View File

@ -216,11 +216,11 @@ class DjangoInterface(object):
else: else:
return list(map(self.pack_name, names)) return list(map(self.pack_name, names))
def get_source_datamap(self, source): def get_source_attribute(self, source):
return dict([map.key, map.value] for map in source.sourcedatamap_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_datamap(self, citation): def get_citation_attribute(self, citation):
return dict([map.key, map.value] for map in citation.citationdatamap_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):
obj_type = ContentType.objects.get_for_model(obj) obj_type = ContentType.objects.get_for_model(obj)
@ -389,7 +389,7 @@ class DjangoInterface(object):
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)
datamap = self.get_citation_datamap(citation) attribute_list = self.get_citation_attribute_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:
@ -404,14 +404,14 @@ class DjangoInterface(object):
handle, handle,
note_list, note_list,
media_list, media_list,
datamap, attribute_list,
totime(citation.last_changed), totime(citation.last_changed),
citation.private) citation.private)
def get_source(self, source): def get_source(self, source):
note_list = self.get_note_list(source) note_list = self.get_note_list(source)
media_list = self.get_media_list(source) media_list = self.get_media_list(source)
datamap = self.get_source_datamap(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)
return (str(source.handle), return (str(source.handle),
source.gramps_id, source.gramps_id,
@ -422,7 +422,7 @@ class DjangoInterface(object):
media_list, media_list,
source.abbrev, source.abbrev,
totime(source.last_changed), totime(source.last_changed),
datamap, attribute_list,
reporef_list, reporef_list,
source.private) source.private)
@ -594,11 +594,11 @@ class DjangoInterface(object):
source_handle = citation.source.handle source_handle = citation.source.handle
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)
datamap = self.get_citation_datamap(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
return (handle, gid, date, page, confidence, source_handle, return (handle, gid, date, page, confidence, source_handle,
note_list, media_list, datamap, changed, private) note_list, media_list, attribute_list, changed, 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)
@ -630,13 +630,13 @@ class DjangoInterface(object):
note_list = self.get_note_list(source) note_list = self.get_note_list(source)
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)
datamap = self.get_source_datamap(source) attribute_list = self.get_source_attribute_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,
media_list, media_list,
source.abbrev, source.abbrev,
totime(last_changed), datamap, totime(last_changed), attribute_list,
reporef_list, reporef_list,
source.private) source.private)
@ -881,7 +881,7 @@ class DjangoInterface(object):
def add_citation(self, citation_data): def add_citation(self, citation_data):
(handle, gid, date, page, confidence, source_handle, note_list, (handle, gid, date, page, confidence, source_handle, note_list,
media_list, datamap, changed, private) = citation_data media_list, attribute_list, changed, tag_list, private) = citation_data
citation = models.Citation( citation = models.Citation(
handle=handle, handle=handle,
gramps_id=gid, gramps_id=gid,
@ -893,7 +893,7 @@ class DjangoInterface(object):
def add_citation_detail(self, citation_data): def add_citation_detail(self, citation_data):
(handle, gid, date, page, confidence, source_handle, note_list, (handle, gid, date, page, confidence, source_handle, note_list,
media_list, datamap, change, private) = citation_data media_list, attribute_list, change, tag_list, private) = citation_data
try: try:
citation = models.Citation.objects.get(handle=handle) citation = models.Citation.objects.get(handle=handle)
except: except:
@ -912,7 +912,8 @@ class DjangoInterface(object):
citation.save() citation.save()
self.add_note_list(citation, note_list) self.add_note_list(citation, note_list)
self.add_media_ref_list(citation, media_list) self.add_media_ref_list(citation, media_list)
self.add_citation_datamap_dict(citation, datamap) self.add_citation_attribute_list(citation, attribute_list)
self.add_tag_list(citation, tag_list)
def add_child_ref_default(self, obj, child, frel=1, mrel=1, private=False): def add_child_ref_default(self, obj, child, frel=1, mrel=1, private=False):
object_type = ContentType.objects.get_for_model(obj) # obj is family object_type = ContentType.objects.get_for_model(obj) # obj is family
@ -1026,23 +1027,25 @@ class DjangoInterface(object):
## Export individual objects: ## Export individual objects:
def add_source_datamap_dict(self, source, datamap_dict): def add_source_attribute_list(self, source, attribute_list):
## FIXME: dict to list
count = 1 count = 1
for key in datamap_dict: #for key in datamap_dict:
value = datamap_dict[key] # value = datamap_dict[key]
datamap = models.SourceDatamap(key=key, value=value, order=count) # datamap = models.SourceDatamap(key=key, value=value, order=count)
datamap.source = source # datamap.source = source
datamap.save() # datamap.save()
count += 1 # count += 1
def add_citation_datamap_dict(self, citation, datamap_dict): def add_citation_attribute_list(self, citation, attribute_list):
## FIXME: dict to list
count = 1 count = 1
for key in datamap_dict: #for key in datamap_dict:
value = datamap_dict[key] # value = datamap_dict[key]
datamap = models.CitationDatamap(key=key, value=value, order=count) # datamap = models.CitationDatamap(key=key, value=value, order=count)
datamap.citation = citation # datamap.citation = citation
datamap.save() # datamap.save()
count += 1 # count += 1
def add_lds(self, field, obj, data, order): def add_lds(self, field, obj, data, order):
(lcitation_list, lnote_list, date, type, place_handle, (lcitation_list, lnote_list, date, type, place_handle,
@ -1430,8 +1433,9 @@ class DjangoInterface(object):
note_list, note_list,
media_list, media_list,
abbrev, abbrev,
change, datamap, change, attribute_list,
reporef_list, reporef_list,
tag_list,
private) = data private) = data
source = models.Source(handle=handle, gramps_id=gid, title=title, source = models.Source(handle=handle, gramps_id=gid, title=title,
author=author, pubinfo=pubinfo, abbrev=abbrev, author=author, pubinfo=pubinfo, abbrev=abbrev,
@ -1445,8 +1449,9 @@ class DjangoInterface(object):
note_list, note_list,
media_list, media_list,
abbrev, abbrev,
change, datamap, change, attribute_list,
reporef_list, reporef_list,
tag_list,
private) = data private) = data
try: try:
source = models.Source.objects.get(handle=handle) source = models.Source.objects.get(handle=handle)
@ -1458,12 +1463,13 @@ class DjangoInterface(object):
source.save() source.save()
self.add_note_list(source, note_list) self.add_note_list(source, note_list)
self.add_media_ref_list(source, media_list) self.add_media_ref_list(source, media_list)
self.add_source_datamap_dict(source, datamap) self.add_source_attribute_list(source, attribute_list)
self.add_repository_ref_list(source, reporef_list) self.add_repository_ref_list(source, reporef_list)
self.add_tag_list(source, tag_list)
def add_repository(self, data): def add_repository(self, data):
(handle, gid, the_type, name, note_list, (handle, gid, the_type, name, note_list,
address_list, url_list, change, private) = data address_list, url_list, change, tag_list, private) = data
repository = models.Repository(handle=handle, repository = models.Repository(handle=handle,
gramps_id=gid, gramps_id=gid,
@ -1476,7 +1482,7 @@ class DjangoInterface(object):
def add_repository_detail(self, data): def add_repository_detail(self, data):
(handle, gid, the_type, name, note_list, (handle, gid, the_type, name, note_list,
address_list, url_list, change, private) = data address_list, url_list, change, tag_list, private) = data
try: try:
repository = models.Repository.objects.get(handle=handle) repository = models.Repository.objects.get(handle=handle)
except: except:
@ -1488,6 +1494,7 @@ class DjangoInterface(object):
self.add_note_list(repository, note_list) self.add_note_list(repository, note_list)
self.add_url_list("repository", repository, url_list) self.add_url_list("repository", repository, url_list)
self.add_address_list("repository", repository, address_list) self.add_address_list("repository", repository, address_list)
self.add_tag_list(repository, tag_list)
def add_location(self, field, obj, location_data, order): def add_location(self, field, obj, location_data, order):
# location now has 8 items # location now has 8 items
@ -1533,7 +1540,9 @@ class DjangoInterface(object):
media_list, media_list,
citation_list, citation_list,
note_list, note_list,
change, private) = data change,
tag_list,
private) = data
place = models.Place(handle=handle, gramps_id=gid, title=title, place = models.Place(handle=handle, gramps_id=gid, title=title,
long=long, lat=lat, last_changed=todate(change), long=long, lat=lat, last_changed=todate(change),
private=private) private=private)
@ -1547,7 +1556,9 @@ class DjangoInterface(object):
media_list, media_list,
citation_list, citation_list,
note_list, note_list,
change, private) = data change,
tag_list,
private) = data
try: try:
place = models.Place.objects.get(handle=handle) place = models.Place.objects.get(handle=handle)
except: except:
@ -1560,6 +1571,7 @@ class DjangoInterface(object):
self.add_media_ref_list(place, media_list) self.add_media_ref_list(place, media_list)
self.add_citation_list(place, citation_list) self.add_citation_list(place, citation_list)
self.add_note_list(place, note_list) self.add_note_list(place, note_list)
self.add_tag_list(place, tag_list)
self.add_location("place", place, main_loc, 1) self.add_location("place", place, main_loc, 1)
count = 2 count = 2
for loc_data in alt_location_list: for loc_data in alt_location_list:
@ -1592,6 +1604,7 @@ class DjangoInterface(object):
def add_media(self, data): def add_media(self, data):
(handle, gid, path, mime, desc, (handle, gid, path, mime, desc,
checksum,
attribute_list, attribute_list,
citation_list, citation_list,
note_list, note_list,
@ -1600,7 +1613,7 @@ class DjangoInterface(object):
tag_list, tag_list,
private) = data private) = data
media = models.Media(handle=handle, gramps_id=gid, media = models.Media(handle=handle, gramps_id=gid,
path=path, mime=mime, path=path, mime=mime, checksum=checksum,
desc=desc, last_changed=todate(change), desc=desc, last_changed=todate(change),
private=private) private=private)
#media.cache = base64.encodestring(cPickle.dumps(data)) #media.cache = base64.encodestring(cPickle.dumps(data))
@ -1609,6 +1622,7 @@ class DjangoInterface(object):
def add_media_detail(self, data): def add_media_detail(self, data):
(handle, gid, path, mime, desc, (handle, gid, path, mime, desc,
checksum,
attribute_list, attribute_list,
citation_list, citation_list,
note_list, note_list,
@ -1632,7 +1646,7 @@ class DjangoInterface(object):
def add_event(self, data): def add_event(self, data):
(handle, gid, the_type, date, description, place_handle, (handle, gid, the_type, date, description, place_handle,
citation_list, note_list, media_list, attribute_list, citation_list, note_list, media_list, attribute_list,
change, private) = data change, tag_list, private) = data
event = models.Event(handle=handle, event = models.Event(handle=handle,
gramps_id=gid, gramps_id=gid,
event_type=models.get_type(models.EventType, the_type), event_type=models.get_type(models.EventType, the_type),
@ -1646,7 +1660,7 @@ class DjangoInterface(object):
def add_event_detail(self, data): def add_event_detail(self, data):
(handle, gid, the_type, date, description, place_handle, (handle, gid, the_type, date, description, place_handle,
citation_list, note_list, media_list, attribute_list, citation_list, note_list, media_list, attribute_list,
change, private) = data change, tag_list, private) = data
try: try:
event = models.Event.objects.get(handle=handle) event = models.Event.objects.get(handle=handle)
except: except:
@ -1660,6 +1674,7 @@ class DjangoInterface(object):
self.add_attribute_list(event, attribute_list) self.add_attribute_list(event, attribute_list)
self.add_media_ref_list(event, media_list) self.add_media_ref_list(event, media_list)
self.add_citation_list(event, citation_list) self.add_citation_list(event, citation_list)
self.add_tag_list(event, tag_list)
def get_raw(self, item): def get_raw(self, item):
""" """

View File

@ -147,6 +147,6 @@ FORMAT_MODULE_PATH = ""
## End Changes for Django 1.3 ## End Changes for Django 1.3
# Changes for Django 1.4: # Changes for Django 1.4:
USE_TZ = True USE_TZ = False
## End Changes for Django 1.4 ## End Changes for Django 1.4

View File

@ -708,9 +708,9 @@ def data_table(obj, user, act, url=None, *args):
if user.is_authenticated() or obj.public: if user.is_authenticated() or obj.public:
item_class = obj.__class__.__name__.lower() item_class = obj.__class__.__name__.lower()
if item_class == "citation": if item_class == "citation":
refs = models.CitationDatamap.objects.filter(citation=obj).order_by("order") refs = models.CitationAttribute.objects.filter(citation=obj).order_by("order")
elif item_class == "source": elif item_class == "source":
refs = models.SourceDatamap.objects.filter(source=obj).order_by("order") refs = models.SourceAttribute.objects.filter(source=obj).order_by("order")
count = 1 count = 1
for ref in refs: for ref in refs:
if item_class == "citation": if item_class == "citation":
@ -729,9 +729,9 @@ def data_table(obj, user, act, url=None, *args):
text = text.replace("}}", """</div>""") text = text.replace("}}", """</div>""")
count = 1 count = 1
for repo_ref in refs: for repo_ref in refs:
text = text.replace("[[x%d]]" % count, make_button("x", "/%s/%s/remove/datamap/%d" % (item_class, obj.handle, count))) text = text.replace("[[x%d]]" % count, make_button("x", "/%s/%s/remove/attribute/%d" % (item_class, obj.handle, count)))
text = text.replace("[[^%d]]" % count, make_button("^", "/%s/%s/up/datamap/%d" % (item_class, obj.handle, count))) text = text.replace("[[^%d]]" % count, make_button("^", "/%s/%s/up/attribute/%d" % (item_class, obj.handle, count)))
text = text.replace("[[v%d]]" % count, make_button("v", "/%s/%s/down/datamap/%d" % (item_class, obj.handle, count))) text = text.replace("[[v%d]]" % count, make_button("v", "/%s/%s/down/attribute/%d" % (item_class, obj.handle, count)))
count += 1 count += 1
retval += text retval += text
if has_data: if has_data: