Skip to content

Commit

Permalink
Merge branch 'master' into 960-dont-use-api_url
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Nov 5, 2013
2 parents 500733e + cba4e6c commit 38ed0ae
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 283 deletions.
10 changes: 8 additions & 2 deletions ckan/controllers/group.py
Expand Up @@ -278,7 +278,8 @@ def pager_url(q=None, page=None):

facets = OrderedDict()

default_facet_titles = {'groups': _('Groups'),
default_facet_titles = {'organization': _('Organizations'),
'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license_id': _('License')}
Expand Down Expand Up @@ -344,6 +345,9 @@ def pager_url(q=None, page=None):
c.facets = {}
c.page = h.Page(collection=[])

self._setup_template_variables(context, {'id':id},
group_type=group_type)

def bulk_process(self, id):
''' Allow bulk processing of datasets for an organization. Make
private/public or delete. For organization admins.'''
Expand Down Expand Up @@ -828,7 +832,9 @@ def admins(self, id):

def about(self, id):
c.group_dict = self._get_group_dict(id)
return render(self._about_template(c.group_dict['type']))
group_type = c.group_dict['type']
self._setup_template_variables({}, {'id': id}, group_type=group_type)
return render(self._about_template(group_type))

def _get_group_dict(self, id):
''' returns the result of group_show action or aborts if there is a
Expand Down
1 change: 1 addition & 0 deletions ckan/controllers/home.py
Expand Up @@ -67,6 +67,7 @@ def index(self):
c.search_facets = query['search_facets']

c.facet_titles = {
'organization': _('Organizations'),
'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
Expand Down
41 changes: 0 additions & 41 deletions ckan/controllers/organization.py
Expand Up @@ -15,46 +15,5 @@ class OrganizationController(group.GroupController):
# this makes us use organization actions
group_type = 'organization'

def _group_form(self, group_type=None):
return 'organization/new_organization_form.html'

def _form_to_db_schema(self, group_type=None):
return group.lookup_group_plugin(group_type).form_to_db_schema()

def _db_to_form_schema(self, group_type=None):
'''This is an interface to manipulate data from the database
into a format suitable for the form (optional)'''
pass

def _setup_template_variables(self, context, data_dict, group_type=None):
pass

def _new_template(self, group_type):
return 'organization/new.html'

def _about_template(self, group_type):
return 'organization/about.html'

def _index_template(self, group_type):
return 'organization/index.html'

def _admins_template(self, group_type):
return 'organization/admins.html'

def _bulk_process_template(self, group_type):
return 'organization/bulk_process.html'

def _read_template(self, group_type):
return 'organization/read.html'

def _history_template(self, group_type):
return group.lookup_group_plugin(group_type).history_template()

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'
8 changes: 8 additions & 0 deletions ckan/lib/cli.py
Expand Up @@ -10,6 +10,8 @@
import ckan.include.rcssmin as rcssmin
import ckan.lib.fanstatic_resources as fanstatic_resources
import sqlalchemy as sa
import urlparse
import routes

import paste.script
from paste.registry import Registry
Expand Down Expand Up @@ -99,6 +101,12 @@ def _load_config(self):
self.translator_obj = MockTranslator()
self.registry.register(pylons.translator, self.translator_obj)

## give routes enough information to run url_for
parsed = urlparse.urlparse(conf.get('ckan.site_url', 'http://0.0.0.0'))
request_config = routes.request_config()
request_config.host = parsed.netloc + parsed.path
request_config.protocol = parsed.scheme

def _setup_app(self):
cmd = paste.script.appinstall.SetupCommand('setup-app')
cmd.run([self.filename])
Expand Down
3 changes: 2 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -597,7 +597,8 @@ def get_facet_title(name):
if config_title:
return config_title

facet_titles = {'groups': _('Groups'),
facet_titles = {'organization': _('Organizations'),
'groups': _('Groups'),
'tags': _('Tags'),
'res_format': _('Formats'),
'license': _('License'), }
Expand Down
39 changes: 38 additions & 1 deletion ckan/lib/plugins.py
Expand Up @@ -53,7 +53,8 @@ def lookup_group_plugin(group_type=None):
"""
if group_type is None:
return _default_group_plugin
return _group_plugins.get(group_type, _default_group_plugin)
return _group_plugins.get(group_type, _default_organization_plugin
if group_type == 'organization' else _default_group_plugin)


def register_package_plugins(map):
Expand Down Expand Up @@ -418,3 +419,39 @@ def setup_template_variables(self, context, data_dict):
c.auth_for_change_state = True
except logic.NotAuthorized:
c.auth_for_change_state = False


class DefaultOrganizationForm(DefaultGroupForm):
def group_form(self):
return 'organization/new_organization_form.html'

def setup_template_variables(self, context, data_dict):
pass

def new_template(self):
return 'organization/new.html'

def about_template(self):
return 'organization/about.html'

def index_template(self):
return 'organization/index.html'

def admins_template(self):
return 'organization/admins.html'

def bulk_process_template(self):
return 'organization/bulk_process.html'

def read_template(self):
return 'organization/read.html'

# don't override history_template - use group template for history

def edit_template(self):
return 'organization/edit.html'

def activity_template(self):
return 'organization/activity_stream.html'

_default_organization_plugin = DefaultOrganizationForm()
7 changes: 5 additions & 2 deletions ckan/logic/action/get.py
Expand Up @@ -91,8 +91,11 @@ def package_list(context, data_dict):
col = (package_revision_table.c.id
if api == 2 else package_revision_table.c.name)
query = _select([col])
query = query.where(_and_(package_revision_table.c.state=='active',
package_revision_table.c.current==True))
query = query.where(_and_(
package_revision_table.c.state=='active',
package_revision_table.c.current==True,
package_revision_table.c.private==False,
))
query = query.order_by(col)

limit = data_dict.get('limit')
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/action/update.py
Expand Up @@ -132,7 +132,7 @@ def related_update(context, data_dict):
id = _get_or_bust(data_dict, "id")

session = context['session']
schema = context.get('schema') or schema_.default_related_schema()
schema = context.get('schema') or schema_.default_update_related_schema()

related = model.Related.get(id)
context["related"] = related
Expand Down
9 changes: 9 additions & 0 deletions ckan/logic/schema.py
Expand Up @@ -332,6 +332,15 @@ def default_related_schema():
return schema


def default_update_related_schema():
schema = default_related_schema()
schema['id'] = [not_empty, unicode]
schema['title'] = [ignore_missing, unicode]
schema['type'] = [ignore_missing, unicode]
schema['owner_id'] = [ignore_missing, unicode]
return schema


def default_extras_schema():

schema = {
Expand Down
96 changes: 96 additions & 0 deletions ckan/tests/logic/test_action.py
Expand Up @@ -84,6 +84,36 @@ def test_01_package_list(self):
assert 'warandpeace' in res['result']
assert 'annakarenina' in res['result']

def test_01_package_list_private(self):
tests.call_action_api(self.app, 'organization_create',
name='test_org_2',
apikey=self.sysadmin_user.apikey)

tests.call_action_api(self.app, 'package_create',
name='public_dataset',
owner_org='test_org_2',
apikey=self.sysadmin_user.apikey)

res = tests.call_action_api(self.app, 'package_list')

assert len(res) == 3
assert 'warandpeace' in res
assert 'annakarenina' in res
assert 'public_dataset' in res

tests.call_action_api(self.app, 'package_create',
name='private_dataset',
owner_org='test_org_2',
private=True,
apikey=self.sysadmin_user.apikey)

res = tests.call_action_api(self.app, 'package_list')
assert len(res) == 3
assert 'warandpeace' in res
assert 'annakarenina' in res
assert 'public_dataset' in res
assert not 'private_dataset' in res

def test_01_current_package_list_with_resources(self):
url = '/api/action/current_package_list_with_resources'

Expand Down Expand Up @@ -1975,3 +2005,69 @@ def _assert_we_can_add_user_to_group(self, user_id, group_id):
group_ids = [g.id for g in groups]
assert res['success'] is True, res
assert group.id in group_ids, (group, user_groups)


class TestRelatedAction(WsgiAppCase):

sysadmin_user = None

normal_user = None

@classmethod
def setup_class(cls):
search.clear()
CreateTestData.create()
cls.sysadmin_user = model.User.get('testsysadmin')

@classmethod
def teardown_class(cls):
model.repo.rebuild_db()

def _add_basic_package(self, package_name=u'test_package', **kwargs):
package = {
'name': package_name,
'title': u'A Novel By Tolstoy',
'resources': [{
'description': u'Full text.',
'format': u'plain text',
'url': u'http://www.annakarenina.com/download/'
}]
}
package.update(kwargs)

postparams = '%s=1' % json.dumps(package)
res = self.app.post('/api/action/package_create', params=postparams,
extra_environ={'Authorization': 'tester'})
return json.loads(res.body)['result']

def test_update_add_related_item(self):
package = self._add_basic_package()
related_item = {
"description": "Testing a Description",
"url": "http://example.com/image.png",
"title": "Testing",
"featured": 0,
"image_url": "http://example.com/image.png",
"type": "idea",
"dataset_id": package['id'],
}
related_item_json = json.dumps(related_item)
res_create = self.app.post('/api/action/related_create',
params=related_item_json,
extra_environ={'Authorization': 'tester'})
assert res_create.json['success']

related_update = res_create.json['result']
related_update = {'id': related_update['id'], 'title': 'Updated'}
related_update_json = json.dumps(related_update)
res_update = self.app.post('/api/action/related_update',
params=related_update_json,
extra_environ={'Authorization': 'tester'})
assert res_update.json['success']
res_update_json = res_update.json['result']
assert res_update_json['title'] == related_update['title']

related_item.pop('title')
related_item.pop('dataset_id')
for field in related_item:
assert related_item[field] == res_update_json[field]
1 change: 0 additions & 1 deletion ckan/tests/test_coding_standards.py
Expand Up @@ -828,7 +828,6 @@ class TestPep8(object):
'ckanext/example_idatasetform/plugin.py',
'ckanext/example_itemplatehelpers/plugin.py',
'ckanext/multilingual/plugin.py',
'ckanext/multilingual/tests/test_multilingual_plugin.py',
'ckanext/reclinepreview/plugin.py',
'ckanext/reclinepreview/tests/test_preview.py',
'ckanext/resourceproxy/plugin.py',
Expand Down
3 changes: 2 additions & 1 deletion ckanext/multilingual/plugin.py
@@ -1,7 +1,7 @@
import sets
import ckan
from ckan.plugins import SingletonPlugin, implements, IPackageController
from ckan.plugins import IGroupController, ITagController
from ckan.plugins import IGroupController, IOrganizationController, ITagController
import pylons
import ckan.logic.action.get as action_get
from pylons import config
Expand Down Expand Up @@ -253,6 +253,7 @@ class MultilingualGroup(SingletonPlugin):
'''
implements(IGroupController, inherit=True)
implements(IOrganizationController, inherit=True)

def before_view(self, data_dict):
translated_data_dict = translate_data_dict(data_dict)
Expand Down

0 comments on commit 38ed0ae

Please sign in to comment.