# Sorting Complete Individual Report

**URL:** <https://gramps.discourse.group/t/sorting-complete-individual-report/1804>\
**Category:** Help\
**Created:** [September 9, 2021, 8:11am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804 "2021-09-09T08:11:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 9, 2021, 8:11am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/1 "2021-09-09T08:11:15Z")

</div>

GrampsAIO64-5.1.3-2 Windows 10

I know that the [Complete Individual Report](https://gramps-project.org/wiki/index.php/Gramps_5.1_Wiki_Manual_-_Reports_-_part_6#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)?

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [September 9, 2021, 9:41am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/2 "2021-09-09T09:41:29Z")

</div>

The relative path from the Gramps application subdirectory of the Program Files folder is:  
`/gramps/plugins/textreport/indivcomplete.py`

That source can be [found here on GitHub](https://github.com/gramps-project/gramps/blob/master/gramps/plugins/textreport/indivcomplete.py) _(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 builtin Report](https://www.gramps-project.org/wiki/index.php/Adapt_a_builtin_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](https://www.gramps-project.org/wiki/index.php/Report-writing_tutorial) describes the creating the .gpr.py registration file and general coding of reports. _(See the [See Also](https://www.gramps-project.org/wiki/index.php/Report-writing_tutorial#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](https://www.gramps-project.org/wiki/index.php/Report_snippets) 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.

---

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 9, 2021, 11:28pm UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/3 "2021-09-09T23:28:12Z")

</div>

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

Thanks again.

Les

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [September 10, 2021, 2:31am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/4 "2021-09-10T02:31:09Z")

</div>

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

What sorting did you want?

---

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 10, 2021, 3:00am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/5 "2021-09-10T03:00:15Z")

</div>

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  
etc

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

---

<div class="post-metadata">

**Author:** ![Mattkmmr](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/mattkmmr/32/410_2.png) [@Mattkmmr](https://gramps.discourse.group/u/Mattkmmr)\
**Post date:** [September 10, 2021, 7:18am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/6 "2021-09-10T07:18:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 10, 2021, 7:31am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/7 "2021-09-10T07:31:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [September 10, 2021, 9:58am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/8 "2021-09-10T09:58:42Z")

</div>

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

```auto
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

```auto
        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
        displayer.set_format(0)
        ind_list = sorted(ind_list, key=sort_by_birth_date, reverse=False)
        displayer.set_format(old_format)

```

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

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [September 10, 2021, 11:17pm UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/9 "2021-09-10T23:17:17Z")

</div>

It worked for me. 🎉 (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”

![](https://gramps-project.org/bugs/images/favicon.ico) [0010362: Providing two custom reports: “Complete individual report” and “Complete Kinship report”](https://gramps-project.org/bugs/view.php?id=10362)

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](https://gramps-project.org/bugs/view_user_page.php?id=2166) 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?

---

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 11, 2021, 12:20am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/10 "2021-09-11T00:20:19Z")

</div>

SNoirand,

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 (indivcomplete.py, 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**?

 ![indivcomplete screen shot 2021 09 11](https://global.discourse-cdn.com/free1/uploads/gramps/original/2X/a/a2401bc7baf4e9e0b18925e9082de330579a7cc8.jpeg)

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

---

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 11, 2021, 12:21am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/11 "2021-09-11T00:21:55Z")

</div>

A closer screen shot

 ![indivcomplete screen shot 2021 09 11 close up](https://global.discourse-cdn.com/free1/uploads/gramps/original/2X/6/6a099ffb2498afa6ceee74d9ee1637d63faaf0ed.jpeg)

---

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 11, 2021, 1:13am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/12 "2021-09-11T01:13:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [September 11, 2021, 6:35am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/13 "2021-09-11T06:35:29Z")

</div>

> [@les61](#):
>
> A closer screen shot

Your indentation is incorrect. it should be:

 ![indiv.2](https://global.discourse-cdn.com/free1/uploads/gramps/original/2X/6/68a83771b314888efaa0f2fcc36c3dc6ae6ce678.png)

---

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 11, 2021, 7:07am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/14 "2021-09-11T07:07:49Z")

</div>

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

 ![indivcomplete error line 843 py](https://global.discourse-cdn.com/free1/uploads/gramps/original/2X/e/e517fd35865fb07fab1c85c2275019832cd3eb30.jpeg)

When I run the report I get an error  
_The plugin Complete Individual Report did not load and reported an error._  
_unexpected indent (indivcomplete.py, line 843)_

Line 843 is the line with cursor that says "if not ind\_list:’

Thanks in advance

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [September 11, 2021, 9:03am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/15 "2021-09-11T09:03:43Z")

</div>

Les,

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.

---

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 12, 2021, 2:06am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/16 "2021-09-12T02:06:58Z")

</div>

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.

Les

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [September 12, 2021, 4:55am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/17 "2021-09-12T04:55:34Z")

</div>

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.)

---

<div class="post-metadata">

**Author:** ![les61](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@les61](https://gramps.discourse.group/u/les61)\
**Post date:** [September 12, 2021, 5:49am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/18 "2021-09-12T05:49:53Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![SNoiraud](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/snoiraud/32/72_2.png) [@SNoiraud](https://gramps.discourse.group/u/SNoiraud)\
**Post date:** [September 12, 2021, 7:48am UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/19 "2021-09-12T07:48:35Z")

</div>

> [@les61](#):
>
> This report also puts all those with no date of birth at the very end

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

> [@les61](#):
>
> it is not what I was really after.

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

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [September 12, 2021, 12:30pm UTC](https://gramps.discourse.group/t/sorting-complete-individual-report/1804/20 "2021-09-12T12:30:08Z")

</div>

> [@les61](#):
>
> 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)

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 tutorial](https://www.gramps-project.org/wiki/index.php/Report-writing_tutorial) … _yet_. 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.)

[Next page](https://gramps.discourse.group/t/sorting-complete-individual-report/1804.md?page=2)
