Skip to content

Commit

Permalink
Merge branch 'master' into feature-2347-related-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Jul 11, 2012
2 parents cab9e7d + 16a6895 commit 66aa4f1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
4 changes: 4 additions & 0 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -102,6 +102,10 @@ def resource_dictize(res, context):
model = context['model']
tracking = model.TrackingSummary.get_for_resource(res.url)
resource['tracking_summary'] = tracking
# some urls do not have the protocol this adds http:// to these
url = resource['url']
if not (url.startswith('http://') or url.startswith('https://')):
resource['url'] = u'http://' + url
return resource

def related_dictize(rel, context):
Expand Down
9 changes: 9 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -886,6 +886,14 @@ def dashboard_activity_stream(user_id):
return logic.get_action('dashboard_activity_list_html')(context, {'id': user_id})


def render_markdown(data):
''' returns the data as rendered markdown '''
# cope with data == None
if not data:
return ''
return literal(ckan.misc.MarkdownFormat().to_html(data))


# these are the functions that will end up in `h` template helpers
# if config option restrict_template_vars is true
__allowed_functions__ = [
Expand Down Expand Up @@ -942,6 +950,7 @@ def dashboard_activity_stream(user_id):
'follow_button',
'follow_count',
'dashboard_activity_stream',
'render_markdown',
# imported into ckan.lib.helpers
'literal',
'link_to',
Expand Down
3 changes: 1 addition & 2 deletions ckan/public/scripts/application.js
Expand Up @@ -1675,7 +1675,6 @@ CKAN.DataPreview = function ($, my) {
// that if we got here (i.e. preview shown) worth doing
// something ...)
resourceData.formatNormalized = my.normalizeFormat(resourceData.format);

resourceData.url = my.normalizeUrl(resourceData.url);
if (resourceData.formatNormalized === '') {
var tmp = resourceData.url.split('/');
Expand All @@ -1702,7 +1701,7 @@ CKAN.DataPreview = function ($, my) {
});

}
else if (resourceData.formatNormalized in {'csv': '', 'xls': ''}) {
else if (resourceData.formatNormalized in {'csv': '', 'xls': '', 'tsv':''}) {
// set format as this is used by Recline in setting format for DataProxy
resourceData.format = resourceData.formatNormalized;
var dataset = new recline.Model.Dataset(resourceData, 'dataproxy');
Expand Down
10 changes: 6 additions & 4 deletions ckan/templates/package/resource_read.html
Expand Up @@ -126,19 +126,21 @@
</dl>
</div>

<div class="notes" property="rdfs:label">
<div class="notes" property="rdfs:label" py:if="c.resource.get('description')">
<div id="notes-extract">
${c.resource.get('description') or '(No description)'}
${ h.render_markdown(c.resource.get('description')) }
</div>
</div>

<div py:if="not c.resource.get('description') and c.package.get('notes')" id="dataset-description">
<div py:if="not c.resource.get('description') and c.package.get('notes')">
<div>
<strong i18n:msg="">
From the <a href="${h.url_for(controller='package', action='read', id=c.package['name'])}">Dataset</a>:
</strong>
</div>
<div>${h.markdown_extract(c.package.get('notes'), 300)}</div>
<div class="notes">
<div id="notes-extract">${h.render_markdown(c.package.get('notes')) }</div>
</div>
</div>

<div class="resource-preview">
Expand Down
16 changes: 8 additions & 8 deletions ckan/tests/lib/test_dictization.py
Expand Up @@ -364,7 +364,7 @@ def test_09_package_alter(self):
anna_dictized = package_dictize(anna1, context)

anna_dictized["name"] = u'annakarenina_changed'
anna_dictized["resources"][0]["url"] = u'new_url'
anna_dictized["resources"][0]["url"] = u'http://new_url'

model.repo.new_revision()
package_dict_save(anna_dictized, context)
Expand Down Expand Up @@ -402,7 +402,7 @@ def test_10_package_alter_pending(self):
anna_dictized = package_dictize(anna1, context)

anna_dictized['name'] = u'annakarenina_changed2'
anna_dictized['resources'][0]['url'] = u'new_url2'
anna_dictized['resources'][0]['url'] = u'http://new_url2'
anna_dictized['tags'][0]['name'] = u'new_tag'
anna_dictized['tags'][0].pop('id') #test if
anna_dictized['extras'][0]['value'] = u'"new_value"'
Expand Down Expand Up @@ -496,7 +496,7 @@ def test_11_add_pending(self):
anna_dictized['notes'] = 'wee'
anna_dictized['resources'].append({
'format': u'plain text',
'url': u'newurl'}
'url': u'http://newurl'}
)
anna_dictized['tags'].append({'name': u'newnew_tag'})
anna_dictized['extras'].append({'key': 'david',
Expand Down Expand Up @@ -676,15 +676,15 @@ def test_13_get_package_in_past(self):
second_dictized = self.remove_changable_columns(package_dictize(anna1, context))

first_dictized["name"] = u'annakarenina_changed'
first_dictized["resources"][0]["url"] = u'new_url'
first_dictized["resources"][0]["url"] = u'http://new_url'

assert second_dictized == first_dictized

context['revision_id'] = sorted_packages[2].revision_id #original state
third_dictized = self.remove_changable_columns(package_dictize(anna1, context))

second_dictized['name'] = u'annakarenina_changed2'
second_dictized['resources'][0]['url'] = u'new_url2'
second_dictized['resources'][0]['url'] = u'http://new_url2'
second_dictized['tags'][0]['name'] = u'new_tag'
second_dictized['tags'][0]['display_name'] = u'new_tag'
second_dictized['extras'][0]['value'] = u'"new_value"'
Expand All @@ -711,7 +711,7 @@ def test_13_get_package_in_past(self):
u'size': None,
u'state': u'active',
u'tracking_summary': {'total': 0, 'recent': 0},
u'url': u'newurl',
u'url': u'http://newurl',
u'webstore_last_updated': None,
u'webstore_url': None})

Expand Down Expand Up @@ -741,7 +741,7 @@ def test_14_resource_no_id(self):
'description': u'Full text. Needs escaping: " Umlaut: \xfc',
'format': u'plain text',
'tracking_summary': {'recent': 0, 'total': 0},
'url': u'test_new',
'url': u'http://test_new',
'cache_url': None,
'webstore_url': None,
'cache_last_updated': None,
Expand All @@ -760,7 +760,7 @@ def test_14_resource_no_id(self):
model.Session.commit()
model.Session.remove()

res = model.Session.query(model.Resource).filter_by(url=u'test_new').one()
res = model.Session.query(model.Resource).filter_by(url=u'http://test_new').one()

res_dictized = self.remove_changable_columns(resource_dictize(res, context))

Expand Down
4 changes: 2 additions & 2 deletions ckan/tests/logic/test_action.py
Expand Up @@ -192,15 +192,15 @@ def test_18_create_package_not_authorized(self):
def test_41_create_resource(self):

anna_id = model.Package.by_name(u'annakarenina').id
resource = {'package_id': anna_id, 'url': 'new_url'}
resource = {'package_id': anna_id, 'url': 'http://new_url'}

postparams = '%s=1' % json.dumps(resource)
res = self.app.post('/api/action/resource_create', params=postparams,
extra_environ={'Authorization': 'tester'})

resource = json.loads(res.body)['result']

assert resource['url'] == 'new_url'
assert resource['url'] == 'http://new_url'

def test_42_create_resource_with_error(self):

Expand Down
6 changes: 3 additions & 3 deletions ckanext/organizations/forms.py
Expand Up @@ -3,15 +3,15 @@

import ckan.authz as authz
from ckan.logic import NotAuthorized
from ckan.logic.schema import group_form_schema, default_package_schema
from ckan.logic.schema import group_form_schema, form_to_db_package_schema
from ckan.lib import base
from ckan.lib.base import c, model, abort, request
from ckan.lib.base import redirect, _, config, h
from ckan.lib.navl.dictization_functions import DataError
from ckan.plugins import IGroupForm, IDatasetForm, IConfigurer, IRoutes
from ckan.plugins import implements, SingletonPlugin
from ckan.logic import check_access

from ckan.logic.validators import tag_string_convert
from ckan.lib.navl.validators import (ignore_missing,
not_empty,
empty,
Expand Down Expand Up @@ -234,7 +234,7 @@ def db_to_form_schema(self):
into a format suitable for the form (optional)'''

def form_to_db_schema(self):
schema = default_package_schema()
schema = form_to_db_package_schema()
schema['groups']['capacity'] = [ignore_missing, unicode]
schema['__after'] = [group_required]
return schema
Expand Down

0 comments on commit 66aa4f1

Please sign in to comment.