Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/okfn/ckan
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Aug 20, 2012
2 parents 3cdc239 + eae560d commit 0d316e5
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 42 deletions.
2 changes: 1 addition & 1 deletion ckan/controllers/feed.py
Expand Up @@ -432,7 +432,7 @@ def _parse_url_params(self):
"""

try:
page = int(request.params.get('page', 1))
page = int(request.params.get('page', 1)) or 1
except ValueError:
abort(400, ('"page" parameter must be an integer'))

Expand Down
6 changes: 6 additions & 0 deletions ckan/controllers/package.py
Expand Up @@ -890,6 +890,12 @@ def _parse_recline_state(self, params):
recline_state.pop('height', None)
recline_state['readOnly'] = True

# previous versions of recline setup used elasticsearch_url attribute
# for data api url - see http://trac.ckan.org/ticket/2639
# fix by relocating this to url attribute which is the default location
if 'dataset' in recline_state and 'elasticsearch_url' in recline_state['dataset']:
recline_state['dataset']['url'] = recline_state['dataset']['elasticsearch_url']

# Ensure only the currentView is available
# default to grid view if none specified
if not recline_state.get('currentView', None):
Expand Down
6 changes: 3 additions & 3 deletions ckan/controllers/related.py
Expand Up @@ -28,7 +28,7 @@ def dashboard(self):
try:
page = int(base.request.params.get('page', 1))
except ValueError, e:
abort(400, ('"page" parameter must be an integer'))
base.abort(400, ('"page" parameter must be an integer'))

# Update ordering in the context
query = logic.get_action('related_list')(context,data_dict)
Expand Down Expand Up @@ -67,12 +67,12 @@ def read(self, id):
try:
logic.check_access('related_show', context, data_dict)
except logic.NotAuthorized:
abort(401, _('Not authorized to see this page'))
base.abort(401, _('Not authorized to see this page'))

related = model.Session.query(model.Related).\
filter(model.Related.id == id).first()
if not related:
abort(404, _('The requested related item was not found'))
base.abort(404, _('The requested related item was not found'))

related.view_count = model.Related.view_count + 1

Expand Down
2 changes: 1 addition & 1 deletion ckan/controllers/storage.py
Expand Up @@ -187,7 +187,7 @@ def file(self, label):
fapp = FileApp(filepath, headers=None, **headers)
return fapp(request.environ, self.start_response)
else:
h.redirect_to(file_url)
h.redirect_to(file_url.encode('ascii','ignore'))


class StorageAPIController(BaseController):
Expand Down
2 changes: 0 additions & 2 deletions ckan/lib/create_test_data.py
Expand Up @@ -868,7 +868,6 @@ def make_some_vocab_tags(cls):
'tolstoy',
"Dave's books",
"Roger's books",
'Other (Open)',
'romantic novel',
'book',
'123',
Expand All @@ -889,7 +888,6 @@ def make_some_vocab_tags(cls):
'tolstoy': 'Tolstoi',
"Dave's books": 'Daves Bucher',
"Roger's books": 'Rogers Bucher',
'Other (Open)': 'Andere (Open)',
'romantic novel': 'Liebesroman',
'book': 'Buch',
'456': 'Realismus',
Expand Down
2 changes: 2 additions & 0 deletions ckan/lib/mailer.py
Expand Up @@ -95,6 +95,8 @@ def send_reset_link(user):
mail_user(user, _('Reset your password'), body)

def verify_reset_link(user, key):
if not key:
return False
if not user.reset_key or len(user.reset_key) < 5:
return False
return key.strip() == user.reset_key
Expand Down
6 changes: 5 additions & 1 deletion ckan/model/license.py
Expand Up @@ -153,7 +153,11 @@ class DefaultLicense(dict):
def __getitem__(self, key):
''' behave like a dict but get from attributes '''
if key in self.keys:
return unicode(getattr(self, key))
value = getattr(self, key)
if isinstance(value, str):
return unicode(value)
else:
return value
else:
raise KeyError()

Expand Down
8 changes: 7 additions & 1 deletion ckan/public/scripts/application.js
Expand Up @@ -1493,7 +1493,13 @@ CKAN.DataPreview = function ($, my) {
my.$dialog.html('<h4>Loading ... <img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" class="loading-spinner" /></h4>');

// Restore the Dataset from the given reclineState.
var dataset = recline.Model.Dataset.restore(reclineState);
var datasetInfo = _.extend({
url: reclineState.url,
backend: reclineState.backend
},
reclineState.dataset
);
var dataset = new recline.Model.Dataset(datasetInfo);

// Only create the view defined in reclineState.currentView.
// TODO: tidy this up.
Expand Down
50 changes: 18 additions & 32 deletions ckan/public/scripts/vendor/recline/recline.js
Expand Up @@ -1181,36 +1181,6 @@ my.Dataset = Backbone.Model.extend({
});


// ### Dataset.restore
//
// Restore a Dataset instance from a serialized state. Serialized state for a
// Dataset is an Object like:
//
// <pre>
// {
// backend: {backend type - i.e. value of dataset.backend.__type__}
// dataset: {dataset info needed for loading -- result of dataset.toJSON() would be sufficient but can be simpler }
// // convenience - if url provided and dataste not this be used as dataset url
// url: {dataset url}
// ...
// }
my.Dataset.restore = function(state) {
var dataset = null;
// hack-y - restoring a memory dataset does not mean much ...
if (state.backend === 'memory') {
var datasetInfo = {
records: [{stub: 'this is a stub dataset because we do not restore memory datasets'}]
};
} else {
var datasetInfo = {
url: state.url,
backend: state.backend
};
}
dataset = new recline.Model.Dataset(datasetInfo);
return dataset;
};

// ## <a id="record">A Record</a>
//
// A single record (or row) in the dataset
Expand Down Expand Up @@ -3055,6 +3025,7 @@ my.MultiView = Backbone.View.extend({
'view-graph': graphState,
backend: this.model.backend.__type__,
url: this.model.get('url'),
dataset: this.model.toJSON(),
currentView: null,
readOnly: false
},
Expand Down Expand Up @@ -3147,16 +3118,31 @@ my.MultiView = Backbone.View.extend({
// ### MultiView.restore
//
// Restore a MultiView instance from a serialized state including the associated dataset
//
// This inverts the state serialization process in Multiview
my.MultiView.restore = function(state) {
var dataset = recline.Model.Dataset.restore(state);
// hack-y - restoring a memory dataset does not mean much ... (but useful for testing!)
if (state.backend === 'memory') {
var datasetInfo = {
backend: 'memory',
records: [{stub: 'this is a stub dataset because we do not restore memory datasets'}]
};
} else {
var datasetInfo = _.extend({
url: state.url,
backend: state.backend
},
state.dataset
);
}
var dataset = new recline.Model.Dataset(datasetInfo);
var explorer = new my.MultiView({
model: dataset,
state: state
});
return explorer;
}


// ## Miscellaneous Utilities
var urlPathRegex = /^([^?]+)(\?.*)?/;

Expand Down
14 changes: 14 additions & 0 deletions ckan/tests/functional/test_group.py
Expand Up @@ -58,6 +58,20 @@ def setup_class(self):
def teardown_class(self):
model.repo.rebuild_db()

def test_atom_feed_page_zero(self):
group_name = 'deletetest'
CreateTestData.create_groups([{'name': group_name,
'packages': []}],
admin_user_name='russianfan')

offset = url_for(controller='feed', action='group',
id=group_name)
offset = offset + '?page=0'
res = self.app.get(offset)
assert '<feed' in res, res
assert 'xmlns="http://www.w3.org/2005/Atom"' in res, res
assert '</feed>' in res, res

def test_children(self):
if model.engine_is_sqlite() :
from nose import SkipTest
Expand Down
9 changes: 9 additions & 0 deletions ckan/tests/functional/test_user.py
Expand Up @@ -965,6 +965,15 @@ def test_perform_reset_user_password_link_key_incorrect(self):
key='randomness') # i.e. incorrect
res = self.app.get(offset, status=403) # error

def test_perform_reset_user_password_link_key_missing(self):
CreateTestData.create_user(name='jack', password='test1')
user = model.User.by_name(u'jack')
offset = url_for(controller='user',
action='perform_reset',
id=user.id) # not, no key specified
res = self.app.get(offset, status=403) # error


def test_perform_reset_user_password_link_user_incorrect(self):
# Make up a key - i.e. trying to hack this
user = model.User.by_name(u'jack')
Expand Down
1 change: 0 additions & 1 deletion ckanext/multilingual/tests/test_multilingual_plugin.py
Expand Up @@ -67,7 +67,6 @@ def test_dataset_read_translation(self):
'tolstoy',
"Dave's books",
"Roger's books",
'Other (Open)',
'romantic novel',
'book',
'123',
Expand Down

0 comments on commit 0d316e5

Please sign in to comment.