This webapplication's primary purpose is to speak REST according to the rest-api defined at http://ddsc.github.com/api .
To get up and running issue the following commands:
$ git clone https://github.com/ddsc/ddsc-site.git
$ cd ddsc-site
$ pip install --user nensbuild
$ nensbuild
The postgis database ddsc_site is needed. Create one with createdb.
For testing out the various "reinout-api" branches and lizard-structure, load the "demodata" fixture. It contains an empty home screen and a bunch of WMS layers (those layers are copied from deltaportaal, btw):
$ bin/django loaddata demodata
Annotations are indexed by the Apache Solr search engine using django-haystack
. Currently, the latest versions of these modules must be used, to support spatial search.
For django-haystack, this is 2.0.0-beta
. This module is current loaded straight from its git repo using buildout's auto-checkout
.
Apache Solr 3.6.2 is included in the subdirectory solr/
. This needs to be added as a webapp in tomcat6 using a config file that's generated by buildout. Note: when Solr 3.6.2 appears in your APT repository, it's better to use that instead.
Create a symlink from your Tomcat 6 config dir to the generated config:
$ ln -s /srv/api.dijkdata.nl/etc/solr.xml /etc/tomcat6/Catalina/localhost/solr.xml
$ service tomcat6 restart
The config file points to Solr to /srv/api.dijkdata.nl/etc/solr
, which in turn refers to /srv/api.dijkdata.nl/var/solr
using a properties file. This directory contains the actual index, and needs to be writable by Solr / Tomcat:
$ sudo chown -R tomcat6.tomcat6 /srv/api.dijkdata.nl/var/solr
The connection to Solr needs to be configured in your settings.py
:
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8080/solr'
},
}
When changing the Annotation model, the Solr schema needs updating as well:
$ bin/django build_solr_schema > etc/solr/conf/schema.xml
When the index has to be rebuilt entirely:
$ bin/django rebuild_index
When the index can be rebuilt partially, for example in a cron job that runs each hour, you can do:
$ bin/django update_index --age=1
A cronjob doing exactly this is already configured for ddsc-site and ddsc-api. The last update time of an Annotation is determined by its updated_at
column, which is marked auto_now=True
.
For now, instant updating of the index is enabled in settings.py
, at the cost of a tiny performance hit when creating annotations:
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
Searching annotations is easy:
$ wget "http://api.dijkdata.nl/api/v1/annotations/count/?bbox=test&tags=tag2%20tag1&datetime_from=2013-03-21T14:46:46.000&datetime_until=2013-03-21T14:46:50.000"
>> {"count": 17928}
$ wget "http://api.dijkdata.nl/api/v1/annotations/search/?bbox=test&tags=tag2%20tag1&datetime_from=2013-03-21T14:46:46.000&datetime_until=2013-03-21T14:46:50.000"
>> {
"count": 774,
"next": "http://api.dijkdata.nl/api/v1/annotations/search/?datetime_from=2013-03-21T14%3A46%3A46.000&datetime_until=2013-03-21T14%3A46%3A50.000&tags=tag2+tag1&bbox=test&page=2&username_override=username+99975",
"previous": null,
"results": [
{
"id": "ddsc_site.annotation.45525",
"category": "ddsc",
"text": "text 45343",
"username": "username 45343",
"picture_url": "picture_url 45343",
"the_model_name": "model_name 45343",
"the_model_pk": "model_pk 45343",
"location": [-80.4656999999999982, 44.5343000000000018],
"datetime_from": "2013-03-21T14:46:46",
"datetime_until": "2013-03-21T14:46:46",
"visibility": "3",
"tags": "tag1 tag2",
"created_at": null,
"updated_at": null
},
...
]
}
$ wget "http://api.dijkdata.nl/api/v1/annotations/count/?model_names_pks=model_name0%2Cmodel_pk5%3bmodel_name1%2Cmodel_pk2
>> {"count": 2}
Possible GET
parameters:
- category
Search in a category. Probably always 'ddsc'.
- bbox
Comma-separated bounding box for the locations. Default WMS format, like, so "west,south,east,north". SRID 4326 (a.k.a. WGS 84). When equal to "test", uses some fixed coordinates which are compatible with Annotation.create_test_data().
- west,south,east,north
Alternative, if bbox isn't defined.
- bottom_left,top_right
Alternative, if bbox isn't defined. Comma separated.
- username_override
Only available in DEBUG mode. Test private/public annotation visibility with this.
- model_name, model_pk
Search for annotations related to a specific model instance. For example a Timeseries with a specific UUID.
- model_names_pks
Search for annotations related to a whole set of model instances. Separate different pairs of model name and PK with a semi-colon (';', or %3B in url encoding). Separate model name and PK with a comma (',', or %2C in url encoding). For example,
model_names_pks=location%2C54%3Btimeseries%2Csome-uuid-here
.- datetime_from, datetime_until
Search annotations in a specific time range. Takes any dateutil.parser compatible format, for example ISO8601: "2013-03-21T14:46:50.000".
- text
Fulltext search in the text of the annotation.
- tags
A set of space-separated tags to search.
Create a set of test annotations:
$ bin/django shell
>> from ddsc_site.models import Annotation
>> Annotation.create_test_data()