From a2b827d02fbff97038e2c998b602fd8bad8cf46f Mon Sep 17 00:00:00 2001 From: Sudo-JHare Date: Sun, 11 May 2025 20:01:02 +1000 Subject: [PATCH] Add files via upload --- Dockerfile | 2 +- app/forms.py | 10 +++++++--- app/routes.py | 3 ++- app/templates/gallery.html | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index a69c404..fb09818 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,4 @@ COPY instance/ instance/ COPY config.py . COPY .env . EXPOSE 5009 -CMD ["flask", "run", "--host=0.0.0.0"] \ No newline at end of file +CMD ["flask", "run", "--host=0.0.0.0" "--port=5009"] \ No newline at end of file diff --git a/app/forms.py b/app/forms.py index 42b4e10..b2a4da8 100644 --- a/app/forms.py +++ b/app/forms.py @@ -18,13 +18,13 @@ def validate_url_or_path(form, field): raise ValidationError('Invalid URL or file path.') def validate_username(form, field): - if field.data != form._obj.username: # Check if username changed + if form.user and field.data != form.user.username: # Check if username changed existing_user = User.query.filter_by(username=field.data).first() if existing_user: raise ValidationError('Username already taken.') def validate_email(form, field): - if field.data != form._obj.email: # Check if email changed + if form.user and field.data != form.user.email: # Check if email changed existing_user = User.query.filter_by(email=field.data).first() if existing_user: raise ValidationError('Email already registered.') @@ -89,4 +89,8 @@ class UserEditForm(FlaskForm): force_password_change = BooleanField('Force Password Change') reset_password = PasswordField('Reset Password', validators=[Optional(), Length(min=6)]) confirm_reset_password = PasswordField('Confirm Reset Password', validators=[Optional(), EqualTo('reset_password')]) - submit = SubmitField('Save Changes') \ No newline at end of file + submit = SubmitField('Save Changes') + + def __init__(self, user=None, *args, **kwargs): + super(UserEditForm, self).__init__(*args, **kwargs) + self.user = user # Store the user object for validation \ No newline at end of file diff --git a/app/routes.py b/app/routes.py index 27957ed..e975e4a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -157,6 +157,7 @@ def register(): file = form.app_image_uploads.data if file and allowed_file(file.filename): filename = secure_filename(f"{uuid.uuid4()}_{file.filename}") + (my apologies, I did not mean to interrupt you, please go ahead and continue. save_path = os.path.join(UPLOAD_FOLDER, filename) logger.debug(f"Attempting to save app image to {save_path}") try: @@ -373,7 +374,7 @@ def edit_user(user_id): flash('Admin access required.', 'danger') return redirect(url_for('gallery.landing')) user = User.query.get_or_404(user_id) - form = UserEditForm(obj=user) + form = UserEditForm(user=user, obj=user) if form.validate_on_submit(): user.username = form.username.data user.email = form.email.data diff --git a/app/templates/gallery.html b/app/templates/gallery.html index b5b0c77..0acea97 100644 --- a/app/templates/gallery.html +++ b/app/templates/gallery.html @@ -54,7 +54,7 @@