[PR #6561] [MERGED] CSV file import #13144

Closed
opened 2025-12-29 22:25:39 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/6561
Author: @abigley
Created: 6/7/2021
Status: Merged
Merged: 7/28/2021
Merged by: @jeremystretch

Base: developHead: csv_feature


📝 Commits (10+)

  • e1fe3ca CSV Upload as second field in existing form
  • 0c93760 working csv upload first draft
  • 2bc6870 csv parse using python csv library
  • 6ff5a1d cleaned up csv parsing
  • c2b2b05 CSV import implemented using CSVFileField
  • ecd84d7 edited docstring for CSVFileField
  • 3549fc0 removed unnecessary use of seek()
  • 55b7cf2 changed name of csv_file variable and started work on ValidationError
  • 934543b Caught and handled ValidationError
  • 0a66159 moved duplicated code in CSV Fields into functions in forms/utils.py

📊 Changes

4 files changed (+114 additions, -39 deletions)

View changed files

📝 netbox/netbox/views/generic.py (+17 -3)
📝 netbox/templates/generic/object_bulk_import.html (+1 -1)
📝 netbox/utilities/forms/fields.py (+43 -35)
📝 netbox/utilities/forms/utils.py (+53 -0)

📄 Description

Fixes: #6560

An example / first draft of a solution for #6560 .

In the current implementation, if users try to use both the CSVFileField and the CSVDataField, the CSVDataField will be ignored and only the objects in the file will be imported. It should be unusual that both fields are populated, but let me know if you prefer to handle that case differently, such as by raising a validation error. The csv file is checked for errors (incorrect formatting, objects already exist, invalid columns) before importing.

This solution involves some duplication between CSVFileField and CSVDataField. If you prefer, I could remove most of the duplication by refactoring them to both inherit from a single class - say, CSVParsingField.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/6561 **Author:** [@abigley](https://github.com/abigley) **Created:** 6/7/2021 **Status:** ✅ Merged **Merged:** 7/28/2021 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `csv_feature` --- ### 📝 Commits (10+) - [`e1fe3ca`](https://github.com/netbox-community/netbox/commit/e1fe3ca14a3cdfdf0826c5db03e4e5d60c62615e) CSV Upload as second field in existing form - [`0c93760`](https://github.com/netbox-community/netbox/commit/0c9376039c84a24a2d38bb316a601bb155d326bc) working csv upload first draft - [`2bc6870`](https://github.com/netbox-community/netbox/commit/2bc68707b5e82c0b868cb65a951ed5d02b691962) csv parse using python csv library - [`6ff5a1d`](https://github.com/netbox-community/netbox/commit/6ff5a1db42df4c3232c2c7f7bb6475d22747af1a) cleaned up csv parsing - [`c2b2b05`](https://github.com/netbox-community/netbox/commit/c2b2b059e6ac3dc5660d380f6d92528d73fd71dc) CSV import implemented using CSVFileField - [`ecd84d7`](https://github.com/netbox-community/netbox/commit/ecd84d7c430cf2c75f99440f5535bea7d367bdb1) edited docstring for CSVFileField - [`3549fc0`](https://github.com/netbox-community/netbox/commit/3549fc07f6b0a681ba2f74d645e78f2441c4a3e4) removed unnecessary use of seek() - [`55b7cf2`](https://github.com/netbox-community/netbox/commit/55b7cf21ccc834598bdb9d1a4bfd6ac0d3bc80fd) changed name of csv_file variable and started work on ValidationError - [`934543b`](https://github.com/netbox-community/netbox/commit/934543b595f4740397b76d836f79601ba688378f) Caught and handled ValidationError - [`0a66159`](https://github.com/netbox-community/netbox/commit/0a661596b3ff3d9e18024d8c621099bfa3eac45d) moved duplicated code in CSV Fields into functions in forms/utils.py ### 📊 Changes **4 files changed** (+114 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `netbox/netbox/views/generic.py` (+17 -3) 📝 `netbox/templates/generic/object_bulk_import.html` (+1 -1) 📝 `netbox/utilities/forms/fields.py` (+43 -35) 📝 `netbox/utilities/forms/utils.py` (+53 -0) </details> ### 📄 Description ### Fixes: #6560 An example / first draft of a solution for #6560 . In the current implementation, if users try to use both the `CSVFileField` and the `CSVDataField`, the `CSVDataField` will be ignored and only the objects in the file will be imported. It should be unusual that both fields are populated, but let me know if you prefer to handle that case differently, such as by raising a validation error. The csv file is checked for errors (incorrect formatting, objects already exist, invalid columns) before importing. This solution involves some duplication between `CSVFileField` and `CSVDataField`. If you prefer, I could remove most of the duplication by refactoring them to both inherit from a single class - say, `CSVParsingField`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:25:39 +01:00
adam closed this issue 2025-12-29 22:25:39 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13144