Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
ckanpublish
Commits
e7ff8cdf0adf
Commit
1e4d4aaa
authored
Dec 09, 2014
by
Denis Laxalde
Browse files
[views] Add goto CKAN dataset link
Backported from client application.
parent
d88cc9dbf6d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
views.py
View file @
e7ff8cdf
...
...
@@ -15,3 +15,47 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb-ckanpublish views/forms/actions/components for web ui"""
from
urlparse
import
urljoin
from
logilab.mtconverter
import
xml_escape
from
cubicweb.predicates
import
score_entity
from
cubicweb.web
import
component
from
cubes.ckanpublish.utils
import
ckan_post
_
=
unicode
class
GotoCKANDatasetComponent
(
component
.
EntityCtxComponent
):
"""Contextual component displaying a link to the CKAN dataset in
Dataset-like entities primary view.
"""
__regid__
=
'ckanpublish.goto-ckan-dataset'
__select__
=
(
component
.
EntityCtxComponent
.
__select__
&
score_entity
(
lambda
x
:
hasattr
(
x
,
'ckan_dataset_id'
)))
title
=
_
(
'CKAN dataset'
)
context
=
'incontext'
_ckan_response
=
None
def
init_rendering
(
self
):
super
(
GotoCKANDatasetComponent
,
self
).
init_rendering
()
config
=
self
.
_cw
.
vreg
.
config
entity
=
self
.
_cw
.
entity_from_eid
(
self
.
cw_rset
[
0
][
0
])
try
:
r
=
ckan_post
(
config
,
'package_show'
,
{
'id'
:
entity
.
ckan_dataset_id
})
except
Exception
as
exc
:
self
.
_cw
.
warning
(
'fail to post to CKAN instance: %s'
,
exc
)
raise
component
.
EmptyComponent
()
self
.
_ckan_response
=
r
def
render_body
(
self
,
w
):
r
=
self
.
_ckan_response
config
=
self
.
_cw
.
vreg
.
config
base
=
config
[
'ckan-baseurl'
]
url
=
urljoin
(
base
,
'dataset/'
+
xml_escape
(
r
[
'name'
]))
w
(
u
'<a target=_blank href="%s">%s<a/>'
%
(
url
,
xml_escape
(
url
)))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment