Skip to content

Commit c153023

Browse files
authored
Release v2.1.1 (#601)
1 parent 6d5ab52 commit c153023

File tree

11 files changed

+157
-26
lines changed

11 files changed

+157
-26
lines changed

ckanext/querytool/controllers/group.py

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def _save_edit(self, id, context):
151151
context['message'] = data_dict.get('log_message', '')
152152
data_dict['id'] = id
153153
context['allow_partial_update'] = True
154-
group = self._action('group_update')(context, data_dict)
154+
group = self._action('querytool_group_update')(context, data_dict)
155155
if id != group['name']:
156156
self._force_reindex(group)
157157

@@ -164,3 +164,92 @@ def _save_edit(self, id, context):
164164
errors = e.error_dict
165165
error_summary = e.error_summary
166166
return self.edit(id, data_dict, errors, error_summary)
167+
168+
def delete(self, id):
169+
group_type = self._ensure_controller_matches_group_type(id)
170+
171+
if 'cancel' in request.params:
172+
self._redirect_to_this_controller(action='edit', id=id)
173+
174+
context = {'model': model, 'session': model.Session,
175+
'user': c.user}
176+
177+
try:
178+
self._check_access('group_delete', context, {'id': id})
179+
except NotAuthorized:
180+
abort(403, _('Unauthorized to delete group %s') % '')
181+
182+
try:
183+
if request.method == 'POST':
184+
self._action('querytool_group_delete')(context, {'id': id})
185+
if group_type == 'organization':
186+
h.flash_notice(_('Organization has been deleted.'))
187+
elif group_type == 'group':
188+
h.flash_notice(_('Group has been deleted.'))
189+
else:
190+
h.flash_notice(_('%s has been deleted.')
191+
% _(group_type.capitalize()))
192+
#self._redirect_to_this_controller(action='index')
193+
h.redirect_to(controller='group', action='index')
194+
c.group_dict = self._action('group_show')(context, {'id': id})
195+
except NotAuthorized:
196+
abort(403, _('Unauthorized to delete group %s') % '')
197+
except NotFound:
198+
abort(404, _('Group not found'))
199+
return self._render_template('group/confirm_delete.html', group_type)
200+
201+
def new(self, data=None, errors=None, error_summary=None):
202+
if data and 'type' in data:
203+
group_type = data['type']
204+
else:
205+
group_type = self._guess_group_type(True)
206+
if data:
207+
data['type'] = group_type
208+
209+
context = {'model': model, 'session': model.Session,
210+
'user': c.user,
211+
'save': 'save' in request.params,
212+
'parent': request.params.get('parent', None)}
213+
try:
214+
self._check_access('group_create', context)
215+
except NotAuthorized:
216+
abort(403, _('Unauthorized to create a group'))
217+
218+
if context['save'] and not data:
219+
return self._save_new(context, group_type)
220+
221+
data = data or {}
222+
if not data.get('image_url', '').startswith('http'):
223+
data.pop('image_url', None)
224+
225+
errors = errors or {}
226+
error_summary = error_summary or {}
227+
vars = {'data': data, 'errors': errors,
228+
'error_summary': error_summary, 'action': 'new',
229+
'group_type': group_type}
230+
231+
self._setup_template_variables(context, data, group_type=group_type)
232+
c.form = render(self._group_form(group_type=group_type),
233+
extra_vars=vars)
234+
return render(self._new_template(group_type),
235+
extra_vars={'group_type': group_type})
236+
237+
def _save_new(self, context, group_type=None):
238+
try:
239+
data_dict = clean_dict(dict_fns.unflatten(
240+
tuplize_dict(parse_params(request.params))))
241+
data_dict['type'] = group_type or 'group'
242+
context['message'] = data_dict.get('log_message', '')
243+
data_dict['users'] = [{'name': c.user, 'capacity': 'admin'}]
244+
group = self._action('querytool_group_create')(context, data_dict)
245+
246+
# Redirect to the appropriate _read route for the type of group
247+
h.redirect_to(group['type'] + '_read', id=group['name'])
248+
except (NotFound, NotAuthorized), e:
249+
abort(404, _('Group not found'))
250+
except dict_fns.DataError:
251+
abort(400, _(u'Integrity Error'))
252+
except ValidationError, e:
253+
errors = e.error_dict
254+
error_summary = e.error_summary
255+
return self.new(data_dict, errors, error_summary)

ckanext/querytool/fanstatic/javascript/dist/public_query.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ckanext/querytool/fanstatic/javascript/dist/public_query.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ckanext/querytool/fanstatic/javascript/public_query.js

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
var buttonImg = $('#download-as-image');
245245

246246
buttonImg.on('click', function(targetElem) {
247+
247248
var nodeList = document.querySelectorAll('.c3-lines path');
248249
var nodeList2 = document.querySelectorAll('.c3-axis path');
249250
var line_graph = Array.from(nodeList);
@@ -261,16 +262,49 @@
261262
// fix references
262263
d3.selectAll('.c3-ygrid-line.base line').attr('stroke', 'grey');
263264

264-
html2canvas(document.body, {
265-
//fix images
266-
ignoreElements: function(element) {
267-
if (element.classList.contains('html2canvas-ignore')) return true;
268-
},
269-
useCORS: true,
270-
allowTaint: true
271-
}).then(function(canvas) {
272-
Canvas2Image.saveAsPNG(canvas);
273-
});
265+
const visualizationsEl = document.getElementsByClassName("container-wrapper");
266+
267+
function saveAs(uri, filename) {
268+
var link = document.createElement('a');
269+
if (typeof link.download === 'string') {
270+
link.href = uri;
271+
link.download = filename;
272+
//Firefox requires the link to be in the body
273+
document.body.appendChild(link);
274+
//simulate click
275+
link.click();
276+
//remove the link when done
277+
document.body.removeChild(link);
278+
} else {
279+
window.open(uri);
280+
}
281+
}
282+
283+
if(visualizationsEl)
284+
setTimeout(() => html2canvas(visualizationsEl[0], {
285+
//fix images
286+
ignoreElements: function(element) {
287+
if (element.classList.contains('html2canvas-ignore')) return true;
288+
},
289+
logging: true,
290+
allowTaint: false,
291+
useCORS: false,
292+
onclone: (document) => {
293+
// Change elements on the cloned document
294+
const elementsToHide = [
295+
'.leaflet-top.leaflet-left',
296+
'.leaflet-top.leaflet-right',
297+
'.__map-loading-indicator',
298+
'.imgBtn.scrBtn',
299+
'.btn',
300+
'#scrollBtn'
301+
].join(', ');
302+
303+
$(document).find(elementsToHide).css('display', 'none');
304+
}
305+
}).then(function(canvas) {
306+
saveAs(canvas.toDataURL(), 'report.png');
307+
}), 500)
274308
});
275309

276310
// Add validation for public filters if no valid values are selected

ckanext/querytool/logic/action/create.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
log = log.getLogger(__name__)
2222

2323

24-
def _group_or_org_create(context, data_dict, is_org=False):
24+
def _querytool_group_or_org_create(context, data_dict, is_org=False):
2525
model = context['model']
2626
user = context['user']
2727
session = context['session']
@@ -50,7 +50,7 @@ def _group_or_org_create(context, data_dict, is_org=False):
5050

5151
data, errors = lib_plugins.plugin_validate(
5252
group_plugin, context, data_dict, schema,
53-
'organization_create' if is_org else 'group_create')
53+
'organization_create' if is_org else 'querytool_group_create')
5454
log.debug('group_create validate_errs=%r user=%s group=%s data_dict=%r',
5555
errors, context.get('user'), data_dict.get('name'), data_dict)
5656

@@ -169,7 +169,7 @@ def _group_or_org_create(context, data_dict, is_org=False):
169169
return output
170170

171171

172-
def group_create(context, data_dict):
172+
def querytool_group_create(context, data_dict):
173173
'''Create a new group.
174174
You must be authorized to create groups.
175175
Plugins may change the parameters of this function depending on the value
@@ -232,4 +232,4 @@ def group_create(context, data_dict):
232232
# FIXME better exception?
233233
raise Exception(_('Trying to create an organization as a group'))
234234
_check_access('group_create', context, data_dict)
235-
return _group_or_org_create(context, data_dict)
235+
return _querytool_group_or_org_create(context, data_dict)

ckanext/querytool/logic/action/delete.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def querytool_delete(context, data_dict):
3636
CkanextQueryTool.delete(id=data_dict['name'])
3737

3838

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

117117

118-
def group_delete(context, data_dict):
118+
def querytool_group_delete(context, data_dict):
119119
'''Delete a group.
120120
You must be authorized to delete the group.
121121
:param id: the name or id of the group
122122
:type id: string
123123
'''
124-
return _group_or_org_delete(context, data_dict)
124+
return _querytool_group_or_org_delete(context, data_dict)

ckanext/querytool/logic/action/update.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def config_option_update(context, data_dict):
316316
return data
317317

318318

319-
def _group_or_org_update(context, data_dict, is_org=False):
319+
def _querytool_group_or_org_update(context, data_dict, is_org=False):
320320
model = context['model']
321321
user = context['user']
322322
session = context['session']
@@ -513,7 +513,7 @@ def _group_or_org_update(context, data_dict, is_org=False):
513513
return model_dictize.group_dictize(group, context)
514514

515515

516-
def group_update(context, data_dict):
516+
def querytool_group_update(context, data_dict):
517517
'''Update a group.
518518
519519
You must be authorized to edit the group.
@@ -535,6 +535,6 @@ def group_update(context, data_dict):
535535
# Callers that set context['allow_partial_update'] = True can choose to not
536536
# specify particular keys and they will be left at their existing
537537
# values. This includes: packages, users, groups, tags, extras
538-
return _group_or_org_update(
538+
return _querytool_group_or_org_update(
539539
context, data_dict
540540
)

ckanext/querytool/plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ def before_map(self, map):
210210
'group_edit', '/group/edit/{id}',
211211
controller=group_controller, action='edit'
212212
)
213+
map.connect(
214+
'group_new', '/group/new',
215+
controller=group_controller, action='new'
216+
)
217+
map.connect(
218+
'group_delete', '/group/delete/{id}',
219+
controller=group_controller, action='delete'
220+
)
213221

214222
# Query tool routes
215223
map.redirect('/querytool', '/querytool/groups',

ckanext/querytool/templates/group/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

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

1616
{% set ctrl = 'ckanext.querytool.controllers.querytool:QueryToolController' %}

ckanext/querytool/templates/group/snippets/group_form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<div class="form-actions">
7070
{% block delete_button %}
7171
{% if h.check_access('group_delete', {'id': data.id}) %}
72-
<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>
72+
<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>
7373
{% endif %}
7474
{% endblock %}
7575
<button class="btn btn-primary" name="save" type="submit">{% block save_text %}{{ _('Save Group') }}{% endblock %}</button>

0 commit comments

Comments
 (0)