Skip to content

Instantly share code, notes, and snippets.

View seanh's full-sized avatar

Sean Hammond seanh

View GitHub Profile

Packages extras seem to get pretty mangled by CKAN's db_fo_form_package_schema() validation. Before validation:

[{u'id': u'ee834033-4771-4e07-8005-bce2a7fe18c6',
  u'key': u'genre',
  u'package_id': u'ac472ed5-cf72-4ab5-a800-32d30628b7f9',
  u'revision_id': u'b6cae82f-742a-4148-8557-fc1454c7ed5f',
  u'revision_timestamp': '2013-02-15T14:51:59.815433',
  u'state': u'active',
  u'value': '"romantic novel"'},
@seanh
seanh / gist:4754566
Created February 11, 2013 14:01
Remove `tracking_summary` from CKAN's `resource_item.html`. (Workaround for this issue: https://github.com/okfn/ckan/pull/85).
diff --git a/ckan/templates/package/snippets/resource_item.html b/ckan/templates/package/snippets/resource_item.html
index 103df3e..2b8549b 100644
--- a/ckan/templates/package/snippets/resource_item.html
+++ b/ckan/templates/package/snippets/resource_item.html
@@ -3,7 +3,6 @@
{% block resource_item_title %}
<a class="heading" href="{{ url }}" title="{{ res.name or res.description }}">
{{ h.resource_display_name(res) | truncate(50) }}<span class="format-label" property="dc:format" data-format="{{ res.format.lower() or 'data' }}">{{ res.format }}</span>
- {{ h.popular('views', res.tracking_summary.total, min=10) }}
</a>
@seanh
seanh / gist:4597885
Last active December 11, 2015 11:59
Traceback (most recent call last):
File "/usr/lib/ckan/lib/python2.7/site-packages/paste/cascade.py", line 130, in __call__
return self.apps[-1](environ, start_response)
File "/usr/lib/ckan/src/ckan/ckan/config/middleware.py", line 213, in __call__
return self.app(environ, start_response)
File "/usr/lib/ckan/lib/python2.7/site-packages/paste/registry.py", line 379, in __call__
app_iter = self.application(environ, start_response)
File "/usr/lib/ckan/lib/python2.7/site-packages/repoze/who/middleware.py", line 107, in __call__
app_iter = app(environ, wrapper.wrap_start_response)
File "/usr/lib/ckan/lib/python2.7/site-packages/pylons/middleware.py", line 214, in __call__
<?python
import ipdb; ipdb.set_trace()
?>

Setting Up Tracking of Dataset Popularity

The CMAP configuration file and templates are configured so that the popularity of datasets (in terms of number of views) are shown in dataset listings. CKAN's internal tracking of page views is used (and not e.g. the ckanext-googleanalytics extension).

The script update_tracking.sh needs to be run regularly on the server to update the page view statistics. A line can be added to the crontab file on the server to run the script. On an Ubuntu server you can use the command `crontab

@seanh
seanh / gist:4556429
Created January 17, 2013 14:51
CKAN's old (circa 2012) Jenkins script (installs CKAN into a virtualenv and runs the tests)
#!/bin/sh -e
# Print out the build description we want (to be retrieved later by the
# Jenkins Description Setter Plugin).
echo 'Set build description to:' $GIT_BRANCH $GIT_COMMIT
PYENV=$WORKSPACE/pyenv
cd $WORKSPACE
2013-01-14 08:50:20 CST WARNING: there is already a transaction in progress
2013-01-14 08:50:26 CST ERROR: deadlock detected
2013-01-14 08:50:26 CST DETAIL: Process 16684 waits for AccessExclusiveLock on
relation 63738 of database 63689; blocked by process 22680.
Process 22680 waits for AccessShareLock on relation 63981 of database 63
689; blocked by process 16684.
Process 16684:
BEGIN;
ALTER TABLE "user"
sqlalchemy.exc.DBAPIError: (TransactionRollbackError) deadlock detected
DETAIL: Process 11727 waits for AccessExclusiveLock on relation 63738 of databa
se 63689; blocked by process 5728.
Process 5728 waits for AccessShareLock on relation 63981 of database 63689; bloc
ked by process 11727.
HINT: See server log for query details.
'\nCREATE TABLE user_following_group (\n follower_id text NOT NULL,\n obj
ect_id text NOT NULL,\n datetime timestamp without time zone NOT NULL\n);\n\n
ALTER TABLE user_following_group\n ADD CONSTRAINT user_following_group_pkey P
RIMARY KEY (follower_id, object_id);\n\nALTER TABLE user_following_group\n AD
~> pg_lsclusters
Version Cluster Port Status Owner Data directory Log file
~> aptitude search postgresql | ack '^i'
i postgresql - object-relational SQL database (supported
i A postgresql-9.1 - object-relational SQL database, version 9.
i A postgresql-client-9.1 - front-end programs for PostgreSQL 9.1
i A postgresql-client-common - manager for multiple PostgreSQL client ver
i A postgresql-common - PostgreSQL database-cluster manager
~> sudo -u postgres psql
[sudo] password for seanh:
could not change directory to "/home/seanh"
psql: could not connect to server: No such file or directory