[ckan-changes] commit/ckanext-pdeu: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Thu Jun 9 20:44:51 UTC 2011
2 new changesets in ckanext-pdeu:
http://bitbucket.org/okfn/ckanext-pdeu/changeset/92d517c614d0/
changeset: 92d517c614d0
user: pudo
date: 2011-06-09 21:37:06
summary: Add domain-specific extras to UI: country, source, etc.
affected #: 5 files (7.3 KB)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ckanext/pdeu/countries.py Thu Jun 09 21:37:06 2011 +0200
@@ -0,0 +1,11 @@
+# -*- coding: UTF-8 -*-
+
+# This Python file uses the following encoding: utf-8
+# ISO 3166-1 country names and codes from http://opencountrycodes.appspot.com/python
+
+COUNTRIES = (("", u"(No country assigned)"), ("AF", u"Afghanistan"), ("AX", u"Ã
land Islands"),("AL", u"Albania"),("DZ", u"Algeria"),("AS", u"American Samoa"),("AD", u"Andorra"),("AO", u"Angola"),("AI", u"Anguilla"),("AQ", u"Antarctica"),("AG", u"Antigua and Barbuda"),("AR", u"Argentina"),("AM", u"Armenia"),("AW", u"Aruba"),("AU", u"Australia"),("AT", u"Austria"),("AZ", u"Azerbaijan"),("BS", u"Bahamas"),("BH", u"Bahrain"),("BD", u"Bangladesh"),("BB", u"Barbados"),("BY", u"Belarus"),("BE", u"Belgium"),("BZ", u"Belize"),("BJ", u"Benin"),("BM", u"Bermuda"),("BT", u"Bhutan"),("BO", u"Bolivia, Plurinational State of"),("BA", u"Bosnia and Herzegovina"),("BW", u"Botswana"),("BV", u"Bouvet Island"),("BR", u"Brazil"),("IO", u"British Indian Ocean Territory"),("BN", u"Brunei Darussalam"),("BG", u"Bulgaria"),("BF", u"Burkina Faso"),("BI", u"Burundi"),("KH", u"Cambodia"),("CM", u"Cameroon"),("CA", u"Canada"),("CV", u"Cape Verde"),("KY", u"Cayman Islands"),("CF", u"Central African Republic"),("TD", u"Chad"),("CL", u"Chile"),("CN", u"China"),("CX", u"Christmas Island"),("CC", u"Cocos (Keeling) Islands"),("CO", u"Colombia"),("KM", u"Comoros"),("CG", u"Congo"),("CD", u"Congo, The Democratic Republic of the"),("CK", u"Cook Islands"),("CR", u"Costa Rica"),("CI", u"Côte d'Ivoire"),("HR", u"Croatia"),("CU", u"Cuba"),("CY", u"Cyprus"),("CZ", u"Czech Republic"),("DK", u"Denmark"),("DJ", u"Djibouti"),("DM", u"Dominica"),("DO", u"Dominican Republic"),("EC", u"Ecuador"),("EG", u"Egypt"),("SV", u"El Salvador"),("GQ", u"Equatorial Guinea"),("ER", u"Eritrea"),("EE", u"Estonia"),("ET", u"Ethiopia"),("FK", u"Falkland Islands (Malvinas)"),("FO", u"Faroe Islands"),("FJ", u"Fiji"),("FI", u"Finland"),("FR", u"France"),("GF", u"French Guiana"),("PF", u"French Polynesia"),("TF", u"French Southern Territories"),("GA", u"Gabon"),("GM", u"Gambia"),("GE", u"Georgia"),("DE", u"Germany"),("GH", u"Ghana"),("GI", u"Gibraltar"),("GR", u"Greece"),("GL", u"Greenland"),("GD", u"Grenada"),("GP", u"Guadeloupe"),("GU", u"Guam"),("GT", u"Guatemala"),("GG", u"Guernsey"),("GN", u"Guinea"),("GW", u"Guinea-Bissau"),("GY", u"Guyana"),("HT", u"Haiti"),("HM", u"Heard Island and McDonald Islands"),("VA", u"Holy See (Vatican City State)"),("HN", u"Honduras"),("HK", u"Hong Kong"),("HU", u"Hungary"),("IS", u"Iceland"),("IN", u"India"),("ID", u"Indonesia"),("IR", u"Iran, Islamic Republic of"),("IQ", u"Iraq"),("IE", u"Ireland"),("IM", u"Isle of Man"),("IL", u"Israel"),("IT", u"Italy"),("JM", u"Jamaica"),("JP", u"Japan"),("JE", u"Jersey"),("JO", u"Jordan"),("KZ", u"Kazakhstan"),("KE", u"Kenya"),("KI", u"Kiribati"),("KP", u"Korea, Democratic People's Republic of"),("KR", u"Korea, Republic of"),("KW", u"Kuwait"),("KG", u"Kyrgyzstan"),("LA", u"Lao People's Democratic Republic"),("LV", u"Latvia"),("LB", u"Lebanon"),("LS", u"Lesotho"),("LR", u"Liberia"),("LY", u"Libyan Arab Jamahiriya"),("LI", u"Liechtenstein"),("LT", u"Lithuania"),("LU", u"Luxembourg"),("MO", u"Macao"),("MK", u"Macedonia, The Former Yugoslav Republic of"),("MG", u"Madagascar"),("MW", u"Malawi"),("MY", u"Malaysia"),("MV", u"Maldives"),("ML", u"Mali"),("MT", u"Malta"),("MH", u"Marshall Islands"),("MQ", u"Martinique"),("MR", u"Mauritania"),("MU", u"Mauritius"),("YT", u"Mayotte"),("MX", u"Mexico"),("FM", u"Micronesia, Federated States of"),("MD", u"Moldova, Republic of"),("MC", u"Monaco"),("MN", u"Mongolia"),("ME", u"Montenegro"),("MS", u"Montserrat"),("MA", u"Morocco"),("MZ", u"Mozambique"),("MM", u"Myanmar"),("NA", u"Namibia"),("NR", u"Nauru"),("NP", u"Nepal"),("NL", u"Netherlands"),("AN", u"Netherlands Antilles"),("NC", u"New Caledonia"),("NZ", u"New Zealand"),("NI", u"Nicaragua"),("NE", u"Niger"),("NG", u"Nigeria"),("NU", u"Niue"),("NF", u"Norfolk Island"),("MP", u"Northern Mariana Islands"),("NO", u"Norway"),("OM", u"Oman"),("PK", u"Pakistan"),("PW", u"Palau"),("PS", u"Palestinian Territory, Occupied"),("PA", u"Panama"),("PG", u"Papua New Guinea"),("PY", u"Paraguay"),("PE", u"Peru"),("PH", u"Philippines"),("PN", u"Pitcairn"),("PL", u"Poland"),("PT", u"Portugal"),("PR", u"Puerto Rico"),("QA", u"Qatar"),("RE", u"Réunion"),("RO", u"Romania"),("RU", u"Russian Federation"),("RW", u"Rwanda"),("BL", u"Saint Barthélemy"),("SH", u"Saint Helena, Ascension and Tristan Da Cunha"),("KN", u"Saint Kitts and Nevis"),("LC", u"Saint Lucia"),("MF", u"Saint Martin"),("PM", u"Saint Pierre and Miquelon"),("VC", u"Saint Vincent and the Grenadines"),("WS", u"Samoa"),("SM", u"San Marino"),("ST", u"Sao Tome and Principe"),("SA", u"Saudi Arabia"),("SN", u"Senegal"),("RS", u"Serbia"),("SC", u"Seychelles"),("SL", u"Sierra Leone"),("SG", u"Singapore"),("SK", u"Slovakia"),("SI", u"Slovenia"),("SB", u"Solomon Islands"),("SO", u"Somalia"),("ZA", u"South Africa"),("GS", u"South Georgia and the South Sandwich Islands"),("ES", u"Spain"),("LK", u"Sri Lanka"),("SD", u"Sudan"),("SR", u"Suriname"),("SJ", u"Svalbard and Jan Mayen"),("SZ", u"Swaziland"),("SE", u"Sweden"),("CH", u"Switzerland"),("SY", u"Syrian Arab Republic"),("TW", u"Taiwan, Province of China"),("TJ", u"Tajikistan"),("TZ", u"Tanzania, United Republic of"),("TH", u"Thailand"),("TL", u"Timor-Leste"),("TG", u"Togo"),("TK", u"Tokelau"),("TO", u"Tonga"),("TT", u"Trinidad and Tobago"),("TN", u"Tunisia"),("TR", u"Turkey"),("TM", u"Turkmenistan"),("TC", u"Turks and Caicos Islands"),("TV", u"Tuvalu"),("UG", u"Uganda"),("UA", u"Ukraine"),("AE", u"United Arab Emirates"),("GB", u"United Kingdom"),("US", u"United States"),("UM", u"United States Minor Outlying Islands"),("UY", u"Uruguay"),("UZ", u"Uzbekistan"),("VU", u"Vanuatu"),("VE", u"Venezuela, Bolivarian Republic of"),("VN", u"Viet Nam"),("VG", u"Virgin Islands, British"),("VI", u"Virgin Islands, U.S."),("WF", u"Wallis and Futuna"),("EH", u"Western Sahara"),("YE", u"Yemen"),("ZM", u"Zambia"),("ZW", u"Zimbabwe"),)
+
+def code_to_country(code):
+ if code is None: return ""
+ return dict(COUNTRIES).get(code.upper().strip(), code)
+
--- a/ckanext/pdeu/plugin.py Thu Jun 09 19:17:07 2011 +0100
+++ b/ckanext/pdeu/plugin.py Thu Jun 09 21:37:06 2011 +0200
@@ -1,11 +1,15 @@
import os
from ckan.plugins import implements, SingletonPlugin
-from ckan.plugins import IRoutes, IConfigurer
+from ckan.plugins import IRoutes, IConfigurer, IPackageController
+from ckan.lib import helpers as h
+from countries import code_to_country
+h.code_to_country = code_to_country
class PDEUCustomizations(SingletonPlugin):
implements(IRoutes)
implements(IConfigurer, inherit=True)
+ implements(IPackageController, inherit=True)
def update_config(self, config):
here = os.path.dirname(__file__)
@@ -17,6 +21,13 @@
config['extra_template_paths'] = ','.join([template_dir,
config.get('extra_template_paths', '')])
config['ckan.site_logo'] = '/img/logo.png'
+ config['package_hide_extras'] = ' '.join(['eu_country',
+ 'harvest_catalogue_name',
+ 'harvest_catalogue_url', 'harvest_dataset_url',
+ 'eu_nuts1', 'eu_nuts2', 'eu_nuts3'])
+ config['search.facets'] = 'groups tags extras_eu_country res_format'
+ config['search.facets.extras_eu_country.title'] = 'Country'
+ config['search.facets.res_format.title'] = 'File format'
def before_map(self, route_map):
wire_controller = 'ckanext.pdeu.controllers:RewiringController'
@@ -43,3 +54,10 @@
def after_map(self, route_map):
return route_map
+ def read(self, pkg):
+ from ckan.lib.base import request, c
+ c.eu_country = pkg.extras.get('eu_country')
+ c.harvest_catalogue_name = pkg.extras.get('harvest_catalogue_name', '(Unspecified)')
+ c.harvest_catalogue_url = pkg.extras.get('harvest_catalogue_url')
+ c.harvest_dataset_url = pkg.extras.get('harvest_dataset_url')
+
--- a/ckanext/pdeu/theme/public/css/style.css Thu Jun 09 19:17:07 2011 +0100
+++ b/ckanext/pdeu/theme/public/css/style.css Thu Jun 09 21:37:06 2011 +0200
@@ -384,7 +384,7 @@
.property-list {
list-style: none;
- padding-left: 2em;
+ padding-left: 3em;
}
#sidebar .property-list li h3 {
--- a/ckanext/pdeu/theme/templates/package/read.html Thu Jun 09 19:17:07 2011 +0100
+++ b/ckanext/pdeu/theme/templates/package/read.html Thu Jun 09 21:37:06 2011 +0200
@@ -43,6 +43,9 @@
<h3>Version</h3>
${c.pkg.version}
</li>
+ <li py:if="c.eu_country">
+ <h3>Country</h3> ${h.code_to_country(c.eu_country)}
+ </li><li py:if="len(c.pkg.tags)"><h3>Tags</h3>
${tag_list(c.pkg.tags)}
@@ -71,6 +74,11 @@
<li py:if="h.am_authorized(c, actions.CHANGE_STATE, c.pkg)"><li><h3>State</h3> ${c.pkg.state}</li></li>
+ <li py:if="c.harvest_catalogue_name">
+ <h3>Source</h3><a href="${c.harvest_dataset_url}">Source
+ page</a> on <a
+ href="${c.harvest_catalogue_url}">${c.harvest_catalogue_name}</a>
+ </li><li py:if="c.package_relationships"><h3>Related packages</h3><ul>
--- a/ckanext/pdeu/theme/templates/package/search.html Thu Jun 09 19:17:07 2011 +0100
+++ b/ckanext/pdeu/theme/templates/package/search.html Thu Jun 09 21:37:06 2011 +0200
@@ -21,10 +21,10 @@
</p></li>
+ ${facet_sidebar('tags')}
+ ${facet_sidebar('extras_eu_country', label=h.code_to_country)}
+ ${facet_sidebar('res_format')}
${facet_sidebar('groups', label=h.group_name_to_title)}
- ${facet_sidebar('tags')}
- ${facet_sidebar('res_format')}
- ${facet_sidebar('license')}
<li class="widget-container widget_text"><h4>Other access</h4>
http://bitbucket.org/okfn/ckanext-pdeu/changeset/a763e726128c/
changeset: a763e726128c
user: pudo
date: 2011-06-09 22:44:44
summary: categorize packages into groups based on categories
affected #: 1 file (668 bytes)
--- a/scripts/normalization.py Thu Jun 09 21:37:06 2011 +0200
+++ b/scripts/normalization.py Thu Jun 09 22:44:44 2011 +0200
@@ -2,13 +2,14 @@
from datautil.normalization.table_based import Normalizer, NormalizerJoin
from CREDENTIALS import GOOGLE_USER, GOOGLE_PASS
from traverse import traverse
+from ckanclient import CkanApiError
from pprint import pprint
def Categories(username, password):
doc_id = 'tE-DPw3k0uXxgNUk1Q8_U_w'
first = Normalizer(username, password, doc_id, 'Mapping', 'category')
- second = Normalizer(username, password, doc_id, 'Groups', 'group_name')
+ second = Normalizer(username, password, doc_id, 'Groups', 'name')
return NormalizerJoin(first, second)
@@ -34,6 +35,20 @@
def __init__(self):
self.normalizer = Categories(GOOGLE_USER, GOOGLE_PASS)
+
+ def _assign_group(self, client, pkg_name, data):
+ try:
+ group = client.group_entity_get(data.get('name'))
+ if pkg_name not in group['packages']:
+ group['packages'] += [pkg_name]
+ client.group_entity_put(group)
+ except CkanApiError, e:
+ group = {'name': data.get('name'),
+ 'title': data.get('title', data.get('name')),
+ 'description': data.get('description', ''),
+ 'packages': [pkg_name]
+ }
+ client.group_register_post(group)
def __call__(self, client, pkg):
cats = pkg.get('extras', {}).get('categories', [])
@@ -41,9 +56,9 @@
cats = [cats]
for cat in cats:
data = self.normalizer.get(cat, source_hint=pkg.get('ckan_url'))
- if data.get('group_name'):
- pprint(data)
- #return pkg
+ pprint(data)
+ if data.get('name'):
+ self._assign_group(client, pkg.get('name'), data)
if __name__ == '__main__':
traverse(categories())
Repository URL: https://bitbucket.org/okfn/ckanext-pdeu/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list