Python/Django requirements can be found in the
Cloning the project
git clone -b develop --recursive email@example.com:kingsdigitallab/dprr-django.git
The above command will clone the development branch, as well as all the submodules.
The main application is
Given that the desired output is a list of Persons, we need to Group the results by person. To do that we use a common field to all Assertion index objects, the
person_id. We’re also using different indexes to reflect the different Assertion types. The queryset is defined in the
queryset = GroupedSearchQuerySet().models( PostAssertion, StatusAssertion, RelationshipAssertion).group_by('person_id')
Given that we wish to search on the Assertions but list Persons we opted to use the SOLR Grouping/Field collapsing feature:
- See http://wiki.apache.org/solr/FieldCollapsing for the Solr feature
This is currently unsupported by Haystack. We're using an experimental backend for Haystack 2.0 adapted from the following code:
- See https://gist.github.com/3750774 for the current version of this code
The backend code can be found on
Adding a new facet
Add the new facet to the
search_index.py file, following Haystack’s documentation.
There are 4 types of index classes:
After adding the new field to the search_indexes file (as well as the prepare method, if needed), you need to:
- rebuild the SOLR schema xml file (overwriting the
schema.xmlin the solr config folder)
- restart Tomcat
- rebuild the index (using the management command
python manage.py rebuild_index)
To add the facet to the frontendend, add the facet field to either the
facet_fields or the
autocomplete facets lists in the
promrep/views.py). These lists will be used by the
.facet() function. These are also used in the template to control how to display the facet.
Some authority lists are hierarchical -- see the Office and Province models, for instance. These were developed using the
In order to display them correctly all hierarchical model objects need to exist in the template. This is currently done in the
views.py file, where each model is added to the context (
get_context_data). In the template we use MPTT
recursetree tag to recurse the tree and display each node.
Scripts and data
There are various scripts in the
promrep/scripts folder. Most were written to be used only once to load data in the staging database. The data itself (usually
csv files created by the project partners) is not stored on the server but, for provenance reasons, all scripts refer to the name/version of the data file that was loaded into the database.
add_highest_office: script that adds the
highest_officefield to all persons on the database. The script checks if the
highest_office_editedfield is False and, if so, overwrites it;
add_senator_statusassertions: # this script enriches the database with the Senator StatusAssertions; for full rules and dicussion please see the original JIRA ticket. Only adds/removes StatusAssertions if the person doesn't have any Senatorial StatusAssertions flagged as
is_verified(defaults to False).
PDF export will not work when behind http auth. This means it will not work on -dev or -stg, but will work on the live site.
The PDF export needs a virtual X server. If this is not working, ensure the following commands have been run.
apt-get install wkhtmltopdf
apt-get install xvfb
echo -e '#!/bin/bash\nxvfb-run -a --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf -q $*' > /usr/bin/wkhtmltopdf.sh
chmod a+x /usr/bin/wkhtmltopdf.sh
ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf