Submit edited csv after preview
This commit is contained in:
parent
ae715af3e1
commit
4511cfdb90
@ -1,13 +1,17 @@
|
|||||||
from flask import Blueprint, redirect, session
|
from flask import Blueprint, redirect, session, request
|
||||||
from models import Asset, db
|
from models import Asset, db
|
||||||
|
import json
|
||||||
|
|
||||||
confirm_save_bp = Blueprint('confirm_save', __name__)
|
confirm_save_bp = Blueprint('confirm_save', __name__)
|
||||||
|
|
||||||
# When confirmed, write the csv data to the database
|
# When confirmed, write the csv data to the database
|
||||||
@confirm_save_bp.route('/confirm_save', methods=['POST'])
|
@confirm_save_bp.route('/confirm_save', methods=['POST'])
|
||||||
def confirm_save():
|
def confirm_save():
|
||||||
assets = session.get('assets', []) # Retrieve assets from session
|
edited_assets = json.loads(request.form['assets'])
|
||||||
for asset_data in assets:
|
session['assets'] = edited_assets
|
||||||
|
|
||||||
|
#assets = session.get('assets', []) # Retrieve assets from session
|
||||||
|
for asset_data in edited_assets:
|
||||||
asset = Asset(
|
asset = Asset(
|
||||||
assettag=asset_data['assettag'],
|
assettag=asset_data['assettag'],
|
||||||
hostname=asset_data['hostname'],
|
hostname=asset_data['hostname'],
|
||||||
|
@ -4,6 +4,30 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>CSV Preview</title>
|
<title>CSV Preview</title>
|
||||||
|
<script>
|
||||||
|
function collectEditedData() {
|
||||||
|
const rows = document.querySelectorAll('tbody tr');
|
||||||
|
const assets = [];
|
||||||
|
|
||||||
|
rows.forEach(row => {
|
||||||
|
const cells = row.querySelectorAll('td');
|
||||||
|
assets.push({
|
||||||
|
assettag: cells[0].innerText,
|
||||||
|
hostname: cells[1].innerText,
|
||||||
|
warrantyfrom: cells[2].innerText,
|
||||||
|
status: cells[3].innerText,
|
||||||
|
staffnum: cells[4].innerText
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add edited data to a hidden input
|
||||||
|
const input = document.createElement('input');
|
||||||
|
input.type = 'hidden';
|
||||||
|
input.name = 'assets';
|
||||||
|
input.value = JSON.stringify(assets);
|
||||||
|
document.querySelector('form').appendChild(input);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>CSV Preview</h1>
|
<h1>CSV Preview</h1>
|
||||||
@ -33,7 +57,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<!-- Form button to confirm and save data -->
|
<!-- Form button to confirm and save data -->
|
||||||
<form action="/confirm_save" method="POST">
|
<form action="/confirm_save" method="POST" onsubmit="collectEditedData()">
|
||||||
<button type="submit">Confirm and Save to Database</button>
|
<button type="submit">Confirm and Save to Database</button>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user