Skip to content

Commit

Permalink
Release v2.1.1 (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolidori committed Jul 6, 2023
1 parent 6d5ab52 commit c153023
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 26 deletions.
91 changes: 90 additions & 1 deletion ckanext/querytool/controllers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _save_edit(self, id, context):
context['message'] = data_dict.get('log_message', '')
data_dict['id'] = id
context['allow_partial_update'] = True
group = self._action('group_update')(context, data_dict)
group = self._action('querytool_group_update')(context, data_dict)
if id != group['name']:
self._force_reindex(group)

Expand All @@ -164,3 +164,92 @@ def _save_edit(self, id, context):
errors = e.error_dict
error_summary = e.error_summary
return self.edit(id, data_dict, errors, error_summary)

def delete(self, id):
group_type = self._ensure_controller_matches_group_type(id)

if 'cancel' in request.params:
self._redirect_to_this_controller(action='edit', id=id)

context = {'model': model, 'session': model.Session,
'user': c.user}

try:
self._check_access('group_delete', context, {'id': id})
except NotAuthorized:
abort(403, _('Unauthorized to delete group %s') % '')

try:
if request.method == 'POST':
self._action('querytool_group_delete')(context, {'id': id})
if group_type == 'organization':
h.flash_notice(_('Organization has been deleted.'))
elif group_type == 'group':
h.flash_notice(_('Group has been deleted.'))
else:
h.flash_notice(_('%s has been deleted.')
% _(group_type.capitalize()))
#self._redirect_to_this_controller(action='index')
h.redirect_to(controller='group', action='index')
c.group_dict = self._action('group_show')(context, {'id': id})
except NotAuthorized:
abort(403, _('Unauthorized to delete group %s') % '')
except NotFound:
abort(404, _('Group not found'))
return self._render_template('group/confirm_delete.html', group_type)

def new(self, data=None, errors=None, error_summary=None):
if data and 'type' in data:
group_type = data['type']
else:
group_type = self._guess_group_type(True)
if data:
data['type'] = group_type

context = {'model': model, 'session': model.Session,
'user': c.user,
'save': 'save' in request.params,
'parent': request.params.get('parent', None)}
try:
self._check_access('group_create', context)
except NotAuthorized:
abort(403, _('Unauthorized to create a group'))

if context['save'] and not data:
return self._save_new(context, group_type)

data = data or {}
if not data.get('image_url', '').startswith('http'):
data.pop('image_url', None)

errors = errors or {}
error_summary = error_summary or {}
vars = {'data': data, 'errors': errors,
'error_summary': error_summary, 'action': 'new',
'group_type': group_type}

self._setup_template_variables(context, data, group_type=group_type)
c.form = render(self._group_form(group_type=group_type),
extra_vars=vars)
return render(self._new_template(group_type),
extra_vars={'group_type': group_type})

def _save_new(self, context, group_type=None):
try:
data_dict = clean_dict(dict_fns.unflatten(
tuplize_dict(parse_params(request.params))))
data_dict['type'] = group_type or 'group'
context['message'] = data_dict.get('log_message', '')
data_dict['users'] = [{'name': c.user, 'capacity': 'admin'}]
group = self._action('querytool_group_create')(context, data_dict)

# Redirect to the appropriate _read route for the type of group
h.redirect_to(group['type'] + '_read', id=group['name'])
except (NotFound, NotAuthorized), e:
abort(404, _('Group not found'))
except dict_fns.DataError:
abort(400, _(u'Integrity Error'))
except ValidationError, e:
errors = e.error_dict
error_summary = e.error_summary
return self.new(data_dict, errors, error_summary)

Large diffs are not rendered by default.

Large diffs are not rendered by default.

54 changes: 44 additions & 10 deletions ckanext/querytool/fanstatic/javascript/public_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
var buttonImg = $('#download-as-image');

buttonImg.on('click', function(targetElem) {

var nodeList = document.querySelectorAll('.c3-lines path');
var nodeList2 = document.querySelectorAll('.c3-axis path');
var line_graph = Array.from(nodeList);
Expand All @@ -261,16 +262,49 @@
// fix references
d3.selectAll('.c3-ygrid-line.base line').attr('stroke', 'grey');

html2canvas(document.body, {
//fix images
ignoreElements: function(element) {
if (element.classList.contains('html2canvas-ignore')) return true;
},
useCORS: true,
allowTaint: true
}).then(function(canvas) {
Canvas2Image.saveAsPNG(canvas);
});
const visualizationsEl = document.getElementsByClassName("container-wrapper");

function saveAs(uri, filename) {
var link = document.createElement('a');
if (typeof link.download === 'string') {
link.href = uri;
link.download = filename;
//Firefox requires the link to be in the body
document.body.appendChild(link);
//simulate click
link.click();
//remove the link when done
document.body.removeChild(link);
} else {
window.open(uri);
}
}

if(visualizationsEl)
setTimeout(() => html2canvas(visualizationsEl[0], {
//fix images
ignoreElements: function(element) {
if (element.classList.contains('html2canvas-ignore')) return true;
},
logging: true,
allowTaint: false,
useCORS: false,
onclone: (document) => {
// Change elements on the cloned document
const elementsToHide = [
'.leaflet-top.leaflet-left',
'.leaflet-top.leaflet-right',
'.__map-loading-indicator',
'.imgBtn.scrBtn',
'.btn',
'#scrollBtn'
].join(', ');

$(document).find(elementsToHide).css('display', 'none');
}
}).then(function(canvas) {
saveAs(canvas.toDataURL(), 'report.png');
}), 500)
});

// Add validation for public filters if no valid values are selected
Expand Down
8 changes: 4 additions & 4 deletions ckanext/querytool/logic/action/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
log = log.getLogger(__name__)


def _group_or_org_create(context, data_dict, is_org=False):
def _querytool_group_or_org_create(context, data_dict, is_org=False):
model = context['model']
user = context['user']
session = context['session']
Expand Down Expand Up @@ -50,7 +50,7 @@ def _group_or_org_create(context, data_dict, is_org=False):

data, errors = lib_plugins.plugin_validate(
group_plugin, context, data_dict, schema,
'organization_create' if is_org else 'group_create')
'organization_create' if is_org else 'querytool_group_create')
log.debug('group_create validate_errs=%r user=%s group=%s data_dict=%r',
errors, context.get('user'), data_dict.get('name'), data_dict)

Expand Down Expand Up @@ -169,7 +169,7 @@ def _group_or_org_create(context, data_dict, is_org=False):
return output


def group_create(context, data_dict):
def querytool_group_create(context, data_dict):
'''Create a new group.
You must be authorized to create groups.
Plugins may change the parameters of this function depending on the value
Expand Down Expand Up @@ -232,4 +232,4 @@ def group_create(context, data_dict):
# FIXME better exception?
raise Exception(_('Trying to create an organization as a group'))
_check_access('group_create', context, data_dict)
return _group_or_org_create(context, data_dict)
return _querytool_group_or_org_create(context, data_dict)
6 changes: 3 additions & 3 deletions ckanext/querytool/logic/action/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def querytool_delete(context, data_dict):
CkanextQueryTool.delete(id=data_dict['name'])


def _group_or_org_delete(context, data_dict, is_org=False):
def _querytool_group_or_org_delete(context, data_dict, is_org=False):
'''Delete a group.
You must be authorized to delete the group.
:param id: the name or id of the group
Expand Down Expand Up @@ -115,10 +115,10 @@ def _group_or_org_delete(context, data_dict, is_org=False):
model.repo.commit()


def group_delete(context, data_dict):
def querytool_group_delete(context, data_dict):
'''Delete a group.
You must be authorized to delete the group.
:param id: the name or id of the group
:type id: string
'''
return _group_or_org_delete(context, data_dict)
return _querytool_group_or_org_delete(context, data_dict)
6 changes: 3 additions & 3 deletions ckanext/querytool/logic/action/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def config_option_update(context, data_dict):
return data


def _group_or_org_update(context, data_dict, is_org=False):
def _querytool_group_or_org_update(context, data_dict, is_org=False):
model = context['model']
user = context['user']
session = context['session']
Expand Down Expand Up @@ -513,7 +513,7 @@ def _group_or_org_update(context, data_dict, is_org=False):
return model_dictize.group_dictize(group, context)


def group_update(context, data_dict):
def querytool_group_update(context, data_dict):
'''Update a group.
You must be authorized to edit the group.
Expand All @@ -535,6 +535,6 @@ def group_update(context, data_dict):
# Callers that set context['allow_partial_update'] = True can choose to not
# specify particular keys and they will be left at their existing
# values. This includes: packages, users, groups, tags, extras
return _group_or_org_update(
return _querytool_group_or_org_update(
context, data_dict
)
8 changes: 8 additions & 0 deletions ckanext/querytool/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ def before_map(self, map):
'group_edit', '/group/edit/{id}',
controller=group_controller, action='edit'
)
map.connect(
'group_new', '/group/new',
controller=group_controller, action='new'
)
map.connect(
'group_delete', '/group/delete/{id}',
controller=group_controller, action='delete'
)

# Query tool routes
map.redirect('/querytool', '/querytool/groups',
Expand Down
2 changes: 1 addition & 1 deletion ckanext/querytool/templates/group/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{% block page_primary_action %}
{% if h.check_access('group_create') %}
{% link_for _('Add Group'), controller='group', action='new', class_='btn btn-primary', icon='plus-square' %}
{% link_for _('Add Group'), controller='ckanext.querytool.controllers.group:QuerytoolGroupController', action='new', class_='btn btn-primary', icon='plus-square' %}
{% endif %}

{% set ctrl = 'ckanext.querytool.controllers.querytool:QueryToolController' %}
Expand Down
2 changes: 1 addition & 1 deletion ckanext/querytool/templates/group/snippets/group_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<div class="form-actions">
{% block delete_button %}
{% if h.check_access('group_delete', {'id': data.id}) %}
<a class="btn btn-danger pull-left" href="{% url_for controller='group', action='delete', id=data.id %}" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to delete this Group?') }}">{% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a>
<a class="btn btn-danger pull-left" href="{% url_for controller='ckanext.querytool.controllers.group:QuerytoolGroupController', action='delete', id=data.id %}" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to delete this Group?') }}">{% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a>
{% endif %}
{% endblock %}
<button class="btn btn-primary" name="save" type="submit">{% block save_text %}{{ _('Save Group') }}{% endblock %}</button>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# http://packaging.python.org/en/latest/tutorial.html#version
version='2.0.3',
version='2.1.1',

description='''CKAN extension that will provide data quering with
pre configured set of rules''',
Expand Down

0 comments on commit c153023

Please sign in to comment.