still doesn't work correctly, but saving progress anyway
This commit is contained in:
parent
5972787789
commit
758a52264e
3 changed files with 73 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import os
|
||||
from flask import Flask, render_template
|
||||
from flask import Flask, render_template, request
|
||||
from flask_login import LoginManager
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
from config import Config
|
||||
|
|
|
|||
|
|
@ -15,8 +15,12 @@ class InspectionForm(FlaskForm):
|
|||
installation_name = StringField('Installation Name', validators=[DataRequired(), Length(max=200)])
|
||||
location = StringField('Location', validators=[DataRequired(), Length(max=200)])
|
||||
inspection_date = DateField('Inspection Date', validators=[DataRequired()])
|
||||
version = IntegerField('Version', validators=[DataRequired()], default=1)
|
||||
reference_number = IntegerField('Reference Number', validators=[DataRequired()])
|
||||
|
||||
# General comments
|
||||
general_comments = TextAreaField('General Comments')
|
||||
|
||||
# Observations
|
||||
observations = TextAreaField('Observations')
|
||||
|
||||
|
|
@ -62,8 +66,10 @@ def inspection_new():
|
|||
installation_name=form.installation_name.data,
|
||||
location=form.location.data,
|
||||
inspection_date=form.inspection_date.data,
|
||||
version=form.version.data,
|
||||
reference_number=form.reference_number.data,
|
||||
observations=form.observations.data,
|
||||
general_comments=form.general_comments.data,
|
||||
conclusion_text=form.conclusion_text.data,
|
||||
conclusion_status=form.conclusion_status.data,
|
||||
created_by_id=current_user.id
|
||||
|
|
@ -89,6 +95,31 @@ def inspection_new():
|
|||
)
|
||||
db.session.add(inspector_entry)
|
||||
|
||||
# Handle photo uploads
|
||||
if 'photos' in request.files:
|
||||
files = request.files.getlist('photos')
|
||||
for file in files:
|
||||
if file and file.filename:
|
||||
filename = secure_filename(file.filename)
|
||||
if filename:
|
||||
# Generate unique filename
|
||||
import uuid
|
||||
unique_filename = f"{uuid.uuid4().hex}_{filename}"
|
||||
# Create uploads directory if it doesn't exist
|
||||
upload_dir = 'uploads'
|
||||
os.makedirs(upload_dir, exist_ok=True)
|
||||
file_path = os.path.join(upload_dir, unique_filename)
|
||||
file.save(file_path)
|
||||
|
||||
# Create Photo record
|
||||
photo = Photo(
|
||||
inspection_id=inspection.id,
|
||||
filename=unique_filename,
|
||||
caption='', # Default empty caption
|
||||
action_required='none' # Default action required
|
||||
)
|
||||
db.session.add(photo)
|
||||
|
||||
db.session.commit()
|
||||
flash('Inspection report created successfully.', 'success')
|
||||
return redirect(url_for('inspections.inspection_view', id=inspection.id))
|
||||
|
|
@ -130,15 +161,13 @@ def inspection_edit(id):
|
|||
inspection.installation_name = form.installation_name.data
|
||||
inspection.location = form.location.data
|
||||
inspection.inspection_date = form.inspection_date.data
|
||||
inspection.version = form.version.data
|
||||
inspection.reference_number = form.reference_number.data
|
||||
inspection.observations = form.observations.data
|
||||
inspection.conclusion_text = form.conclusion_text.data
|
||||
inspection.conclusion_status = form.conclusion_status.data
|
||||
inspection.updated_at = datetime.utcnow()
|
||||
|
||||
# Increment version
|
||||
inspection.version += 1
|
||||
|
||||
# Update inspectors
|
||||
InspectionInspector.query.filter_by(inspection_id=inspection.id).delete()
|
||||
for inspector in form.inspectors.data:
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="sm:col-span-6">
|
||||
{{ form.installation_name.label(class="block text-sm font-medium text-gray-700 mb-1") }}
|
||||
{{ form.installation_name(class="form-input") }}
|
||||
|
|
@ -81,6 +79,42 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="text-xl font-semibold text-gray-900">General Comments</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6">
|
||||
<div class="sm:col-span-6">
|
||||
{{ form.general_comments.label(class="block text-sm font-medium text-gray-700 mb-1") }}
|
||||
{{ form.general_comments(class="form-textarea") }}
|
||||
{% if form.general_comments.errors %}
|
||||
<ul class="mt-2 text-sm text-red-600">
|
||||
{% for error in form.general_comments.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="text-xl font-semibold text-gray-900">Photo Upload</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6">
|
||||
<div class="sm:col-span-6">
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Upload Photos</label>
|
||||
<input type="file" id="photo-upload" name="photos" multiple accept="image/*" class="form-input">
|
||||
<p class="mt-1 text-sm text-gray-500">Select one or more images to upload</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="text-xl font-semibold text-gray-900">Inspection Results</h2>
|
||||
|
|
@ -100,11 +134,11 @@
|
|||
</div>
|
||||
|
||||
<div class="sm:col-span-6">
|
||||
{{ form.comments.label(class="block text-sm font-medium text-gray-700 mb-1") }}
|
||||
{{ form.comments(class="form-textarea") }}
|
||||
{% if form.comments.errors %}
|
||||
{{ form.conclusion_text.label(class="block text-sm font-medium text-gray-700 mb-1") }}
|
||||
{{ form.conclusion_text(class="form-textarea") }}
|
||||
{% if form.conclusion_text.errors %}
|
||||
<ul class="mt-2 text-sm text-red-600">
|
||||
{% for error in form.comments.errors %}
|
||||
{% for error in form.conclusion_text.errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
|||
Loading…
Reference in a new issue