Skip to content

feat(webportal): Add export to Web Portal function#7994

Open
grantfitzsimmons wants to merge 47 commits into
mainfrom
issue-7606
Open

feat(webportal): Add export to Web Portal function#7994
grantfitzsimmons wants to merge 47 commits into
mainfrom
issue-7606

Conversation

@grantfitzsimmons

@grantfitzsimmons grantfitzsimmons commented Apr 18, 2026

Copy link
Copy Markdown
Member

Fixes #7606

This PR adds support for exporting query results as a Web Portal package (ZIP) for import into the Specify Web Portal. It introduces backend endpoints and logic for generating the export, updates frontend components to allow users to trigger and download the export, and adds appropriate permission checks and notifications. It even includes tests and validation improvements for tree-related queries.

At this time, exports using this tool require no changes on the Web Portal side of things.

Button in Query Builder Notification when complete
image image
Policy Note
image Users need to be given specific permission to be able to export to the web portal.

Web Portal Export Feature:

  • Added backend support for exporting queries as a Web Portal ZIP package via a new endpoint (exportwebportal/), including a new query_to_web_portal_zip function and integration with the export workflow.
  • Implemented frontend UI to trigger the Web Portal export from the query builder, including permission checks, export button, and download link in notifications.

Testing and Validation:

  • Added backend tests for the new export endpoint and attachment mapping logic.

Error Reporting
This also adds handling for error reporting if an export (either CSV, KML, or Web Portal) fails.

Screenshot 2026-04-26 at 9 37 03 PM

exampleWebPortalfailure.txt
exampleCSVfailure.txt
exampleKMLfailure.txt

Example

Specify Query

image

Portal

image

Attachments

image

Map

image

Uniqueness Check

image

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add relevant issue to release milestone
  • Add automated tests

Testing instructions

  • Confirm the new Export to Web Portal button appears in the query export controls (when you have permission).
  • Confirm the new Export to Web Portal button does not appear in the query export controls if you do not have permission to that tool (Querybuilder → Query → Export To Web Portal).
  • Start the export and wait for the completion notification.
  • Use the notification or download link to retrieve the generated ZIP package.
  • Open the ZIP and confirm it contains:
    • PortalFiles/PortalData.csv
    • PortalFiles/flds.json
    • PortalFiles/PortalInstanceSetting.json
    • PortalFiles/SolrFldSchema.xml
  • Inspect PortalFiles/flds.json and verify:
    • the spid and img rows are present
    • attachment metadata is emitted correctly (if there are attachments)
    • attachment Title is derived from attachment.title when available
  • Verify existing query export behavior still works for normal CSV exports.
  • Confirm tree-related query validation still passes after the new tree parsing validation changes.

DEVELOPERS: To really make sure this works, we need to import this into the Web Portal. To really make sure it is an adequate replacement for the Specify 6 exporter, it is a good idea to test the same export query in both versions. All KU databases have a mapping setup in them, which can be compared easily.

  • Import the ZIP into a Specify Web Portal instance to confirm the package can be ingested.
  • Verify that the rows in the query are the same count as the rows in the portal
  • Verify that all visible fields (within the 7 query itself) are searchable in the portal when using 'advanced' search
  • Verify that all attachments marked as public (via attachment.ispublic) are visible in the portal
  • Verify that the asset server URL and collection are set correctly (based on the docker environment for the Specify installation)
  • Verify that the map plots all points (as long as longitude1, latitude1, longitude2, or latitude2 are present, but keep If second set of coordinates fields are present, they are required for Geo Coords webportal-installer#64 in mind), and make sure they are clickable (so a dialog appears)
  • Check that the attachment 'Title' is shown in the dialog header when viewing an attachment
  • Verify that no unexpected console errors are logged in the web portal (no more than before, comparing against a standard Specify 6-exported data set in the portal)

Summary by CodeRabbit

  • New Features

    • "Export to Web Portal" added to Query Builder — permission-controlled ZIP export (data, images, metadata), endpoint and UI button included; duplicate-record-ID detection with a warning dialog.
  • Bug Fixes

    • Export flows for CSV, KML, and Web Portal now emit clear success/failure notifications and offer downloadable error payloads (including tracebacks when available).
  • Tests

    • New tests for web-portal export flow and field-spec parsing.
  • Localization

    • Localized messages for export success/failure and duplicate-ID warnings.

@grantfitzsimmons grantfitzsimmons marked this pull request as ready for review April 22, 2026 15:06
@grantfitzsimmons grantfitzsimmons modified the milestones: 7.12.2, 7.12.1 Apr 22, 2026
@lexiclevenger lexiclevenger requested a review from a team April 22, 2026 19:48

@lexiclevenger lexiclevenger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Confirm the new Export to Web Portal button appears in the query export controls (when you have permission).
  • Confirm the new Export to Web Portal button does not appear in the query export controls if you do not have permission to that tool (Querybuilder → Query → Export To Web Portal).
  • Start the export and wait for the completion notification.
  • Use the notification or download link to retrieve the generated ZIP package.
  • Open the ZIP and confirm it contains:
    • PortalFiles/PortalData.csv
    • PortalFiles/flds.json
    • PortalFiles/PortalInstanceSetting.json
    • PortalFiles/SolrFldSchema.xml
  • Inspect PortalFiles/flds.json and verify:
    • the spid and img rows are present
    • attachment metadata is emitted correctly (if there are attachments)
    • attachment Title is derived from attachment.title when available
  • Verify existing query export behavior still works for normal CSV exports.
  • Confirm tree-related query validation still passes after the new tree parsing validation changes.

Looks good to me! Tested using 'Vanessa Mapping 2' query on sbmnhiz_2025_12_12. The files appear as expected, and the existing query and csv export features don't seem to have been impacted.

@Iwantexpresso Iwantexpresso self-requested a review April 30, 2026 16:59

@Iwantexpresso Iwantexpresso left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Confirm the new Export to Web Portal button appears in the query export controls (when you have permission).
  • Confirm the new Export to Web Portal button does not appear in the query export controls if you do not have permission to that tool (Querybuilder → Query → Export To Web Portal).
  • Start the export and wait for the completion notification.
  • Use the notification or download link to retrieve the generated ZIP package.
  • Open the ZIP and confirm it contains:
    • PortalFiles/PortalData.csv
    • PortalFiles/flds.json
    • PortalFiles/PortalInstanceSetting.json
    • PortalFiles/SolrFldSchema.xml
  • Inspect PortalFiles/flds.json and verify:
    • the spid and img rows are present
    • attachment metadata is emitted correctly (if there are attachments)
    • attachment Title is derived from attachment.title when available
  • Verify existing query export behavior still works for normal CSV exports.
  • Confirm tree-related query validation still passes after the new tree parsing validation changes.

Dev Additions:
Thank you @melton-jason For quickly helping me set this up on a MacOS through a docker container. It was very useful and this should be considered as an addition to the web portal it can be deployed easily on other local machines besides linux distros

Another Note: whenever importing through docker there is an issue caused by the spaces within the ZIP file's names when building the container. The zip name format should be reconsidered at least for MacOS.

  • Import the ZIP into a Specify Web Portal instance to confirm the package can be ingested.

  • Verify that the rows in the query are the same count as the rows in the portal

  • Verify that all visible fields (within the 7 query itself) are searchable in the portal when using 'advanced' search

  • Verify that all attachments marked as public (via attachment.ispublic) are visible in the portal

  • Verify that the asset server URL and collection are set correctly (based on the docker environment for the Specify installation)

  • Verify that the map plots all points (as long as longitude1, latitude1, longitude2, or latitude2 are present, but keep specify/webportal-installer#64 in mind), and make sure they are clickable (so a dialog appears)

  • following 2 have been Skipped for now, I did not include any attachments to any CO in my query and its. a freshly rebuilt database. Finally, I have never seen console logs for an sp6 export data set, So far I have monitored the logs to my terminal and nothing seems out of the ordinary.

  • Check that the attachment 'Title' is shown in the dialog header when viewing an attachment

  • Verify that no unexpected console errors are logged in the web portal (no more than before, comparing against a standard Specify 6-exported data set in the portal)

overall functionality is great!. just ran into a couple of hiccups when setting up the web portal locally. besides that core functional of exporting and importing are running great!

@grantfitzsimmons

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

Warning

One or more dependencies are approaching or past End-of-Life.
Please plan upgrades accordingly.

STATUS=WARNING
NODE_VERSION=20
NODE_CYCLE=20
EOL_DATE=2026-04-30
DAYS_REMAINING=-77

--- Node.js ---
Version: 20
EOL: 2026-04-30
Status: WARNING

STATUS=OK
PYTHON_VERSION=3.12
PYTHON_CYCLE=3.12
EOL_DATE=2028-10-31
DAYS_REMAINING=838

--- Python ---
Version: 3.12
EOL: 2028-10-31
Status: OK

STATUS=WARNING
DJANGO_VERSION=4.2
DJANGO_CYCLE=4.2
EOL_DATE=2026-04-07
DAYS_REMAINING=-100

--- Django ---
Version: 4.2
EOL: 2026-04-07
Status: WARNING


Triggered by 4832a3f on branch refs/heads/issue-7606
Comment thread specifyweb/backend/stored_queries/views.py Fixed
Comment thread specifyweb/backend/stored_queries/views.py Fixed
Comment thread specifyweb/backend/inheritance/api.py Fixed
Comment thread specifyweb/backend/inheritance/api.py Fixed
Comment thread specifyweb/backend/inheritance/api.py Outdated
Comment thread specifyweb/backend/stored_queries/web_portal_export.py Fixed
from django.apps import apps
from django.conf import settings

from specifyweb.backend.context.schema_localization import get_schema_localization
Comment thread specifyweb/backend/stored_queries/web_portal_export.py Fixed
from specifyweb.backend.context.schema_localization import get_schema_localization
from specifyweb.specify.datamodel import datamodel, Field
from specifyweb.specify.models_utils.models_by_table_id import get_model_by_table_id
from specifyweb.specify.utils.uiformatters import CNNField, get_catalognumber_format
from specifyweb.specify.utils.uiformatters import CNNField, get_catalognumber_format

if TYPE_CHECKING:
from specifyweb.backend.stored_queries.queryfield import QueryField
CarolineDenis and others added 8 commits July 13, 2026 15:51
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread specifyweb/backend/stored_queries/views.py Fixed
Comment thread specifyweb/backend/stored_queries/queryfieldspec.py Fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Dev Attention Needed

Development

Successfully merging this pull request may close these issues.

Export to Web Portal

8 participants