Skip to content

Commit

Permalink
Merge pull request #259 from qld-gov-au/develop
Browse files Browse the repository at this point in the history
Develop to master - replace obsolete Pylons global object
  • Loading branch information
ThrawnCA authored Dec 9, 2024
2 parents b9a2457 + 8afd1a3 commit e769700
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 38 deletions.
10 changes: 5 additions & 5 deletions ckanext/data_qld/controller_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import json

from ckantoolkit import _, abort, c, check_access, g, get_action, \
from ckantoolkit import _, abort, check_access, g, get_action, \
redirect_to, NotAuthorized, ObjectNotFound, url_for, \
ValidationError, render

Expand Down Expand Up @@ -38,17 +38,17 @@ def open_datarequest(id):
context = _get_context()

# Basic initialization
c.datarequest = {}
datarequest = {}
try:
check_access(OPEN_DATAREQUEST, context, data_dict)
c.datarequest = get_action(SHOW_DATAREQUEST)(context, data_dict)
datarequest = get_action(SHOW_DATAREQUEST)(context, data_dict)

if c.datarequest.get('closed', False) is False:
if datarequest.get('closed', False) is False:
return abort(403, _('This data request is already open'))
else:
data_dict = {}
data_dict['id'] = id
data_dict['organization_id'] = c.datarequest.get('organization_id')
data_dict['organization_id'] = datarequest.get('organization_id')

get_action(OPEN_DATAREQUEST)(context, data_dict)
return redirect_to(url_for('datarequest.show', id=data_dict['id']))
Expand Down
12 changes: 1 addition & 11 deletions ckanext/data_qld/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ckan import model
from ckan.lib import uploader
from ckantoolkit import _, c, g, h, abort, asbool, check_ckan_version, \
from ckantoolkit import _, g, h, abort, asbool, check_ckan_version, \
config, get_action, get_endpoint, ObjectNotFound, render, request, \
aslist

Expand Down Expand Up @@ -207,16 +207,6 @@ def dashboard_index_route():
return 'dashboard.index'


def get_all_groups():
groups = get_action('group_list')(
data_dict={'include_dataset_count': False, 'all_fields': True})
pkg_group_ids = set(group['id'] for group
in c.pkg_dict.get('groups', []))
return [[group['id'], group['display_name']]
for group in groups if
group['id'] not in pkg_group_ids]


def get_comment_notification_recipients_enabled():
return config.get('ckan.comments.follow_mute_enabled', False)

Expand Down
1 change: 0 additions & 1 deletion ckanext/data_qld/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def get_helpers(self):
'ytp_comments_enabled': helpers.ytp_comments_enabled,
'dashboard_index_route': helpers.dashboard_index_route,
'is_datarequests_enabled': helpers.is_datarequests_enabled,
'get_all_groups': helpers.get_all_groups,
'is_request_for_resource': helpers.is_request_for_resource,
'set_background_image_class': helpers.set_background_image_class,
'set_external_resources': helpers.set_external_resources,
Expand Down
13 changes: 11 additions & 2 deletions ckanext/data_qld/templates/datarequests/close.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
{% ckan_extends %}
{#
Handle either old Pylons-style global variables, or newer template parameters.
#}
{% if datarequest is not defined %}
{% set datarequest = c.datarequest %}
{% set datasets = c.datasets %}
{% set errors = c.errors %}
{% set errors_summary = c.errors_summary %}
{% endif %}

{% block subtitle %}{{ _('Close data request') }}{% endblock %}

{% block breadcrumb_content %}
<li>{% link_for _('Data requests'), named_route='datarequest.index' %}</li>
<li>{% link_for c.datarequest.get('title')|truncate(30), named_route='datarequest.show', id=c.datarequest.get('id') %}</li>
<li>{% link_for datarequest.get('title')|truncate(30), named_route='datarequest.show', id=datarequest.get('id') %}</li>
<li class="active"><a href="">{{ _('Close data request') }}</a></li>
{% endblock %}

{% block primary_content_inner %}
<h1 class="{% block page_heading_class %}page-heading{% endblock %}">{% block page_heading %}{{ _('Close data request') }}{% endblock %}</h1>
{% snippet "datarequests/snippets/close_datarequest_form.html", datarequest=c.datarequest, datasets=c.datasets, errors=c.errors, errors_summary=c.errors_summary %}
{% snippet "datarequests/snippets/close_datarequest_form.html", datarequest=datarequest, datasets=datasets, errors=errors, errors_summary=errors_summary %}
{% endblock %}

{% block page_header %}{% endblock %}
8 changes: 7 additions & 1 deletion ckanext/data_qld/templates/datarequests/comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@


{% block primary_content_inner %}
{#
Handle either old Pylons-style global variables, or newer template parameters.
#}
{% if datarequest is not defined %}
{% set datarequest = c.datarequest %}
{% endif %}

{% snippet "package/comment_list.html", content_type='datarequest', pkg_id=c.datarequest.id, pkg_name=c.datarequest.id, userobj=c.userobj %}
{% snippet "package/comment_list.html", content_type='datarequest', pkg_id=datarequest.id, pkg_name=datarequest.id, userobj=g.userobj %}

{% endblock %}
13 changes: 11 additions & 2 deletions ckanext/data_qld/templates/datarequests/edit.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
{% ckan_extends %}
{#
Handle either old Pylons-style global variables, or newer template parameters.
#}
{% if datarequest is not defined %}
{% set datarequest = c.datarequest %}
{% set errors = c.errors %}
{% set errors_summary = c.errors_summary %}
{% set original_title = c.original_title %}
{% endif %}

{% block subtitle %}{{ _('Edit data request') }}{% endblock %}

{% block breadcrumb_content %}
<li>{% link_for _('Data requests'), named_route='datarequest.index' %}</li>
<li>{% link_for c.original_title|truncate(30), named_route='datarequest.show', id=c.datarequest.get('id') %}</li>
<li>{% link_for original_title|truncate(30), named_route='datarequest.show', id=datarequest.get('id') %}</li>
<li class="active"><a href="">{{ _('Edit data request') }}</a></li>
{% endblock %}

{% block primary_content_inner %}
<h1 class="{% block page_heading_class %}page-heading{% endblock %}">{% block page_heading %}{{ _('Edit data request') }}{% endblock %}</h1>
{% snippet "datarequests/snippets/edit_datarequest_form.html", data=c.datarequest, errors=c.errors, errors_summary=c.errors_summary, offering=c.offering %}
{% snippet "datarequests/snippets/edit_datarequest_form.html", data=datarequest, errors=errors, errors_summary=errors_summary %}
{% endblock %}

{% block page_header %}{% endblock %}
2 changes: 1 addition & 1 deletion ckanext/data_qld/templates/datarequests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% link_for _('Add data request'), named_route='datarequest.new', class_='btn btn-primary', icon=h.get_plus_icon() %}
</div>
{% endif %}
{% if not c.user %}
{% if not g.user %}
<div class="page_primary_action">
{% link_for _('Login to create data request'), named_route='user.login', class_='btn btn-primary', came_from=h.full_current_url() %}
</div>
Expand Down
10 changes: 9 additions & 1 deletion ckanext/data_qld/templates/datarequests/new.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{% ckan_extends %}
{#
Handle either old Pylons-style global variables, or newer template parameters.
#}
{% if datarequest is not defined %}
{% set datarequest = c.datarequest %}
{% set errors = c.errors %}
{% set errors_summary = c.errors_summary %}
{% endif %}

{% block subtitle %}{{ _('Create data request') }}{% endblock %}

Expand All @@ -9,7 +17,7 @@

{% block primary_content_inner %}
<h1 class="{% block page_heading_class %}page-heading{% endblock %}">{% block page_heading %}{{ _('Create data request') }}{% endblock %}</h1>
{% snippet "datarequests/snippets/new_datarequest_form.html", data=c.datarequest, errors=c.errors, errors_summary=c.errors_summary, offering=c.offering %}
{% snippet "datarequests/snippets/new_datarequest_form.html", data=datarequest, errors=errors, errors_summary=errors_summary %}
{% endblock %}

{% block secondary_content_additional_info %}
Expand Down
14 changes: 10 additions & 4 deletions ckanext/data_qld/templates/datarequests/show.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{% ckan_extends %}
{#
Handle either old Pylons-style global variables, or newer template parameters.
#}
{% if datarequest is not defined %}
{% set datarequest = c.datarequest %}
{% endif %}

{% block title %}Data request {{c.datarequest.get('title', '')}}{% endblock %}
{% block title %}Data request {{datarequest.get('title', '')}}{% endblock %}

{% block breadcrumb_content %}
<li>{% link_for _('Data requests'), named_route='datarequest.index' %}</li>
<li>{% link_for c.datarequest.get('title'), named_route='datarequest.show', id=datarequest_id %}</li>
<li>{% link_for datarequest.get('title'), named_route='datarequest.show', id=datarequest_id %}</li>
{% endblock %}

{% block content_action %}
Expand All @@ -13,11 +19,11 @@
{% link_for _('Manage'), named_route='datarequest.update', id=datarequest_id, class_='btn btn-default', icon='wrench' %}
{% endif %}

{% if h.check_access('close_datarequest', {'id':datarequest_id }) and not c.datarequest.closed %}
{% if h.check_access('close_datarequest', {'id':datarequest_id }) and not datarequest.closed %}
{% link_for _('Close'), named_route='datarequest.close', id=datarequest_id, class_='btn btn-danger', icon='lock' %}
{% endif %}

{% if h.check_access('open_datarequest', {'id':datarequest_id }) and c.datarequest.closed %}
{% if h.check_access('open_datarequest', {'id':datarequest_id }) and datarequest.closed %}
{% link_for _('Re-open'), named_route='data_qld.open_datarequest', id=datarequest_id, class_='btn btn-success', icon='unlock' %}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<label class="control-label" for="field-accepted_dataset_id">{{ _("Accepted dataset") }}</label>
<div class="controls">
<select id="field-accepted_dataset_id" name="accepted_dataset_id" data-module="autocomplete">
<option value="" selected="selected">No Dataset</option>
<option value="" selected="selected">No Dataset</option>
{% for dataset in datasets %}
<option value="{{ dataset.get('name') }}">{{ dataset.get('title') }}</option>
{% endfor %}
Expand Down
10 changes: 5 additions & 5 deletions ckanext/data_qld/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<div class="account-masthead">
<div class="container">
{% block header_account_container_content %} {% if g.userobj %}
<div class="account avatar authed" data-module="me" data-me="{{ c.userobj.id }}">
<div class="account avatar authed" data-module="me" data-me="{{ g.userobj.id }}">
<ul class="unstyled">
{% block header_account_logged %} {% if c.userobj.sysadmin %}
{% block header_account_logged %} {% if g.userobj.sysadmin %}
<li>CKAN {{ h.ckan_version() }}</li>
<li>
<a href="{{ h.url_for('admin.index') }}" title="{{ _('Sysadmin settings') }}">
Expand All @@ -18,9 +18,9 @@
</li>
{% endif %}
<li>
<a href="{{ h.url_for('user.read', id=c.userobj.name) }}" class="image" title="{{ _('View profile') }}">
{{ h.gravatar((c.userobj.email_hash if c and c.userobj else ''), size=22) }}
<span class="username">{{ c.userobj.display_name }}</span>
<a href="{{ h.url_for('user.read', id=g.userobj.name) }}" class="image" title="{{ _('View profile') }}">
{{ h.gravatar((g.userobj.email_hash if g and g.userobj else ''), size=22) }}
<span class="username">{{ g.userobj.display_name }}</span>
</a>
</li>
{% set new_activities = h.new_activities() %}
Expand Down
4 changes: 2 additions & 2 deletions ckanext/data_qld/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% endblock %}

{% block maintag %}
<div role="main" class={{ h.set_background_image_class() }}>
<div role="main" class="main {{ h.set_background_image_class() }}">
{% endblock %}

{% block flash %}
Expand Down Expand Up @@ -80,4 +80,4 @@ <h1>My page content</h1>
</article>
{% endblock %}
</div>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion ckanext/data_qld/templates/report/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1>{{ report.title }}</h1>
<p>
{{ _('Generated') }}: {{ h.report__render_datetime(report_date, '%d/%m/%Y %H:%M') }}
</p>
{% if c.userobj.sysadmin %}
{% if g.userobj.sysadmin %}
<div class="panel panel-info" style="width=700px">
<div class="panel-heading"><strong>{% trans %}Refresh report{% endtrans %}</strong></div>
<div class="panel-body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{%- do exclude_fields.append('governance_acknowledgement') -%}
{%- endif -%}

{% if not h.resource_visibility_has_user_permission_for_org(pkg['owner_org'], c.userobj, 'create_dataset') %}
{% if not h.resource_visibility_has_user_permission_for_org(pkg['owner_org'], g.userobj, 'create_dataset') %}
{%- do exclude_fields.append('request_privacy_assessment') -%}
{%- do exclude_fields.append('privacy_assessment_result') -%}
{% endif %}
Expand Down

0 comments on commit e769700

Please sign in to comment.