Minor refactor

This commit is contained in:
Aitor Magán 2015-06-18 13:05:37 +02:00
parent fc0cf6fef3
commit 4b59fc982b
4 changed files with 21 additions and 16 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2014 CoNWeT Lab., Universidad Politécnica de Madrid
# Copyright (c) 2014-2015 CoNWeT Lab., Universidad Politécnica de Madrid
# This file is part of CKAN Private Dataset Extension.
@ -28,6 +28,7 @@ from ckan.common import request
import logging
log = logging.getLogger(__name__)
def is_dataset_acquired(pkg_dict):
db.init_db(model)
@ -75,15 +76,17 @@ def show_acquire_url_on_edit():
def snippet(template_name, data=None):
''' This function is used to load html snippets into pages. keywords
can be used to pass parameters into the snippet rendering '''
'''
This function is used to load html snippets into pages. keywords
can be used to pass parameters into the snippet rendering
'''
return tk.render_snippet(template_name, data)
def getaccess_button(package):
'''Return a Get Access button for the given package id.
If the user is not logged in return an empty string instead.
def acquire_button(package):
'''
Return a Get Access button for the given package id when the dataset has
an acquisition URL.
:param package: the the package to request access when the get access
button is clicked
@ -98,6 +101,6 @@ def getaccess_button(package):
and package['acquire_url'] != '':
url_dest = package['acquire_url']
data = {'url_dest': url_dest}
return snippet('snippets/fiware_getaccess_button.html', data)
return snippet('snippets/acquire_button.html', data)
else:
return ''

View File

@ -273,7 +273,7 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm):
# to read the package.
attrs.append('resources')
# Delete
# Delete
self._delete_pkg_atts(result, attrs)
return search_results
@ -289,5 +289,5 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm):
'can_read': helpers.can_read,
'show_acquire_url_on_create': helpers.show_acquire_url_on_create,
'show_acquire_url_on_edit': helpers.show_acquire_url_on_edit,
'getaccess_button': helpers.getaccess_button
'acquire_button': helpers.acquire_button
}

View File

@ -6,10 +6,10 @@ ulr_dest - target url
Example:
{% snippet 'snippets/fiware_getaccess_button.html', url_dest=url %}
{% snippet 'snippets/acquire_button.html', url_dest=url %}
#}
<a href={{ url_dest }} class="btn btn-mini">
<i class="icon-plus-sign"></i>
{{ _('Get Access') }}
<i class="icon-shopping-cart"></i>
{{ _('Acquire') }}
</a>

View File

@ -44,15 +44,17 @@ Example:
{{ _('Owner') }}
</span>
{% endif %}
<!-- Customizations FIWARE GETACCESS GETACCESSBUTTON-->
<!-- Customizations Acquire Button -->
{% if package.private and not h.can_read(package) %}
{{ _(h.truncate(title, truncate_title)) }}
<div class="divider"/>
{{ h.getaccess_button(package) }}
{{ h.acquire_button(package) }}
{% else %}
{{ h.link_to(h.truncate(title, truncate_title), h.url_for(controller='package', action='read', id=package.name)) }}
{% endif %}
<!-- End of customizations FIWARE GETACCESSBUTTON -->
<!-- End of customizations Acquire Button -->
{% if package.get('state', '').startswith('draft') %}
<span class="label label-info">{{ _('Draft') }}</span>
{% elif package.get('state', '').startswith('deleted') %}