Sorting Complete Individual Report

GrampsAIO64-5.1.3-2 Windows 10

I know that the Complete Individual Report sorts but surname but no further. Can anyone tell me where I would find the file that creates the report to see if I can work out if I can add an extra sort query (not that I know much about programming)?

The relative path from the Gramps application subdirectory of the Program Files folder is:

That source can be found here on GitHub (The GitHub code is a good reference tool for discussing the module. Their interface identifies original code sections by line number… which simplifies pointing out where to find each coding change.)

When modifying a built-in report, it is generally better to fork it… to create an add-on of a similar (but still unique) name. This saves having to battle with Windows over whether you have admin rights each time you want to change the file. (And, when you create a useful modification, you can share your fork on GitHub for others… which raises the report’s visibility to others who might continue to improve it.)

The wiki page on forking a report (“Adapt a built-in Report”) needs a lot of correction and expanding. (I was out of my depth! Any help from a programmer in making this document ACCURATE would be appreciated.)

The report writing tutorial describes the creating the registration file and general coding of reports. (See the See Also section of that wiki page for reference pages on the report API, output format options & data model.)

There isn’t a Report Snippet showing any example of sorting.

The sorting options already in the Complete Individual Report code are only about the Event data inside each individual’s report: whether to force events to sort in chronological order.

Many thanks but after looking at this it all looks way over my head.

Thanks again.


The sort order is based on the person’s “Surname, Given Suffix”

What sorting did you want?

My report sorts by “Surname, ID number”. I have as an example:

Ablett, John ID 221
Ablett, John ID 223
Ablett, John ID 225
Ablett, Henry ID 229
Ablett, Edmund ID231
Ablett, Maria ID 388

Ideally I would like it in the order: “Surname, Given, Date of Birth”

You could using books for that. One report for each person and sort them manually the way you like, but this is only useful if you have a small number of persons, otherwise it is too much work.

Matt, thanks but so far I have 4,379 people and counting… :thinking:

If you really want to do that, here is a patch to do that in gramps/plugins/textreport/
add two lines after: from gramps.gen.errors import ReportError

from gramps.gen.utils.db import get_birth_or_fallback
from gramps.gen.datehandler import displayer

Add the following after line 828: ind_list = plist

        def sort_by_birth_date(person_hdle):
            person = self._db.get_person_from_handle(person_hdle)
            birth = get_birth_or_fallback(self._db, person)
            date = "9999-12-31" # if no birth date
            if birth:
                dateo = birth.get_date_object()
                date = displayer.display(dateo)
            return date

        old_format = displayer.format
        ind_list = sorted(ind_list, key=sort_by_birth_date, reverse=False)

It should work. If you want to sort from old dates at the end, change reverse=False to reverse=True

1 Like

It worked for me. :tada: (Thank you @SNoiraud !)

I went over to MantisBT to submit a feature enhancement so that your change will not be lost here in the Discourse forum but be rolled into 5.2 release. But I found a surprise.

It seems that there been another variant with source code languishing in MantisBT since 2018. It has a “Thank you” reply and sits as “Confirmed”

0010362: Providing two custom reports: “Complete individual report” and “Complete Kinship report”

It has a new layout and includes up to 3 images. But the big thing seems to be a contextual kin sorting routine Matthias Basler created and is asking to have rolled into core. He feels it would be useful for more reports.

Any idea how this could be moved out of limbo and be evaluated for inclusion in the 5.2 track?


Many thanks for the script details. I tried this and got the following error message when trying to run the report

The plugin Complete Individual Report did not load and reported an error.
inconsistent use of tabs and spaces in indentation (, line 830)

Line 828 is now line 830.

I adjusted line 830 using tab and spaces but now get the same error with line 839. I have tried adding tabs and spaces but still get the error message. What tabs and spaces should there be?

Is there any online courses on how to write this sort of script and where everything is in GRAMPS?

A closer screen shot

@SNoiraud I done some tweaking and no get the error message on line 843.

Your indentation is incorrect. it should be:

@SNoiraud , Sorry to be a pest but I have it as follows:

When I run the report I get an error
The plugin Complete Individual Report did not load and reported an error.
unexpected indent (, line 843)

Line 843 is the line with cursor that says "if not ind_list:’

Thanks in advance


The indentation and white space is critical in Python.

Do you see in Serge’s capture that the ‘d’ of the ‘def sort_by_birth_date’ line aligns directly below the initial ‘e’ of the ‘else’ 2 lines above? Your lines are to the left of where they need to be. The same indent should be used with the inserted lines below the 'return date line.

So that misalignment of just 5 lines is what’s fouling you up.

Serge and Brian, Thanks for your help. I have the report working now however it is not what I was really after. The original reports sorts by: Surname, ID Number.

This reports sorts by : Date of Birth, Surname.

I was trying to do sort : Surname, Given Name, Date of Birth"

This report also puts all those with no date of birth at the very end and also puts those born before 1000 after those born after 1000 and before those with no date of birth. Also those with “About”, “before”, “estimated”, “between” are at the end of the report after all the “no date of birth”.

Thanks anyway.


Ahh… I had filtered to an example of recurring surname & given. Then looked at how it sub-sorted those. (That report meanders a bit and I was trying to get the page count down enough to be readable.)

Brian, Yes that works but I want to do the full database knowing it is a huge file (6,000 + pages without media at this stage and still almost 300 ancestors with more parents to be added)

You can replace “9999-12-31” by 0000-01-01"

This is a first start to help you to improve this report.

I understand you want to sort the whole tree. My comment was almost a ‘dammit’ comment to self. I used the wrong data sunset to properly test the new sort.

This is an interesting discussion. It will help improve the manual.

Information on sorting & sub-sorting is not a section the Report writing tutorialyet. This discussion (and the example in that MantisBT file) should give a good start to writing an ‘advanced’ topic offshoot articles for that tutorial.

(The tutorial needs to be trimmed down anyway. It frequently digresses into features people typically want in a basic report. Which means a novice has to wade through a LOT of text and sample source code. In this case, the ‘comprehensive tutorial’ discourages the first experiment in report writing. All those digressions can be moved into more digestible “advanced topic” offshoot articles.)