diff --git a/ckanext/datavic_odp_theme/config.py b/ckanext/datavic_odp_theme/config.py index 9534d42..2393cfa 100644 --- a/ckanext/datavic_odp_theme/config.py +++ b/ckanext/datavic_odp_theme/config.py @@ -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" @@ -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, "") diff --git a/ckanext/datavic_odp_theme/grunt/sass/_form.scss b/ckanext/datavic_odp_theme/grunt/sass/_form.scss index 3c9baf9..38e2dc4 100644 --- a/ckanext/datavic_odp_theme/grunt/sass/_form.scss +++ b/ckanext/datavic_odp_theme/grunt/sass/_form.scss @@ -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 { diff --git a/ckanext/datavic_odp_theme/grunt/sass/_resources.scss b/ckanext/datavic_odp_theme/grunt/sass/_resources.scss index 7b0202d..a68a415 100644 --- a/ckanext/datavic_odp_theme/grunt/sass/_resources.scss +++ b/ckanext/datavic_odp_theme/grunt/sass/_resources.scss @@ -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; } diff --git a/ckanext/datavic_odp_theme/helpers.py b/ckanext/datavic_odp_theme/helpers.py index 4a863aa..b77b657 100644 --- a/ckanext/datavic_odp_theme/helpers.py +++ b/ckanext/datavic_odp_theme/helpers.py @@ -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""" @@ -261,6 +284,7 @@ def datavic_update_org_error_dict( return error_dict + @helper def resource_attributes(attrs): try: diff --git a/ckanext/datavic_odp_theme/logic/__init__.py b/ckanext/datavic_odp_theme/logic/__init__.py index c150b40..676357d 100644 --- a/ckanext/datavic_odp_theme/logic/__init__.py +++ b/ckanext/datavic_odp_theme/logic/__init__.py @@ -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, } diff --git a/ckanext/datavic_odp_theme/logic/action.py b/ckanext/datavic_odp_theme/logic/action.py index 13489cb..ffcb3a9 100644 --- a/ckanext/datavic_odp_theme/logic/action.py +++ b/ckanext/datavic_odp_theme/logic/action.py @@ -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 @@ -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] diff --git a/ckanext/datavic_odp_theme/logic/auth/get.py b/ckanext/datavic_odp_theme/logic/auth/get.py index ae53426..8c4f3cf 100644 --- a/ckanext/datavic_odp_theme/logic/auth/get.py +++ b/ckanext/datavic_odp_theme/logic/auth/get.py @@ -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} @@ -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} \ No newline at end of file diff --git a/ckanext/datavic_odp_theme/logic/scheme.py b/ckanext/datavic_odp_theme/logic/scheme.py new file mode 100644 index 0000000..1e43176 --- /dev/null +++ b/ckanext/datavic_odp_theme/logic/scheme.py @@ -0,0 +1,10 @@ +from ckan.logic.schema import validator_args + + +@validator_args +def datatables_view_prioritize(not_empty): + return { + "resource_id": [ + not_empty, + ], + } diff --git a/ckanext/datavic_odp_theme/templates/package/snippets/datavic_dtv.html b/ckanext/datavic_odp_theme/templates/package/snippets/datavic_dtv.html index 8b2fe50..ba8f4be 100644 --- a/ckanext/datavic_odp_theme/templates/package/snippets/datavic_dtv.html +++ b/ckanext/datavic_odp_theme/templates/package/snippets/datavic_dtv.html @@ -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 %}

{{ _('Map preview') }}

diff --git a/ckanext/datavic_odp_theme/templates/package/snippets/resource_view.html b/ckanext/datavic_odp_theme/templates/package/snippets/resource_view.html index 1bfd4fb..a4367a3 100644 --- a/ckanext/datavic_odp_theme/templates/package/snippets/resource_view.html +++ b/ckanext/datavic_odp_theme/templates/package/snippets/resource_view.html @@ -30,9 +30,6 @@

{{ _('This resource view is not available at the moment.') }} - - {{ _('Click here for more information.') }} -

diff --git a/ckanext/datavic_odp_theme/templates/scheming/package/resource_read.html b/ckanext/datavic_odp_theme/templates/scheming/package/resource_read.html index 09a67b2..fd08553 100644 --- a/ckanext/datavic_odp_theme/templates/scheming/package/resource_read.html +++ b/ckanext/datavic_odp_theme/templates/scheming/package/resource_read.html @@ -101,7 +101,8 @@

{{ _('Data Dictionary') }}

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] -%} {{- h.scheming_language_text(field.label) -}} diff --git a/ckanext/datavic_odp_theme/templates/snippets/package_item.html b/ckanext/datavic_odp_theme/templates/snippets/package_item.html index 338a519..b6f06bc 100644 --- a/ckanext/datavic_odp_theme/templates/snippets/package_item.html +++ b/ckanext/datavic_odp_theme/templates/snippets/package_item.html @@ -79,19 +79,27 @@

{% endblock %} {% endif %}
    - {% 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 %} -
  • - {% if digital_twin_resources %} - - {% endif %} - {% if featured_resource %} - - {% endif %} - {{ _('Preview') }} -
  • - {% endif %} +
      + {% 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]) %} + +
    • + + {{ _('Preview') }} +
    • + {% endif %} + + {% if featured_resource %} +
    • + {{ _('Preview') }} +
    • + {% endif %} +
    + {% set datastore_loaded_resources = h.datastore_loaded_resources(package) %} {% if datastore_loaded_resources %}
  • diff --git a/ckanext/datavic_odp_theme/webassets/css/datavic_odp_theme.css b/ckanext/datavic_odp_theme/webassets/css/datavic_odp_theme.css index 2d8e3aa..f14305a 100644 --- a/ckanext/datavic_odp_theme/webassets/css/datavic_odp_theme.css +++ b/ckanext/datavic_odp_theme/webassets/css/datavic_odp_theme.css @@ -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 { @@ -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; }