Skip to content

Commit

Permalink
dev/v2.0.9 (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolidori committed Apr 20, 2023
1 parent eb213e2 commit 33ac548
Show file tree
Hide file tree
Showing 70 changed files with 2,994 additions and 227 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ The extension supports some optional configurations:

- OpenStreetMaps
- Cookie Control
- reCAPTCHA v2 on login page

#### Optional Map Config Settings

Expand Down Expand Up @@ -293,6 +294,16 @@ ckanext.querytool.cc.initial_state = OPEN # Or CLOSED

By default, if `enabled` is true, only `api_key` is required for the Cookie Control to work. Currently, it considers `auth_tkt` as a core cookie and Google Analytics Cookies as optionals. An API key can be generated by [registering here](https://www.civicuk.com/cookie-control/).

#### Optional reCAPTCHA v2 on login page

It's possible o enable reCAPTCHA v2 on the login page by setting the following environment variables:

```bash
# Example values
ckanext.querytool.recaptcha.sitekey = 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
ckanext.querytool.recaptcha.secretkey = 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
```

### Modify CSS

This extension uses LESS for styles. All changes must be made in one of the LESS
Expand Down
89 changes: 88 additions & 1 deletion ckanext/querytool/controllers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
from ckan.common import config, c, _
from ckan.plugins import toolkit
import ckan.lib.helpers as h
import ckanext.querytool.helpers as helpers
import ckan.lib.uploader as uploader
from ckan.common import response, request
from ckan.controllers.group import GroupController
import ckan.lib.navl.dictization_functions as dict_fns

from ckanext.querytool.logic.action import get as querytool_get
import ckanext.querytool.helpers as helpers

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,3 +79,88 @@ def read_report(self, id):

return self._render_template('group/reports.html', {'id': id})

def edit(self, id, data=None, errors=None, error_summary=None):
group_type = self._ensure_controller_matches_group_type(
id.split('@')[0])

context = {'model': model, 'session': model.Session,
'user': c.user,
'save': 'save' in request.params,
'for_edit': True,
'parent': request.params.get('parent', None)
}
data_dict = {'id': id, 'include_datasets': False}

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

try:
data_dict['include_datasets'] = False
old_data = self._action('group_show')(context, data_dict)
c.grouptitle = old_data.get('title')
c.groupname = old_data.get('name')
data = data or old_data
except (NotFound, NotAuthorized):
abort(404, _('Group not found'))

group = context.get("group")
c.group = group
c.group_dict = self._action('group_show')(context, data_dict)

try:
self._check_access('group_update', context)
except NotAuthorized:
abort(403, _('User %r not authorized to edit %s') % (c.user, id))

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

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

def _save_edit(self, id, context):
try:
data_dict = clean_dict(dict_fns.unflatten(
tuplize_dict(parse_params(request.params))))

# Handle child groups that don't exist
group_children = data_dict.get('children', [])

if group_children:
group_children = group_children.split(',') if group_children else []
groups = logic.get_action('group_list')(context, {})
invalid_groups = []

for child in group_children:
if child not in groups:
invalid_groups.append(child)

if invalid_groups:
error = {
'Children': 'Invalid child group(s) - %s' % ', '.join(invalid_groups)
}
errors = error
error_summary = error

return self.edit(id, data_dict, errors, error_summary)

context['message'] = data_dict.get('log_message', '')
data_dict['id'] = id
context['allow_partial_update'] = True
group = self._action('group_update')(context, data_dict)
if id != group['name']:
self._force_reindex(group)

h.redirect_to('%s_read' % group['type'], 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.edit(id, data_dict, errors, error_summary)
169 changes: 140 additions & 29 deletions ckanext/querytool/controllers/querytool.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ckan.plugins import toolkit
import ckan.lib.helpers as h
import ckanext.querytool.helpers as helpers
import ckanext.querytool.model as qmodel
import ckan.lib.uploader as uploader
from ckan.common import response, request

Expand Down Expand Up @@ -843,51 +844,145 @@ def querytool_public_reports(self):
Lists all available groups
:return: base template
'''
parent_name = toolkit.request.params.get('parent')
q = toolkit.request.params.get('report_q', '')
context = _get_context()
groups = helpers.get_groups()

querytools = _get_action('querytool_list_other', {'groups': groups})
extra_vars = {}

if parent_name == '__misc__group__':
misc_groups = _get_action('get_available_groups', {})
misc_groups = ','.join([
group['name'] for group in misc_groups
if group['group_relationship_type'] != 'parent'
])
querytool_search_results = qmodel.child_group_report_search(
query_string=q, query_children=misc_groups
)
querytools = [
querytool for querytool in querytool_search_results
]
extra_vars['parent'] = parent_name

q = toolkit.request.params.get('report_q', '')
elif parent_name:
parent_group = _get_action('group_show', {'id': parent_name})
children_names = parent_group.get('children')

if q:
querytool_search_results = helpers.querytool_search(query_string=q)
querytool_search_results_names = [
querytool.name for querytool in querytool_search_results
]
querytool_search_results = qmodel.child_group_report_search(
query_string=q, query_children=children_names
)
querytools = [
querytool for querytool in querytools if
querytool['name'] in querytool_search_results_names
querytool for querytool in querytool_search_results
]

return render('querytool/public/reports.html',
extra_vars={'data': querytools})
else:
groups = helpers.get_groups()

querytools = _get_action('querytool_list_other', {'groups': groups})

if q:
querytool_search_results = helpers.querytool_search(query_string=q)
querytool_search_results_names = [
querytool.name for querytool in querytool_search_results
]
querytools = [
querytool for querytool in querytools if
querytool['name'] in querytool_search_results_names
]

extra_vars['data'] = querytools

return render(
'querytool/public/reports.html',
extra_vars=extra_vars
)


def querytool_public_list(self, group):
'''
List all of the available query tools
:return: querytool list template page
'''
querytools = _get_action('querytool_public_list', {'group': group})
from_parent = toolkit.request.params.get('from_parent', False)
parent_group_children = toolkit.request.params.get('parent_group_children', False)
parent_title = toolkit.request.params.get('title', False)
q = toolkit.request.params.get('report_q', '')

if group == '__misc__group__':
group = {
'misc_group': True,
'title': 'Other',
'description': 'Miscellaneous groups',
'name': '__misc__group__'
}
child_group_search_results = []

if q:
child_group_search_results = helpers.child_group_search(
query_string=q,
query_children=parent_group_children,
misc_group=True
)

return render(
'querytool/public/list.html',
extra_vars={
'child_groups': child_group_search_results,
'group': group,
'from_parent': True,
'title': parent_title
}
)

group_details = _get_action('group_show', {'id': group})

q = toolkit.request.params.get('report_q', '')
if from_parent and parent_group_children:
child_group_search_results = []

if q:
querytool_search_results = helpers.querytool_search(
query_string=q, query_group=group
if q:
child_group_search_results = helpers.child_group_search(
query_string=q, query_children=parent_group_children
)

return render(
'querytool/public/list.html',
extra_vars={
'child_groups': child_group_search_results,
'group': group_details,
'from_parent': True,
'title': parent_title
}
)
querytool_search_results_names = [
querytool.name for querytool in querytool_search_results
]
querytools = [
querytool for querytool in querytools if
querytool['name'] in querytool_search_results_names
]
else:
querytools = _get_action('querytool_public_list', {'group': group})

return render('querytool/public/list.html',
extra_vars={'data': querytools, 'group': group_details})
if q:
querytool_search_results = helpers.querytool_search(
query_string=q, query_group=group
)
querytool_search_results_names = [
querytool.name for querytool in querytool_search_results
]
querytools = [
querytool for querytool in querytools if
querytool['name'] in querytool_search_results_names
]

if from_parent:
extra_vars = {
'data': querytools,
'group': group_details,
'from_parent': True,
'title': parent_title
}
else:
extra_vars = {
'data': querytools,
'group': group_details
}
return render(
'querytool/public/list.html',
extra_vars=extra_vars
)

def querytool_public_read(self, name):
'''
Expand Down Expand Up @@ -921,6 +1016,10 @@ def querytool_public_read(self, name):

params = toolkit.request.params

parent = params.get('parent', None)
parent_title = params.get('title', None)
from_parent = params.get('from_parent', False)

querytools = []
items = []
items.append({u'order': 0, u'name': querytool['name']})
Expand Down Expand Up @@ -1021,8 +1120,20 @@ def querytool_public_read(self, name):

embed = True if 'embed' in params and params['embed'] == 'true' else False

return render('querytool/public/read.html',
extra_vars={'querytools': querytools, 'embed': embed})
extra_vars = {
'querytools': querytools,
'embed': embed
}

if parent and parent_title and from_parent:
extra_vars['parent'] = parent
extra_vars['parent_title'] = parent_title
extra_vars['from_parent'] = from_parent

return render(
'querytool/public/read.html',
extra_vars=extra_vars
)

def querytool_download_data(self, name):
params = request.params
Expand Down
Loading

0 comments on commit 33ac548

Please sign in to comment.