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 -*- # -*- 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. # This file is part of CKAN Private Dataset Extension.
@ -28,6 +28,7 @@ from ckan.common import request
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def is_dataset_acquired(pkg_dict): def is_dataset_acquired(pkg_dict):
db.init_db(model) db.init_db(model)
@ -75,15 +76,17 @@ def show_acquire_url_on_edit():
def snippet(template_name, data=None): 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) return tk.render_snippet(template_name, data)
def getaccess_button(package): def acquire_button(package):
'''Return a Get Access button for the given package id. '''
Return a Get Access button for the given package id when the dataset has
If the user is not logged in return an empty string instead. an acquisition URL.
:param package: the the package to request access when the get access :param package: the the package to request access when the get access
button is clicked button is clicked
@ -98,6 +101,6 @@ def getaccess_button(package):
and package['acquire_url'] != '': and package['acquire_url'] != '':
url_dest = package['acquire_url'] url_dest = package['acquire_url']
data = {'url_dest': url_dest} data = {'url_dest': url_dest}
return snippet('snippets/fiware_getaccess_button.html', data) return snippet('snippets/acquire_button.html', data)
else: else:
return '' return ''

View File

@ -289,5 +289,5 @@ class PrivateDatasets(p.SingletonPlugin, tk.DefaultDatasetForm):
'can_read': helpers.can_read, 'can_read': helpers.can_read,
'show_acquire_url_on_create': helpers.show_acquire_url_on_create, 'show_acquire_url_on_create': helpers.show_acquire_url_on_create,
'show_acquire_url_on_edit': helpers.show_acquire_url_on_edit, '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: 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"> <a href={{ url_dest }} class="btn btn-mini">
<i class="icon-plus-sign"></i> <i class="icon-shopping-cart"></i>
{{ _('Get Access') }} {{ _('Acquire') }}
</a> </a>

View File

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