diff --git a/app/routes/community.py b/app/routes/community.py index 98d024e..db19184 100644 --- a/app/routes/community.py +++ b/app/routes/community.py @@ -273,8 +273,8 @@ def new_post(): original_name=cover_file.filename, size=result['size'], mime_type=result['mime_type'], - post_id=post.id - # Note: is_cover column missing, will be added in future migration + post_id=post.id, + is_cover=True # Mark as cover image ) db.session.add(cover_image) current_app.logger.info(f'Cover image saved: {result["filename"]}') @@ -300,6 +300,32 @@ def new_post(): except Exception as e: current_app.logger.warning(f'Error processing GPX file: {str(e)}') + # Handle section images (multiple images from content sections) + section_images_processed = 0 + for key in request.files.keys(): + if key.startswith('section_image_') and not key.endswith('_section'): + try: + image_file = request.files[key] + if image_file and image_file.filename: + current_app.logger.info(f'Processing section image: {image_file.filename}') + result = save_image(image_file, post.id) + if result['success']: + section_image = PostImage( + filename=result['filename'], + original_name=image_file.filename, + size=result['size'], + mime_type=result['mime_type'], + post_id=post.id, + is_cover=False # Section images are not cover images + ) + db.session.add(section_image) + section_images_processed += 1 + current_app.logger.info(f'Section image saved: {result["filename"]}') + except Exception as e: + current_app.logger.warning(f'Error processing section image {key}: {str(e)}') + + current_app.logger.info(f'Total section images processed: {section_images_processed}') + db.session.commit() current_app.logger.info(f'Post {post.id} committed to database successfully') diff --git a/app/templates/community/new_post.html b/app/templates/community/new_post.html index faa926e..321d73c 100644 --- a/app/templates/community/new_post.html +++ b/app/templates/community/new_post.html @@ -244,6 +244,8 @@