Skip to content

Commit

Permalink
Merge branch 'master' into 766
Browse files Browse the repository at this point in the history
Conflicts:
	bin/travis-install-dependencies
  • Loading branch information
vitorbaptista committed Oct 22, 2013
2 parents 852a23c + 3d36ae1 commit 809f6b6
Show file tree
Hide file tree
Showing 29 changed files with 257 additions and 151 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
@@ -0,0 +1,3 @@
[run]
omit = /ckan/migration/*, /ckan/tests/*, */tests/*
source = ckan, ckanext
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -15,3 +15,5 @@ notifications:
on_failure: change
template:
- "%{repository} %{branch} %{commit} %{build_url} %{author}: %{message}"
after_success:
- coveralls
4 changes: 4 additions & 0 deletions README.rst
Expand Up @@ -5,6 +5,10 @@ CKAN: The Open Source Data Portal Software
:target: http://travis-ci.org/okfn/ckan
:alt: Build Status

.. image:: https://coveralls.io/repos/okfn/ckan/badge.png
:target: https://coveralls.io/r/okfn/ckan
:alt: Test coverage

**CKAN is the world’s leading open-source data portal platform**.
CKAN makes it easy to publish, share and work with data. It's a data management
system that provides a powerful platform for cataloging, storing and accessing
Expand Down
2 changes: 1 addition & 1 deletion ckan/config/environment.py
Expand Up @@ -159,7 +159,7 @@ def find_controller(self, controller):
'''
This code is based on Genshi code
Copyright © 2006-2012 Edgewall Software
Copyright © 2006-2012 Edgewall Software
All rights reserved.
Redistribution and use in source and binary forms, with or
Expand Down
9 changes: 6 additions & 3 deletions ckan/config/routing.py
Expand Up @@ -222,7 +222,6 @@ def make_map():
])))
m.connect('/dataset/{action}/{id}',
requirements=dict(action='|'.join([
'edit',
'new_metadata',
'new_resource',
'history',
Expand All @@ -234,20 +233,24 @@ def make_map():
'delete',
'api_data',
])))
m.connect('dataset_edit', '/dataset/edit/{id}', action='edit',
ckan_icon='edit')
m.connect('dataset_followers', '/dataset/followers/{id}',
action='followers', ckan_icon='group')
m.connect('dataset_activity', '/dataset/activity/{id}',
action='activity', ckan_icon='time')
m.connect('/dataset/activity/{id}/{offset}', action='activity')
m.connect('/dataset/{id}.{format}', action='read')
m.connect('dataset_resources', '/dataset/resources/{id}',
action='resources', ckan_icon='reorder')
m.connect('dataset_read', '/dataset/{id}', action='read',
ckan_icon='sitemap')
m.connect('/dataset/{id}/resource/{resource_id}',
action='resource_read')
m.connect('/dataset/{id}/resource_delete/{resource_id}',
action='resource_delete')
m.connect('/dataset/{id}/resource_edit/{resource_id}',
action='resource_edit')
m.connect('resource_edit', '/dataset/{id}/resource_edit/{resource_id}',
action='resource_edit', ckan_icon='edit')
m.connect('/dataset/{id}/resource/{resource_id}/download',
action='resource_download')
m.connect('/dataset/{id}/resource/{resource_id}/embed',
Expand Down
41 changes: 39 additions & 2 deletions ckan/controllers/package.py
Expand Up @@ -19,6 +19,7 @@
import ckan.lib.datapreview as datapreview
import ckan.lib.plugins
import ckan.plugins as p
import ckan.lib.render

from ckan.common import OrderedDict, _, json, request, c, g, response
from home import CACHE_PARAMETERS
Expand Down Expand Up @@ -301,6 +302,31 @@ def _content_type_from_accept(self):
ct, mu, ext = accept.parse_header(request.headers.get('Accept', ''))
return ct, ext, (NewTextTemplate, MarkupTemplate)[mu]

def resources(self, id):
package_type = self._get_package_type(id.split('@')[0])
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True,
'auth_user_obj': c.userobj}
data_dict = {'id': id}

try:
check_access('package_update', context)
except NotAuthorized, e:
abort(401, _('User %r not authorized to edit %s') % (c.user, id))
# check if package exists
try:
c.pkg_dict = get_action('package_show')(context, data_dict)
c.pkg = context['package']
except NotFound:
abort(404, _('Dataset not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read package %s') % id)

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

return render('package/resources.html')

def read(self, id, format='html'):
if not format == 'html':
ctype, extension, loader = \
Expand Down Expand Up @@ -366,7 +392,15 @@ def read(self, id, format='html'):
template = self._read_template(package_type)
template = template[:template.index('.') + 1] + format

return render(template, loader_class=loader)
try:
return render(template, loader_class=loader)
except ckan.lib.render.TemplateNotFound:
msg = _("Viewing {package_type} datasets in {format} format is "
"not supported (template file {file} not found).".format(
package_type=package_type, format=format, file=template))
abort(404, msg)

assert False, "We should never get here"

def history(self, id):
package_type = self._get_package_type(id.split('@')[0])
Expand Down Expand Up @@ -666,11 +700,14 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
abort(404, _('The dataset {id} could not be found.').format(id=id))
# required for nav menu
vars['pkg_dict'] = pkg_dict
template = 'package/new_resource_not_draft.html'
if pkg_dict['state'] == 'draft':
vars['stage'] = ['complete', 'active']
template = 'package/new_resource.html'
elif pkg_dict['state'] == 'draft-complete':
vars['stage'] = ['complete', 'active', 'complete']
return render('package/new_resource.html', extra_vars=vars)
template = 'package/new_resource.html'
return render(template, extra_vars=vars)

def new_metadata(self, id, data=None, errors=None, error_summary=None):
''' FIXME: This is a temporary action to allow styling of the
Expand Down
7 changes: 3 additions & 4 deletions ckan/controllers/template.py
@@ -1,6 +1,5 @@
from genshi.template.loader import TemplateNotFound

import ckan.lib.base as base
import ckan.lib.render


class TemplateController(base.BaseController):
Expand Down Expand Up @@ -29,11 +28,11 @@ def view(self, url):
"""
try:
return base.render(url)
except TemplateNotFound:
except ckan.lib.render.TemplateNotFound:
if url.endswith('.html'):
base.abort(404)
url += '.html'
try:
return base.render(url)
except TemplateNotFound:
except ckan.lib.render.TemplateNotFound:
base.abort(404)
5 changes: 3 additions & 2 deletions ckan/lib/base.py
Expand Up @@ -128,8 +128,7 @@ def render_template():
try:
template_path, template_type = render_.template_info(template_name)
except render_.TemplateNotFound:
template_type = 'genshi'
template_path = ''
raise

# snippets should not pass the context
# but allow for legacy genshi templates
Expand Down Expand Up @@ -227,6 +226,8 @@ def render_template():
raise ckan.exceptions.CkanUrlException(
'\nAn Exception has been raised for template %s\n%s' %
(template_name, e.message))
except render_.TemplateNotFound:
raise


class ValidationException(Exception):
Expand Down
6 changes: 0 additions & 6 deletions ckan/lib/cli.py
Expand Up @@ -842,25 +842,21 @@ def show(self, dataset_ref):
pprint.pprint(dataset.as_dict())

def delete(self, dataset_ref):
from ckan import plugins
import ckan.model as model
dataset = self._get_dataset(dataset_ref)
old_state = dataset.state

plugins.load('synchronous_search')
rev = model.repo.new_revision()
dataset.delete()
model.repo.commit_and_remove()
dataset = self._get_dataset(dataset_ref)
print '%s %s -> %s' % (dataset.name, old_state, dataset.state)

def purge(self, dataset_ref):
from ckan import plugins
import ckan.model as model
dataset = self._get_dataset(dataset_ref)
name = dataset.name

plugins.load('synchronous_search')
rev = model.repo.new_revision()
dataset.purge()
model.repo.commit_and_remove()
Expand Down Expand Up @@ -1286,8 +1282,6 @@ class CreateTestDataCommand(CkanCommand):
def command(self):
self._load_config()
self._setup_app()
from ckan import plugins
plugins.load('synchronous_search') # so packages get indexed
from create_test_data import CreateTestData

if self.args:
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/auth/create.py
Expand Up @@ -23,7 +23,7 @@ def package_create(context, data_dict=None):

# If an organization is given are we able to add a dataset to it?
data_dict = data_dict or {}
org_id = data_dict.get('organization_id')
org_id = data_dict.get('owner_org')
if org_id and not new_authz.has_user_permission_for_group_or_org(
org_id, user, 'create_dataset'):
return {'success': False, 'msg': _('User %s not authorized to add dataset to this organization') % user}
Expand Down
5 changes: 4 additions & 1 deletion ckan/new_authz.py
Expand Up @@ -243,7 +243,10 @@ def has_user_permission_for_group_or_org(group_id, user_name, permission):
''' Check if the user has the given permission for the group '''
if not group_id:
return False
group_id = model.Group.get(group_id).id
group = model.Group.get(group_id)
if not group:
return False
group_id = group.id

# Sys admins can do anything
if is_sysadmin(user_name):
Expand Down
9 changes: 9 additions & 0 deletions ckan/plugins/interfaces.py
Expand Up @@ -769,6 +769,15 @@ def read_template(self):
The path should be relative to the plugin's templates dir, e.g.
``'package/read.html'``.
If the user requests the dataset in a format other than HTML
(CKAN supports returning datasets in RDF or N3 format by appending .rdf
or .n3 to the dataset read URL, see :doc:`linked-data-and-rdf`) then
CKAN will try to render
a template file with the same path as returned by this function,
but a different filename extension, e.g. ``'package/read.rdf'``.
If your extension doesn't have this RDF version of the template
file, the user will get a 404 error.
:rtype: string
'''
Expand Down
2 changes: 1 addition & 1 deletion ckan/plugins/toolkit.py
Expand Up @@ -348,7 +348,7 @@ def _requires_ckan_version(cls, min_version, max_version=None):
else:
error = 'Requires ckan version between %s and %s' % \
(min_version, max_version)
raise cls.CkanVersionException(error)
raise CkanVersionException(error)

def __getattr__(self, name):
''' return the function/object requested '''
Expand Down
15 changes: 8 additions & 7 deletions ckan/templates/group/snippets/helper.html
Expand Up @@ -4,12 +4,13 @@ <h2 class="module-heading">
{{ _('What are Groups?') }}
</h2>
<div class="module-content">
{% trans %}
<p>Groups allow you to group together datasets under a community (for
example, Civil Liberty data) or topic (e.g. Transport, Health,
Environment) to make it easier for users to browse datasets by theme.
Datasets can be part of a group, but do not belong to the group for
editing or authorisation purposes.</p>
{% endtrans %}
<p>
{% trans %}
You can use CKAN Groups to create and manage collections of datasets.
This could be to catalogue datasets for a particular project or team,
or on a particular theme, or as a very simple way to help people find
and search your own published datasets.
{% endtrans %}
</p>
</div>
</div>
16 changes: 7 additions & 9 deletions ckan/templates/organization/snippets/helper.html
Expand Up @@ -4,14 +4,12 @@ <h2 class="module-heading">
{{ _('What are Organizations?') }}
</h2>
<div class="module-content">
{% trans %}
<p>Organizations act like publishing departments for datasets (for
example, the Department of Health). This means that datasets can be
published by and belong to a department instead of an individual
user.</p>
<p>Within organizations, admins can assign roles and authorisation its
members, giving individual users the right to publish datasets from
that particular organisation (e.g. Office of National Statistics).</p>
{% endtrans %}
<p>
{% trans %}
CKAN Organizations are used to create, manage and publish collections
of datasets. Users can have different roles within an Organization,
depending on their level of authorisation to create, edit and publish.
{% endtrans %}
</p>
</div>
</div>
6 changes: 3 additions & 3 deletions ckan/templates/package/base_form_page.html
Expand Up @@ -15,9 +15,9 @@ <h2 class="module-heading"><i class="icon-info-sign"></i> {{ _('What are dataset
<div class="module-content">
<p>
{% trans %}
Datasets are simply used to group related pieces of data. These
can then be found under a single url with a description and
licensing information.
A CKAN Dataset is a collection of data resources (such as files),
together with a description and other information, at a fixed URL.
Datasets are what users see when searching for data.
{% endtrans %}
</p>
</div>
Expand Down
29 changes: 4 additions & 25 deletions ckan/templates/package/edit.html
@@ -1,28 +1,7 @@
{% extends 'package/base_form_page.html' %}
{% extends 'package/edit_base.html' %}

{% set pkg = c.pkg_dict %}
{% block subtitle %}{{ _('Edit') }} - {{ h.dataset_display_name(pkg) }}{% endblock %}

{% block breadcrumb_content_selected %}{% endblock %}

{% block breadcrumb_content %}
{{ super() }}
<li class="active">{% link_for _('Edit'), controller='package', action='edit', id=pkg.name %}</li>
{% endblock %}

{% block resources_module %}
{% snippet 'package/snippets/resources.html', pkg=pkg, action='resource_edit' %}
{% endblock %}

{% block content_action %}
{% link_for _('View dataset'), controller='package', action='read', id=pkg.name, class_='btn', icon='eye-open' %}
{% block primary_content_inner %}
{% block form %}{{ c.form | safe }}{% endblock %}
{% endblock %}

{% block secondary_content %}
{% snippet 'package/snippets/info.html', pkg=pkg, action='package_edit' %}
{% endblock %}

{% block primary_content %}
<header class="module-content page-header"></header>
{{ super() }}
{% endblock %}

23 changes: 23 additions & 0 deletions ckan/templates/package/edit_base.html
@@ -0,0 +1,23 @@
{% extends 'package/base.html' %}

{% set pkg = c.pkg_dict %}

{% block breadcrumb_content_selected %}{% endblock %}

{% block breadcrumb_content %}
{{ super() }}
<li class="active">{% link_for _('Edit'), controller='package', action='edit', id=pkg.name %}</li>
{% endblock %}

{% block content_action %}
{% link_for _('View dataset'), controller='package', action='read', id=pkg.name, class_='btn', icon='eye-open' %}
{% endblock %}

{% block content_primary_nav %}
{{ h.build_nav_icon('dataset_edit', _('Edit metadata'), id=pkg.name) }}
{{ h.build_nav_icon('dataset_resources', _('Resources'), id=pkg.name) }}
{% endblock %}

{% block secondary_content %}
{% snippet 'package/snippets/info.html', pkg=pkg, hide_follow_button=true %}
{% endblock %}

0 comments on commit 809f6b6

Please sign in to comment.