[ckan-changes] commit/ckan: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Tue Jun 14 09:04:40 UTC 2011
2 new changesets in ckan:
http://bitbucket.org/okfn/ckan/changeset/5af6964146fc/
changeset: 5af6964146fc
branch: feature-1141-moderated-edits-ajax
user: kindly
date: 2011-06-13 21:58:07
summary: [moderated edit] reads now get results from revision table
affected #: 9 files (865 bytes)
--- a/ckan/controllers/package.py Sat Jun 11 14:00:50 2011 +0100
+++ b/ckan/controllers/package.py Mon Jun 13 20:58:07 2011 +0100
@@ -174,11 +174,20 @@
@proxy_cache()
def read(self, id):
-
+
+ context = {'model': model, 'session': model.Session,
+ 'user': c.user or c.author, 'extras_as_string': True,
+ 'schema': self._form_to_db_schema(),
+ 'id': id}
#check if package exists
- c.pkg = model.Package.get(id)
- if c.pkg is None:
+ try:
+ c.pkg_dict = get.package_show(context)
+ c.pkg = context['package']
+ except NotFound:
abort(404, _('Package not found'))
+ except NotAuthorized:
+ abort(401, _('Unauthorized to read package %s') % id)
+
cache_key = self._pkg_cache_key(c.pkg)
etag_cache(cache_key)
@@ -197,39 +206,34 @@
rdf_url = '%s%s.%s' % (config['rdf_packages'], c.pkg.id, exts[0])
redirect(rdf_url, code=303)
break
-
- #is the user allowed to see this package?
- auth_for_read = self.authorizer.am_authorized(c, model.Action.READ, c.pkg)
- if not auth_for_read:
- abort(401, _('Unauthorized to read package %s') % id)
-
- for item in self.extensions:
- item.read(c.pkg)
#render the package
- PackageSaver().render_package(c.pkg)
+ PackageSaver().render_package(c.pkg_dict, context)
return render('package/read.html')
def comments(self, id):
+ context = {'model': model, 'session': model.Session,
+ 'user': c.user or c.author, 'extras_as_string': True,
+ 'schema': self._form_to_db_schema(),
+ 'id': id}
#check if package exists
- c.pkg = model.Package.get(id)
- if c.pkg is None:
+ try:
+ c.pkg_dict = get.package_show(context)
+ c.pkg = context['package']
+ except NotFound:
abort(404, _('Package not found'))
+ except NotAuthorized:
+ abort(401, _('Unauthorized to read package %s') % id)
# used by disqus plugin
c.current_package_id = c.pkg.id
- #is the user allowed to see this package?
- auth_for_read = self.authorizer.am_authorized(c, model.Action.READ, c.pkg)
- if not auth_for_read:
- abort(401, _('Unauthorized to read package %s') % id)
-
for item in self.extensions:
item.read(c.pkg)
#render the package
- PackageSaver().render_package(c.pkg)
+ PackageSaver().render_package(c.pkg_dict)
return render('package/comments.html')
@@ -406,7 +410,9 @@
pkg = create.package_create(data_dict, context)
if context['preview']:
- PackageSaver().render_package(context['package'])
+ PackageSaver().render_package(pkg, context)
+ c.pkg = context['package']
+ c.pkg_dict = data_dict
c.is_preview = True
c.preview = render('package/read_core.html')
return self.new(data_dict)
@@ -435,10 +441,11 @@
if request.params.get('save', '') == 'Approve':
update.make_latest_pending_package_active(context)
c.pkg = context['package']
+ c.pkg_dict = pkg
if context['preview']:
c.is_preview = True
- PackageSaver().render_package(context['package'])
+ PackageSaver().render_package(pkg, context)
c.preview = render('package/read_core.html')
return self.edit(id, data_dict)
--- a/ckan/lib/package_saver.py Sat Jun 11 14:00:50 2011 +0100
+++ b/ckan/lib/package_saver.py Mon Jun 13 20:58:07 2011 +0100
@@ -26,29 +26,31 @@
# TODO: rename to something more correct like prepare_for_render
@classmethod
- def render_package(cls, pkg):
+ def render_package(cls, pkg, context):
'''Prepares for rendering a package. Takes a Package object and
formats it for the various context variables required to call
render.
Note that the actual calling of render('package/read') is left
to the caller.'''
- c.pkg = pkg
try:
- notes_formatted = ckan.misc.MarkdownFormat().to_html(pkg.notes)
+ notes_formatted = ckan.misc.MarkdownFormat().to_html(pkg.get('notes',''))
c.pkg_notes_formatted = genshi.HTML(notes_formatted)
except Exception, e:
error_msg = "<span class='inline-warning'>%s</span>" % _("Cannot render package description")
c.pkg_notes_formatted = genshi.HTML(error_msg)
- c.current_rating, c.num_ratings = ckan.rating.get_rating(pkg)
- c.pkg_url_link = h.link_to(c.pkg.url, c.pkg.url, target='_blank') if c.pkg.url else _("No web page given")
- c.pkg_author_link = cls._person_email_link(c.pkg.author, c.pkg.author_email, "Author")
- c.pkg_maintainer_link = cls._person_email_link(c.pkg.maintainer, c.pkg.maintainer_email, "Maintainer")
- c.package_relationships = pkg.get_relationships_printable()
+ c.current_rating, c.num_ratings = ckan.rating.get_rating(context['package'])
+ url = pkg.get('url', '')
+ c.pkg_url_link = h.link_to(url, url, target='_blank') if url else _("No web page given")
+ c.pkg_author_link = cls._person_email_link(pkg.get('author', ''), pkg.get('author_email', ''), "Author")
+ maintainer = pkg.get('maintainer', '')
+ maintainer_email = pkg.get('maintainer_email', '')
+ c.pkg_maintainer_link = cls._person_email_link(maintainer, maintainer_email, "Maintainer")
+ c.package_relationships = context['package'].get_relationships_printable()
c.pkg_extras = []
- for extra in sorted(pkg.extras_list, key=lambda x:x.key):
- if extra.state == 'deleted':
+ for extra in sorted(pkg.get('extras',[]), key=lambda x:x['key']):
+ if extra.get('state') == 'deleted':
continue
- k, v = extra.key, extra.value
+ k, v = extra['key'], extra['value']
if k in g.package_hide_extras:
continue
if isinstance(v, (list, tuple)):
--- a/ckan/logic/action/create.py Sat Jun 11 14:00:50 2011 +0100
+++ b/ckan/logic/action/create.py Mon Jun 13 20:58:07 2011 +0100
@@ -73,6 +73,8 @@
log.debug('Created object %s' % str(pkg.name))
if not preview:
return package_dictize(pkg, context)
+ else:
+ return data
def resource_create(data_dict, context):
model = context['model']
--- a/ckan/logic/action/update.py Sat Jun 11 14:00:50 2011 +0100
+++ b/ckan/logic/action/update.py Mon Jun 13 20:58:07 2011 +0100
@@ -179,8 +179,8 @@
for item in PluginImplementations(IPackageController):
item.edit(pkg)
model.repo.commit()
-
- return package_dictize(pkg, context)
+ return package_dictize(pkg, context)
+ return data
def _update_package_relationship(relationship, comment, context):
--- a/ckan/migration/versions/039_add_expired_id_and_dates.py Sat Jun 11 14:00:50 2011 +0100
+++ b/ckan/migration/versions/039_add_expired_id_and_dates.py Mon Jun 13 20:58:07 2011 +0100
@@ -99,7 +99,6 @@
update package_revision pr set revision_timestamp = (select revision_timestamp from tmp_expired_id tmp where tmp.revision_id = pr.revision_id and tmp.id = pr.id),
expired_timestamp = (select expired_timestamp from tmp_expired_id tmp where tmp.revision_id = pr.revision_id and tmp.id = pr.id),
expired_id = (select expired_id from tmp_expired_id tmp where tmp.revision_id = pr.revision_id and tmp.id = pr.id);
-update package_revision set state = 'active-current' where expired_timestamp = '9999-12-31';
update package_revision set current = '1' where expired_timestamp = '9999-12-31';
create index idx_package_period on package_revision(revision_timestamp, expired_timestamp, id);
--- a/ckan/templates/_util.html Sat Jun 11 14:00:50 2011 +0100
+++ b/ckan/templates/_util.html Mon Jun 13 20:58:07 2011 +0100
@@ -27,7 +27,7 @@
tag listing --><ul py:def="tag_list(tags)" class="tags clearfix"><li py:for="tag in tags">
- ${h.link_to(tag.name, h.url_for(controller='tag', action='read', id=tag.name))}
+ ${h.link_to(tag['name'], h.url_for(controller='tag', action='read', id=tag['name']))}
</li></ul>
--- a/ckan/templates/package/comments.html Sat Jun 11 14:00:50 2011 +0100
+++ b/ckan/templates/package/comments.html Mon Jun 13 20:58:07 2011 +0100
@@ -2,12 +2,12 @@
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip="">
- <py:def function="page_title">${c.pkg.title or c.pkg.name} - Data Packages - History</py:def>
+ <py:def function="page_title">${c.pkg_dict.get('title', c.pkg_dict['name'])} - Data Packages - History</py:def><div py:match="content" class="package"><h2 class="head">
- ${c.pkg.title}
- <span class="name">(${c.pkg.name})</span>
+ ${c.pkg_dict.get('title', '')}
+ <span class="name">(${c.pkg_dict['name']})</span></h2></div><!-- content -->
--- a/ckan/templates/package/read.html Sat Jun 11 14:00:50 2011 +0100
+++ b/ckan/templates/package/read.html Mon Jun 13 20:58:07 2011 +0100
@@ -3,7 +3,7 @@
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip="">
- <py:def function="page_title">${c.pkg.title or c.pkg.name} - Data Packages</py:def>
+ <py:def function="page_title">${c.pkg_dict.get('title', c.pkg_dict['name'])} - Data Packages</py:def><py:match path="primarysidebar">
@@ -16,7 +16,7 @@
<li class="widget-container widget_text"><h3>Tags</h3>
- ${tag_list(c.pkg.tags)}
+ ${tag_list(c.pkg_dict.get('tags', ''))}
<p class="widget_action" py:if="h.am_authorized(c, actions.EDIT, c.pkg)">
${h.subnav_link(c, 'Add a new Tag', controller='package', action='edit', id=c.pkg.name)}
</p>
--- a/ckan/templates/package/read_core.html Sat Jun 11 14:00:50 2011 +0100
+++ b/ckan/templates/package/read_core.html Mon Jun 13 20:58:07 2011 +0100
@@ -6,7 +6,7 @@
<div id="package" class="package"><!-- Title --><h2 class="head">
- ${c.pkg.title}
+ ${c.pkg_dict.get('title','')}
<p class="atom-feed-link package-history-link"><a
href="${url(controller='package', action='history', id=c.pkg.name, format='atom', days=7)}"
@@ -16,7 +16,7 @@
</h2><!-- Source URL -->
- <div class="url" py:if="c.pkg.url">
+ <div class="url" py:if="c.pkg_dict.get('url')"><p>
Source: ${c.pkg_url_link}
</p>
@@ -31,30 +31,30 @@
<div class="resources subsection"><h3>Downloads & Resources</h3><py:choose test="">
- <table py:when="c.pkg.resources">
+ <table py:when="c.pkg_dict.get('resources', [])"><tr><th>Description</th><th>Format</th><th>Hash</th></tr>
- <py:for each="res in c.pkg.resources">
+ <py:for each="res in c.pkg_dict.get('resources', [])"><tr><td><py:choose test="">
- <py:when test="res.description">
- <a href="${res.url}" target="_blank">${res.description}</a>
+ <py:when test="res.get('description')">
+ <a href="${res.get('url', '')}" target="_blank">${res.description}</a></py:when><py:otherwise test="">
- <a href="${res.url}" target="_blank">Download <em>(no description)</em></a>
+ <a href="${res.get('url', '')}" target="_blank">Download <em>(no description)</em></a></py:otherwise></py:choose></td>
- <td>${res.format}</td>
- <td>${res.hash}</td>
+ <td>${res.get('format', '')}</td>
+ <td>${res.get('hash', '')}</td></tr></py:for><caption>
- This is a list of all known formats and datasets for <em>${c.pkg.title}</em>. If you know of another (CSV, SPARQL end-point etc.) ${h.subnav_link(c, 'please edit this page and add it to the list', controller='package', action='edit', id=c.pkg.name)}.
+ This is a list of all known formats and datasets for <em>${c.pkg_dict.get('title', '')}</em>. If you know of another (CSV, SPARQL end-point etc.) ${h.subnav_link(c, 'please edit this page and add it to the list', controller='package', action='edit', id=c.pkg.name)}.
</caption></table><table py:otherwise=""><tr><th>Resources</th><td>None given for this package.</td></tr></table>
@@ -80,7 +80,7 @@
<tbody>
${details_item('Author', c.pkg_author_link)}
${details_item('Maintainer', c.pkg_maintainer_link)}
- ${details_item('Version', c.pkg.version)}
+ ${details_item('Version', c.pkg_dict.get('version', ''))}
<tr><td class="package-label">
License
http://bitbucket.org/okfn/ckan/changeset/c3d02782160c/
changeset: c3d02782160c
branch: feature-1141-moderated-edits-ajax
user: kindly
date: 2011-06-14 11:04:16
summary: [moderated edits] use moderated from config
affected #: 1 file (8 bytes)
--- a/ckan/controllers/package.py Mon Jun 13 20:58:07 2011 +0100
+++ b/ckan/controllers/package.py Tue Jun 14 10:04:16 2011 +0100
@@ -326,7 +326,7 @@
'user': c.user or c.author, 'extras_as_string': True,
'preview': 'preview' in request.params,
'save': 'save' in request.params,
- 'id': id, 'moderated': request.params.get('moderated'),
+ 'id': id, 'moderated': config.get('moderated'),
'pending': True,
'schema': self._form_to_db_schema()}
Repository URL: https://bitbucket.org/okfn/ckan/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list