first pass at using jinja2 to make an edit form dynamically, its a bit hit and miss :(
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
<html>
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.18.0/dist/bootstrap-table.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.22/css/dataTables.bootstrap4.min.css">
|
||||
<script src="https://kit.fontawesome.com/9b4c7cf470.js" crossorigin="anonymous"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.18.0/dist/bootstrap-table.min.css">
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.22/css/dataTables.bootstrap4.min.css">
|
||||
<script src="https://kit.fontawesome.com/9b4c7cf470.js" crossorigin="anonymous"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
{% if books is not mapping %}
|
||||
<h3>All Books</h1>
|
||||
@@ -44,22 +44,49 @@
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<h3>Book</h1>
|
||||
<p>{{books.title}}, {{ books.author[0]['surname'] }}, {{books.author[0]['firstnames']}} </p>
|
||||
{% if books.sub_book is defined %}
|
||||
<p>sub_book is defined: {{books.sub_book}}</p>
|
||||
{% endif %}
|
||||
<h3>View/Edit Book</h1>
|
||||
{% set keys = [ 'title', 'author', 'publisher', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<form class="form">
|
||||
{% for key in keys %}
|
||||
<div class="form-group row">
|
||||
<label for="{{key}}" class="col-sm-4 col-form-label">{{key}}:</label>
|
||||
<div class="col-sm-8">
|
||||
{% if books[key] is iterable and books[key] is not string %}
|
||||
{% for objects in books[key] %}
|
||||
{% for attr in objects %}
|
||||
<label for="{{attr}}" class="col-sm-4 col-form-label">{{attr}}:</label>
|
||||
<input type="text" class="form-control" id="not-sure-{{key}}-{{attr}}" value="{{objects[attr]}}">
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% if key == "notes" or key == "blurb" %}
|
||||
<textarea rows="10" type="text" class="form-control" id="{{key}}">{{books[key]}}</textarea>
|
||||
{% else %}
|
||||
<input type="text" class="form-control" id="{{key}}" value="{{books[key]}}">
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div class="form-group">
|
||||
{% endfor %}
|
||||
</form>
|
||||
</div class="row">
|
||||
</div class="container">
|
||||
{% if books.sub_book is defined %}
|
||||
<p>sub_book is defined: {{books.sub_book}}</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<!-- code to get bootstrap & bootstrap datatable to work -->
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.10.22/js/dataTables.bootstrap4.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#book_table').DataTable( { 'pageLength': 25 } );
|
||||
} );
|
||||
$(document).ready(function() {
|
||||
$('#book_table').DataTable( { 'pageLength': 25 } );
|
||||
} );
|
||||
</script>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user