Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.9.0 [PROD] #242

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ckanext/datavic_odp_theme/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"csv-geo-au",
"aus-geo-csv",
]
CONFIG_DTV_MAX_SIZE_LIMIT = "ckanext.datavicmain.dtv.max_size_limit"
CONFIG_DTV_URL = "ckanext.datavic_odp_theme.dtv.url"
CONFIG_DTV_EXTERNAL_LINK = "ckanext.datavic_odp_theme.dtv.external_link"

Expand Down Expand Up @@ -49,6 +50,10 @@ def get_dtv_supported_formats() -> set[str]:
}


def get_dtv_max_size_limit() -> str:
return tk.config.get(CONFIG_DTV_MAX_SIZE_LIMIT, "157286400")


def get_dtv_url() -> str:
return tk.config.get(CONFIG_DTV_URL, "")

Expand Down
5 changes: 5 additions & 0 deletions ckanext/datavic_odp_theme/grunt/sass/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ select.form-control {
appearance: auto;
}

.dataset-form {
.form-label[for="field-update_frequency"] {
margin-bottom: 0;
}
}

// hide URL button for upload widget
.organization-edit {
Expand Down
10 changes: 9 additions & 1 deletion ckanext/datavic_odp_theme/grunt/sass/_resources.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,17 @@ $primary-color: #0052C2;
}

.dataset-api {
ul {
padding-right: 50px;
display: inline-flex;

i {
margin-right: 3px;
}
}

li {
display: inline;
padding-right: 50px;
&:last-child {
padding-right: 0;
}
Expand Down
24 changes: 24 additions & 0 deletions ckanext/datavic_odp_theme/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,29 @@ def is_resource_downloadable(resource: dict[str, Any]) -> bool:
return False


@helper
def dtv_exceeds_max_size_limit(resource_id: str) -> bool:
"""Check if DTV resource exceeds the maximum file size limit
Args:
resource_id (str): DTV resource id
Returns:
bool: return True if dtv resource exceeds maximum file size limit set
in ckan config "ckanext.datavicmain.dtv.max_size_limit",
otherwise - False
"""
try:
resource = toolkit.get_action("resource_show")({}, {"id": resource_id})
except (toolkit.ObjectNotFound, toolkit.NotAuthorized):
return True

limit = conf.get_dtv_max_size_limit()
filesize = resource.get("filesize")
if filesize and int(filesize) >= int(limit):
return True

return False


@helper
def datastore_loaded_resources(pkg_dict: dict[str, Any]) -> list[str]:
"""Return a list of the dataset resources that are loaded to the datastore"""
Expand Down Expand Up @@ -261,6 +284,7 @@ def datavic_update_org_error_dict(

return error_dict


@helper
def resource_attributes(attrs):
try:
Expand Down
2 changes: 2 additions & 0 deletions ckanext/datavic_odp_theme/logic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def actions():
"resource_update": action.resource_update,
"resource_create": action.resource_create,
"datavic_list_incomplete_resources": action.datavic_list_incomplete_resources,
"datavic_datatables_view_prioritize": action.datavic_datatables_view_prioritize,
"resource_view_create": action.resource_view_create,
}


Expand Down
57 changes: 57 additions & 0 deletions ckanext/datavic_odp_theme/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from ckan import model
from ckan.types import Action, Context, DataDict
from ckan.types.logic import ActionResult
from ckan.logic import validate
from ckan.model import ResourceView
from ckanext.datavic_odp_theme.logic import scheme

from ckanext.datavic_odp_theme import jobs

Expand Down Expand Up @@ -198,3 +201,57 @@ def datavic_list_incomplete_resources(context, data_dict):
"num_packages": num_packages,
"results": results,
}


@validate(scheme.datatables_view_prioritize)
def datavic_datatables_view_prioritize(
context: Context, data_dict: DataDict
) -> ActionResult:
"""Check if the datatables view is prioritized over the recline view.
If not, swap their order.
"""
tk.check_access("vic_datatables_view_prioritize", context, data_dict)

resource_id = data_dict["resource_id"]
res_views = sorted(
model.Session.query(ResourceView)
.filter(ResourceView.resource_id == resource_id)
.all(),
key=lambda x: x.order,
)
datatables_views = _filter_views(res_views, "datatables_view")
recline_views = _filter_views(res_views, "recline_view")

if not (
datatables_views
and recline_views
and datatables_views[0].order > recline_views[0].order
):
return {"updated": False}

datatables_views[0].order, recline_views[0].order = (
recline_views[0].order,
datatables_views[0].order,
)
order = [view.id for view in sorted(res_views, key=lambda x: x.order)]
tk.get_action("resource_view_reorder")(
{"ignore_auth": True}, {"id": resource_id, "order": order}
)
return {"updated": True}


@tk.chained_action
def resource_view_create(next_, context, data_dict):
result = next_(context, data_dict)
if data_dict["view_type"] == "datatables_view":
tk.get_action("datavic_datatables_view_prioritize")(
{"ignore_auth": True}, {"resource_id": data_dict["resource_id"]}
)
return result


def _filter_views(
res_views: list[ResourceView], view_type: str
) -> list[ResourceView]:
"""Return a list of views with the given view type."""
return [view for view in res_views if view.view_type == view_type]
11 changes: 8 additions & 3 deletions ckanext/datavic_odp_theme/logic/auth/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def vic_activity_list(context, data_dict):
# DataVIC modification
if (
data_dict["object_type"] in ["package", "organization"]
and not authz.auth_is_loggedin_user()
and authz.auth_is_anon_user(context)
):
return {"success": False}

Expand All @@ -47,13 +47,18 @@ def vic_activity_list(context, data_dict):


@tk.chained_auth_function
def vic_package_activity_list(context, data_dict):
def vic_package_activity_list(next_auth, context, data_dict):
data_dict["object_type"] = "package"
return vic_activity_list(context, data_dict)


@tk.chained_auth_function
def vic_organization_activity_list(
context: dict[str, Any], group_dict: dict[str, str]
next_auth, context: dict[str, Any], group_dict: dict[str, str]
) -> dict[bool, bool]:
group_dict["object_type"] = "organization"
return vic_activity_list(context, group_dict)


def vic_datatables_view_prioritize(context, data_dict):
return {"success": False}
10 changes: 10 additions & 0 deletions ckanext/datavic_odp_theme/logic/scheme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ckan.logic.schema import validator_args


@validator_args
def datatables_view_prioritize(not_empty):
return {
"resource_id": [
not_empty,
],
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% set dtv_resources = h.get_digital_twin_resources(pkg.id)|map(attribute="id")|list %}
{% set dtv_preview = pkg.dtv_preview %}
{% set dtv_exceeds_limit = h.dtv_exceeds_max_size_limit(dtv_resources[0]) %}
{% set dtv_url = h.datavic_get_dtv_url() %}
{% set dtv_external_link = h.datavic_get_dtv_url(ext_link=True) %}


{% if dtv_resources and dtv_url and dtv_preview is not sameas false %}
{% if dtv_resources and not dtv_exceeds_limit and dtv_preview is not sameas false %}
<section class="datapreview resource-preview">
<div class="header-container">
<h3>{{ _('Map preview') }}</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
<p class="text-danger">
<i class="fa fa-info-circle"></i>
{{ _('This resource view is not available at the moment.') }}
<a href="#" data-bs-toggle="collapse" data-bs-target="#data-view-error">
{{ _('Click here for more information.') }}
</a>
</p>
<p id="data-view-error" class="collapse"></p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ <h2>{{ _('Data Dictionary') }}</h2>
or not res.filesize or res.filesize == "0" %}
{% else %}
{%- if field.field_name not in exclude_fields
and field.display_snippet is not none -%}
and field.display_snippet is not none
and res[field.field_name] -%}
<tr>
<th scope="row">
{{- h.scheming_language_text(field.label) -}}
Expand Down
34 changes: 21 additions & 13 deletions ckanext/datavic_odp_theme/templates/snippets/package_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,27 @@ <h4 class="search-result-organisation">
{% endblock %}
{% endif %}
<ul class="list-unstyled dataset-api">
{% set digital_twin_resources = h.get_digital_twin_resources(package.id) %}
{% set featured_resource = h.featured_resource_preview(package) %}
{% if digital_twin_resources or featured_resource %}
<li class="preview">
{% if digital_twin_resources %}
<i class="fa-solid fa-map-location-dot"></i>
{% endif %}
{% if featured_resource %}
<i class="fa-solid fa-table"></i>
{% endif %}
{{ _('Preview') }}
</li>
{% endif %}
<ul>
{% set dtv_resources = h.get_digital_twin_resources(package.id)|map(attribute="id")|list %}
{% set featured_resource = h.featured_resource_preview(package) %}

{% if dtv_resources %}
{% set dtv_preview_enabled = package.dtv_preview %}
{% set dtv_exceeds_limit = h.dtv_exceeds_max_size_limit(dtv_resources[0]) %}

<li class="preview {{ 'hidden' if dtv_exceeds_limit or not dtv_preview_enabled }}">
<i class="fa-solid fa-map-location-dot"></i>
<span class="{{ 'hidden' if featured_resource }}">{{ _('Preview') }}</span>
</li>
{% endif %}

{% if featured_resource %}
<li class="preview">
<i class="fa-solid fa-table"></i> {{ _('Preview') }}
</li>
{% endif %}
</ul>

{% set datastore_loaded_resources = h.datastore_loaded_resources(package) %}
{% if datastore_loaded_resources %}
<li class="api">
Expand Down
11 changes: 9 additions & 2 deletions ckanext/datavic_odp_theme/webassets/css/datavic_odp_theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -1728,9 +1728,13 @@ nav {
float: right;
color: #465870;
font-size: 0.875rem; }
.dataset-api ul {
padding-right: 50px;
display: inline-flex; }
.dataset-api ul i {
margin-right: 3px; }
.dataset-api li {
display: inline;
padding-right: 50px; }
display: inline; }
.dataset-api li:last-child {
padding-right: 0; }
.dataset-api i {
Expand Down Expand Up @@ -1921,6 +1925,9 @@ nav {
select.form-control {
appearance: auto; }

.dataset-form .form-label[for="field-update_frequency"] {
margin-bottom: 0; }

.organization-edit .image-upload .btn[title*="Link to a URL"] {
display: none !important; }

Expand Down