Mar 03 2026: enhanced inspection and issue workflow
This commit is contained in:
@@ -344,6 +344,13 @@ def execute(inspection_id):
|
|||||||
flash('Inspection submitted successfully!', 'success')
|
flash('Inspection submitted successfully!', 'success')
|
||||||
return redirect(url_for('inspections.view', inspection_id=inspection_id))
|
return redirect(url_for('inspections.view', inspection_id=inspection_id))
|
||||||
|
|
||||||
|
elif action == 'flag':
|
||||||
|
# Save current form state as a draft so no work is lost,
|
||||||
|
# then send the inspector to the issue creation page.
|
||||||
|
_save_draft(inspection, responses)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for('inspections.flag_issue', inspection_id=inspection_id))
|
||||||
|
|
||||||
else: # save draft
|
else: # save draft
|
||||||
_save_draft(inspection, responses)
|
_save_draft(inspection, responses)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|||||||
@@ -214,10 +214,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="d-flex gap-2 align-items-center">
|
<div class="d-flex gap-2 align-items-center">
|
||||||
<span class="freq-badge">{{ inspection.template.frequency|title }}</span>
|
<span class="freq-badge">{{ inspection.template.frequency|title }}</span>
|
||||||
<a href="{{ url_for('inspections.flag_issue', inspection_id=inspection.id) }}"
|
<button type="submit" name="action" value="flag"
|
||||||
class="btn btn-sm btn-outline-danger btn-outline-light">
|
class="btn btn-sm btn-outline-danger btn-outline-light"
|
||||||
|
onclick="return confirm('Your current progress will be saved automatically. Continue to flag an issue?')">
|
||||||
<i class="bi bi-exclamation-triangle"></i> Flag Issue
|
<i class="bi bi-exclamation-triangle"></i> Flag Issue
|
||||||
</a>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+12
-2
@@ -46,8 +46,8 @@ class ProfileForm(FlaskForm):
|
|||||||
class UserForm(FlaskForm):
|
class UserForm(FlaskForm):
|
||||||
username = StringField('Username', validators=[DataRequired(), Length(min=3, max=100)])
|
username = StringField('Username', validators=[DataRequired(), Length(min=3, max=100)])
|
||||||
email = StringField('Email', validators=[DataRequired(), Email(), Length(max=255)])
|
email = StringField('Email', validators=[DataRequired(), Email(), Length(max=255)])
|
||||||
password = PasswordField('Password', validators=[Length(min=6, max=100)])
|
password = PasswordField('Password', validators=[Optional(), Length(min=6, max=100)])
|
||||||
confirm_password = PasswordField('Confirm Password', validators=[EqualTo('password')])
|
confirm_password = PasswordField('Confirm Password', validators=[Optional(), EqualTo('password')])
|
||||||
role = SelectField('Role', choices=[
|
role = SelectField('Role', choices=[
|
||||||
('admin', 'Administrator'), ('supervisor', 'Supervisor'), ('inspector', 'Inspector')
|
('admin', 'Administrator'), ('supervisor', 'Supervisor'), ('inspector', 'Inspector')
|
||||||
], validators=[DataRequired()])
|
], validators=[DataRequired()])
|
||||||
@@ -56,6 +56,16 @@ class UserForm(FlaskForm):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.user = user
|
self.user = user
|
||||||
|
|
||||||
|
def validate_password(self, field):
|
||||||
|
"""Enforce minimum length only when a new password is actually provided."""
|
||||||
|
if field.data and len(field.data) < 6:
|
||||||
|
raise ValidationError('Password must be at least 6 characters.')
|
||||||
|
|
||||||
|
def validate_confirm_password(self, field):
|
||||||
|
"""Require confirmation to match only when a new password is provided."""
|
||||||
|
if self.password.data and field.data != self.password.data:
|
||||||
|
raise ValidationError('Passwords must match.')
|
||||||
|
|
||||||
def validate_username(self, field):
|
def validate_username(self, field):
|
||||||
q = User.query.filter_by(username=field.data).first()
|
q = User.query.filter_by(username=field.data).first()
|
||||||
if self.user:
|
if self.user:
|
||||||
|
|||||||
Reference in New Issue
Block a user