diff --git a/routes/create.py b/routes/create.py index 0975cf3..e4abc7c 100644 --- a/routes/create.py +++ b/routes/create.py @@ -10,7 +10,7 @@ addasset_bp = Blueprint('addasset', __name__) def create(): if request.method == 'GET': # Render the "add item" form - return render_template('create.html', item_attributes=item_attributes) + return render_template('item_form.html', item_attributes=item_attributes, item=None) # Process submitted form if request.method == 'POST': @@ -20,7 +20,7 @@ def create(): # Form validation error = validate_values(form_data) if error: - return render_template('create.html', item_attributes=item_attributes, error=error) + return render_template('item_form.html', item_attributes=item_attributes, item=None, error=error) # Create the Asset object item = Asset(**form_data) @@ -35,15 +35,15 @@ def create(): error = f"An entry with {primary_attrib.display_name} '{form_data[primary_attrib.attrib_name]}' already exists." else: error = "An entry with the same primary key already exists." - return render_template('create.html', item_attributes=item_attributes, error=error) + return render_template('item_form.html', item_attributes=item_attributes, item=None, error=error) except exc.StatementError as e: # Handle other database errors error = f"Database error: {str(e)}" - return render_template('create.html', item_attributes=item_attributes, error=error) + return render_template('item_form.html', item_attributes=item_attributes, item=None, error=error) except Exception as e: # Handle unexpected errors error = f"An unexpected error occurred: {str(e)}" - return render_template('create.html', item_attributes=item_attributes, error=error) + return render_template('item_form.html', item_attributes=item_attributes, item=None, error=error) # Redirect to /viewall on success return redirect('/viewall') \ No newline at end of file diff --git a/routes/update.py b/routes/update.py index fdf7948..bc06ee1 100644 --- a/routes/update.py +++ b/routes/update.py @@ -20,7 +20,7 @@ def update(primary_value): if request.method == 'GET': # Render the update form with the current item data - return render_template('update.html', item=item, item_attributes=item_attributes) + return render_template('item_form.html', item=item, item_attributes=item_attributes) if request.method == 'POST': # Get data from form @@ -29,7 +29,7 @@ def update(primary_value): # Form validation error = validate_values(form_data) if error: - return render_template('update.html', item=item, item_attributes=item_attributes, error=error) + return render_template('item_form.html', item=item, item_attributes=item_attributes, error=error) # Update the item with the new data for attrib in item_attributes: @@ -40,15 +40,15 @@ def update(primary_value): except exc.IntegrityError: # Handle duplicate primary key or unique constraint errors error = f"An entry with {primary_attrib.display_name} '{form_data[primary_attrib.attrib_name]}' already exists." - return render_template('update.html', item=item, item_attributes=item_attributes, error=error) + return render_template('item_form.html', item=item, item_attributes=item_attributes, error=error) except exc.StatementError as e: # Handle other database errors error = f"Database error: {str(e)}" - return render_template('update.html', item=item, item_attributes=item_attributes, error=error) + return render_template('item_form.html', item=item, item_attributes=item_attributes, error=error) except Exception as e: # Handle unexpected errors error = f"An unexpected error occurred: {str(e)}" - return render_template('update.html', item=item, item_attributes=item_attributes, error=error) + return render_template('item_form.html', item=item, item_attributes=item_attributes, error=error) # Redirect to /viewall on success return redirect('/viewall') \ No newline at end of file diff --git a/templates/create.html b/templates/item_form.html similarity index 72% rename from templates/create.html rename to templates/item_form.html index 06ce7b3..68793c9 100644 --- a/templates/create.html +++ b/templates/item_form.html @@ -2,17 +2,17 @@
-{{ error }}
{% endif %} - + diff --git a/templates/update.html b/templates/update.html deleted file mode 100644 index 628f202..0000000 --- a/templates/update.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - -{{ error }}
- {% endif %} - - - - - \ No newline at end of file