64
edits
Changes
From Gramps
→Defining the Report class: A code description is aligned with the new code
===Defining the ReportOptions class===
In this exampletutorial, no special the report has two options . The first, called <code>what_types</code>, allows a user to choose whether the counts of persons whose gender is Male, Female, Unknown or Other are requiredshown in the report. This makes The second is the standard Gramps option that allows the user to choose the locale for the report different from UI locale. It is added by calling <code>stdoptions.add_localization_option()</code> method. These two options class very simpleare added in the overridden <code>add_menu_options()</code> method. All that is necessary is to To define two unique styles for the report: DBS-Title and DBS-Normal the default method <code>make_default_style()</code> is overridden too. Both stylesare added by calling <code>default_style.add_paragraph_style()</code> method.
{{RWT_ReportOptions.py}}
So create now file '''report.py''' and copy there the above code.
===Defining the Report class===
The actual implementation of the <code>DbSummaryReport</code> is rather simple. No additional work needs to be done to To initialize the class, so the parent <code>Report.__init__()</code> routine is calledand then values of the options entered by the user are extracted from <code>options_class</code> parameter which is of class <code>DbSummaryOptions</code>. An instance variable <code>self.what_types</code> is assigned a list of names of check boxes selected by the user. Then <code>self.set_locale()</code> method is called with the value of the locale to be used to run the report. All the work is done in the <code>_count()</code> method. It uses a [https://www.gramps-project.org/docs/gen/gen_db.html#gramps.gen.db.generic.DbGeneric.iter_people <code>self.database.iter_people()</code>] to iterate through [https://www.gramps-project.org/docs/gen/gen_lib.html#module-gramps.gen.lib.person <code>Person</code>] objects and gathers some simple statistics. The only thing of any complication is the determination of the most common surnames. A python dictionary is used to store the number of times each surname is used. Each time a surname is encountered, the value in the dictionary is incremented. The results are then loaded into a list and sorted in the reverse order <code>slist.sort(reverse=True)</code>, allowing us to find the most common names by looking at the first entries in the list. Finally <code>write_report()</code> method outputs the data collected in accordance with the options selected by the report user. Note that the strings being used in the report (such as "Report Options", "Males" etc) have already been used somewhere else in Gramps and have already been translated into various languages. Thus the content of our report as well as its parameters are already translated!
{{RWT_Report.py}}
Append the above code to the '''report.py''' file