I m trying to write a supertool script to modify some typo error with the data i enter for a census.
I used the form gramplet to enter the data for the census.
I have written the following script
[Gramps SuperTool script file]
version=1
[title]
recensement
[description]
[category]
Events
[initial_statements]
from collections import defaultdict
display=False
dat=makedate(1946)
my_res=defaultdict(str)
recploug1946 = ('Nom','Section','Adresse','Numéro Maison','Numéro Foyer','Numéro','Relation','Année de naissance','Nationalité','Profession')
badvalue=("rue du cimetièr","rue du cimetiere","rue du cimitière")
fixvalue="rue du cimetière"
[statements]
resul=""
display=False
if type == "Census" and date == dat and place.name == "Plouguerneau":
for event_ref in refs:
resul=""
attrs = event_ref.get_attribute_list()
my_res = defaultdict(str)
my_res.clear()
for attribute in attrs:
attr_type = str(attribute.get_type()).strip()
attr_val = str(attribute.get_value())
if attr_type == "Adresse" and attr_val in badvalue:
display = True
attribute.set_value(fixvalue)
my_res[attr_type]=attr_val
my_data=[]
for k in recploug1946:
my_data.append(my_res[k])
if my_data:
result.add_row(my_data,obj=self)
[filter]
display
[expressions]
[scope]
all
[unwind_lists]
False
[commit_changes]
False
[summary_only]
False
```
Well the script is working. i can detect all the bad data in the census. I replace the data in the attribute but i m not able to commit the change. I have selected the checkbox commit changes but i guess it only commit to the event object.
And what i want to to is to change attributes on eventref.
@PLegoux has a sample script that sets Event attributes on Geneanet. But it mentions shared events.
Is it possible the attribute_list is being committed at 2 different levels? At the shared Event versus the unshared EventRef level of the Gramps Data Model
Your script need to be a Person SuperTool script, not an Event script, to do that
You need to look for these events and attributes in Person’s records and modify them.
In my script directory i don’t have any one for event_ref attributes but this one for creating media_ref attributes I’ve created to define signature picture for using them with FamilyTreeView is probably a good reference:
Here is the result that work
thank you for your help
[Gramps SuperTool script file]
version=1
[title]
fixcensusdata
[description]
this script fix census typo in data.
attrtype : field that contain bas data
badvalue ; list that contain value to be fixed
fixvalue : Good value
[category]
People
[initial_statements]
dat=makedate(1946)
attrtype = "Relation"
badvalue=("Domestiue", "Domestiqur")
fixvalue="Domestique"
placename="Plouguerneau"
[statements]
badval=""
display=False
for evnt in events:
if evnt.type == "Census" and evnt.date == dat and evnt.place.name == placename:
hdl=evnt.handle
evt=db.get_event_from_handle(hdl)
for event_ref in person.get_event_ref_list():
evt = db.get_event_from_handle(event_ref.ref)
if evt.get_handle() == hdl:
attrs = event_ref.get_attribute_list()
display=False
for attr in attrs:
attr_type = str(attr.get_type()).strip()
attr_val = str(attr.get_value())
if attr_type == attrtype and attr_val in badvalue:
display = True
badval = attr_val
attr.set_value(fixvalue)
[filter]
display
[expressions]
name,badval,fixvalue
[scope]
all
[unwind_lists]
False
[commit_changes]
False
[summary_only]
False