Skip to content

Commit

Permalink
Merge branch 'master' into 515-org-group-search-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Mar 13, 2013
2 parents 7e3de5f + 45f540a commit d0f8e93
Show file tree
Hide file tree
Showing 240 changed files with 1,860 additions and 3,882 deletions.
28 changes: 4 additions & 24 deletions .travis.yml
Expand Up @@ -2,30 +2,10 @@ language: python
python:
- "2.6"
- "2.7"
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq solr-jetty
install:
- "pip install -r pip-requirements.txt --use-mirrors"
- "pip install -r pip-requirements-test.txt --use-mirrors"
before_script:
- psql -c 'CREATE DATABASE ckantest;' -U postgres
- psql -c 'CREATE DATABASE datastore;' -U postgres
- psql -c 'CREATE USER readonlyuser;' -U postgres
- python setup.py develop
- paster make-config ckan development.ini --no-interactive
- sed -i -e 's/.*solr_url.*/solr_url = http:\/\/127.0.0.1:8983\/solr/' development.ini
- sed -i -e 's/.*ckan\.site_id.*/ckan.site_id = travis_ci/' development.ini
- sed -i -e 's/^sqlalchemy.url.*/sqlalchemy.url = postgresql:\/\/postgres@localhost\/ckantest/' development.ini
- sed -i -e 's/.*datastore.write_url.*/ckan.datastore.write_url = postgresql:\/\/postgres@localhost\/datastore/' development.ini
- sed -i -e 's/.*datastore.read_url.*/ckan.datastore.read_url = postgresql:\/\/readonlyuser@localhost\/datastore/' development.ini
- cat development.ini
- echo -e "NO_START=0\nJETTY_HOST=127.0.0.1\nJETTY_PORT=8983\nJAVA_HOME=$JAVA_HOME" | sudo tee /etc/default/jetty
- sudo cp ckan/config/solr/schema-2.0.xml /etc/solr/conf/schema.xml
- sudo service jetty restart
- paster --plugin=ckan db init
- paster datastore set-permissions postgres
script: "nosetests --ckan --with-pylons=test-core.ini --nologcapture ckan ckanext"
env:
- PGVERSION=9.1
- PGVERSION=8.4
script: ./bin/travis-build
notifications:
irc:
channels:
Expand Down
55 changes: 55 additions & 0 deletions bin/travis-build
@@ -0,0 +1,55 @@
#!/bin/sh

# Drop Travis' postgres cluster if we're building using a different pg version
TRAVIS_PGVERSION='9.1'
if [ $PGVERSION != $TRAVIS_PGVERSION ]
then
sudo -u postgres pg_dropcluster --stop $TRAVIS_PGVERSION main
# Make psql use $PGVERSION
export PGCLUSTER=$PGVERSION/main
fi

# Install postgres and solr
# We need this ppa so we can install postgres-8.4
sudo add-apt-repository -yy ppa:pitti/postgresql
sudo apt-get update -qq
sudo apt-get install solr-jetty postgresql-$PGVERSION

# Don't require a password to access DB
sudo sed -i -e 's/ident/trust/g' /etc/postgresql/$PGVERSION/main/pg_hba.conf

sudo service postgresql reload

pip install -r pip-requirements.txt --use-mirrors
pip install -r pip-requirements-test.txt --use-mirrors

psql -c 'CREATE DATABASE ckantest;' -U postgres
psql -c 'CREATE DATABASE datastore;' -U postgres

python setup.py develop

# Configure CKAN's configuration file
paster make-config ckan development.ini --no-interactive
sed -i -e 's/.*solr_url.*/solr_url = http:\/\/127.0.0.1:8983\/solr/' development.ini
sed -i -e 's/.*ckan\.site_id.*/ckan.site_id = travis_ci/' development.ini
sed -i -e 's/^sqlalchemy.url.*/sqlalchemy.url = postgresql:\/\/postgres@\/ckantest/' development.ini
sed -i -e 's/.*datastore.write_url.*/ckan.datastore.write_url = postgresql:\/\/postgres@\/datastore/' development.ini

# Configure Solr
echo "NO_START=0\nJETTY_HOST=127.0.0.1\nJETTY_PORT=8983\nJAVA_HOME=$JAVA_HOME" | sudo tee /etc/default/jetty
sudo cp ckan/config/solr/schema-2.0.xml /etc/solr/conf/schema.xml
sudo service jetty restart

paster --plugin=ckan db init

# If Postgres >= 9.0, we don't need to use datastore's legacy mode.
if [ $PGVERSION != '8.4' ]
then
psql -c 'CREATE USER readonlyuser;' -U postgres
sed -i -e 's/.*datastore.read_url.*/ckan.datastore.read_url = postgresql:\/\/readonlyuser@\/datastore/' development.ini
paster datastore set-permissions postgres
fi


# And finally, run the tests
nosetests --ckan --with-pylons=test-core.ini --nologcapture ckan ckanext
17 changes: 17 additions & 0 deletions ckan/common.py
@@ -0,0 +1,17 @@
# This file contains commonly used parts of external libraries. The idea is
# to help in removing helpers from being used as a dependency by many files
# but at the same time making it easy to change for example the json lib
# used.
#
# NOTE: This file is specificaly created for
# from ckan.common import x, y, z to be allowed


from pylons.i18n import _, ungettext
from pylons import g, c, request, session, response
import simplejson as json

try:
from collections import OrderedDict # from python 2.7
except ImportError:
from sqlalchemy.util import OrderedDict
27 changes: 19 additions & 8 deletions ckan/config/routing.py
Expand Up @@ -284,12 +284,15 @@ def make_map():
'follow',
'unfollow',
'admins',
'about',
'activity',
]))
)
m.connect('group_activity', '/group/activity/{id}/{offset}', action='activity'),
m.connect('group_read', '/group/{id}', action='read')
m.connect('group_about', '/group/about/{id}', action='about',
ckan_icon='info-sign'),
m.connect('group_activity', '/group/activity/{id}/{offset}',
action='activity', ckan_icon='time'),
m.connect('group_read', '/group/{id}', action='read',
ckan_icon='sitemap')

# organizations these basically end up being the same as groups
with SubMapper(map, controller='organization') as m:
Expand All @@ -298,18 +301,26 @@ def make_map():
m.connect('/organization/new', action='new')
m.connect('/organization/{action}/{id}',
requirements=dict(action='|'.join([
'edit',
'delete',
'admins',
'members',
'member_new',
'member_delete',
'history',
'bulk_process',
'about'
'history'
]))
)
m.connect('organization_activity', '/organization/activity/{id}',
action='activity', ckan_icon='time')
m.connect('organization_read', '/organization/{id}', action='read')
m.connect('organization_about', '/organization/about/{id}',
action='about', ckan_icon='info-sign')
m.connect('organization_read', '/organization/{id}', action='read',
ckan_icon='sitemap')
m.connect('organization_edit', '/organization/edit/{id}',
action='edit', ckan_icon='edit')
m.connect('organization_members', '/organization/members/{id}',
action='members', ckan_icon='group')
m.connect('organization_bulk_process', '/organization/bulk_process/{id}',
action='bulk_process', ckan_icon='sitemap')
register_package_plugins(map)
register_group_plugins(map)

Expand Down
7 changes: 5 additions & 2 deletions ckan/controllers/api.py
Expand Up @@ -832,8 +832,11 @@ def make_unicode(entity):
raise ValueError(msg)
cls.log.debug('Retrieved request body: %r' % request.body)
if not request_data:
msg = "No request body data"
raise ValueError(msg)
if not try_url_params:
msg = "No request body data"
raise ValueError(msg)
else:
request_data = {}
if request_data:
try:
request_data = h.json.loads(request_data, encoding='utf8')
Expand Down
12 changes: 6 additions & 6 deletions ckan/controllers/feed.py
Expand Up @@ -29,7 +29,7 @@

from ckan import model
from ckan.lib.base import BaseController, c, request, response, json, abort, g
from ckan.lib.helpers import date_str_to_datetime, url_for
import ckan.lib.helpers as h
from ckan.logic import get_action, NotFound

# TODO make the item list configurable
Expand Down Expand Up @@ -348,18 +348,18 @@ def output_feed(self, results, feed_title, feed_description,
for pkg in results:
feed.add_item(
title=pkg.get('title', ''),
link=self.base_url + url_for(controller='package',
link=self.base_url + h.url_for(controller='package',
action='read',
id=pkg['id']),
description=pkg.get('notes', ''),
updated=date_str_to_datetime(pkg.get('metadata_modified')),
published=date_str_to_datetime(pkg.get('metadata_created')),
updated=h.date_str_to_datetime(pkg.get('metadata_modified')),
published=h.date_str_to_datetime(pkg.get('metadata_created')),
unique_id=_create_atom_id(u'/dataset/%s' % pkg['id']),
author_name=pkg.get('author', ''),
author_email=pkg.get('author_email', ''),
categories=[t['name'] for t in pkg.get('tags', [])],
enclosure=webhelpers.feedgenerator.Enclosure(
self.base_url + url_for(controller='api',
self.base_url + h.url_for(controller='api',
register='package',
action='show',
id=pkg['name'],
Expand All @@ -377,7 +377,7 @@ def _feed_url(self, query, controller, action, **kwargs):
Constructs the url for the given action. Encoding the query
parameters.
"""
path = url_for(controller=controller, action=action, **kwargs)
path = h.url_for(controller=controller, action=action, **kwargs)
query = [(k, v.encode('utf-8') if isinstance(v, basestring)
else str(v)) for k, v in query.items()]

Expand Down
51 changes: 42 additions & 9 deletions ckan/controllers/group.py
Expand Up @@ -4,11 +4,11 @@
import datetime
from urllib import urlencode

from ckan.lib.base import BaseController, c, model, request, render, h, g
from ckan.lib.base import BaseController, c, model, request, render, g
from ckan.lib.base import ValidationException, abort, gettext
import ckan.lib.base as base
from pylons.i18n import get_lang, _
from ckan.lib.helpers import Page
import ckan.lib.helpers as h
import ckan.lib.maintain as maintain
from ckan.lib.navl.dictization_functions import DataError, unflatten, validate
from ckan.logic import NotFound, NotAuthorized, ValidationError
Expand All @@ -19,6 +19,12 @@
import ckan.new_authz

from ckan.lib.plugins import lookup_group_plugin
import ckan.plugins as plugins

try:
from collections import OrderedDict # 2.7
except ImportError:
from sqlalchemy.util import OrderedDict

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -62,6 +68,9 @@ def _history_template(self, group_type):
def _edit_template(self, group_type):
return lookup_group_plugin(group_type).edit_template()

def _activity_template(self, group_type):
return lookup_group_plugin(group_type).activity_template()

def _admins_template(self, group_type):
return lookup_group_plugin(group_type).admins_template()

Expand Down Expand Up @@ -143,7 +152,7 @@ def index(self):

results = self._action('group_list')(context, data_dict)

c.page = Page(
c.page = h.Page(
collection=results,
page=request.params.get('page', 1),
url=h.pager_url,
Expand Down Expand Up @@ -271,10 +280,37 @@ def pager_url(q=None, page=None):
fq = ''
context['ignore_capacity_check'] = True

facets = OrderedDict()

default_facet_titles = {'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('Licence'), }

for facet in g.facets:
if facet in default_facet_titles:
facets[facet] = default_facet_titles[facet]
else:
facets[facet] = facet

# Facet titles
for plugin in plugins.PluginImplementations(plugins.IFacets):
if self.group_type == 'organization':
facets = plugin.organization_facets(
facets, self.group_type, None)
else:
facets = plugin.group_facets(
facets, self.group_type, None)

if 'capacity' in facets and (self.group_type != 'organization' or not user_member_of_orgs):
del facets['capacity']

c.facet_titles = facets

data_dict = {
'q': q,
'fq': fq,
'facet.field': g.facets,
'facet.field': facets.keys(),
'rows': limit,
'sort': sort_by,
'start': (page - 1) * limit,
Expand All @@ -297,10 +333,6 @@ def pager_url(q=None, page=None):
'Use `c.search_facets` instead.')

c.search_facets = query['search_facets']
c.facet_titles = {'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('Licence'), }
c.search_facets_limits = {}
for facet in c.facets.keys():
limit = int(request.params.get('_%s_limit' % facet, 10))
Expand Down Expand Up @@ -725,7 +757,8 @@ def activity(self, id, offset=0):
c.group_activity_stream = get_action('group_activity_list_html')(
context, {'id': c.group_dict['id'], 'offset': offset})

return render('group/activity_stream.html')
#return render('group/activity_stream.html')
return render(self._activity_template(c.group_dict['type']))

def follow(self, id):
'''Start following this group.'''
Expand Down
3 changes: 3 additions & 0 deletions ckan/controllers/organization.py
Expand Up @@ -52,5 +52,8 @@ def _history_template(self, group_type):
def _edit_template(self, group_type):
return 'organization/edit.html'

def _activity_template(self, group_type):
return 'organization/activity_stream.html'

def _guess_group_type(self, expecting_name=False):
return 'organization'

0 comments on commit d0f8e93

Please sign in to comment.