CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-flask-admin

Simple and extensible admin interface framework for Flask

86

1.30x

Quality

Pending

Does it follow best practices?

Impact

86%

1.30x

Average score across 10 eval scenarios

Overview
Eval results
Files

task.mdevals/scenario-7/

Product Image Management System

Build a simple product catalog admin interface that allows administrators to manage products with image uploads. The system should handle product images with automatic thumbnail generation, file validation, and proper storage management.

Requirements

Product Model

Create a Product model with the following attributes:

  • id: Integer primary key
  • name: String (required, max 100 characters)
  • description: Text (optional)
  • price: Decimal (required, 2 decimal places)
  • image: Image file path (optional, stored in 'uploads/products' directory)

Image Upload Requirements

  1. Image Validation:

    • Only accept image files (jpg, jpeg, png, gif)
    • Store uploaded images in the 'uploads/products' directory
    • Generate secure filenames automatically
  2. Thumbnail Generation:

    • Automatically generate thumbnails for uploaded images
    • Thumbnails should be 150x150 pixels
    • Store thumbnails in 'uploads/products/thumbnails' directory
    • Thumbnail filenames should have '_thumb' suffix before the extension
  3. Image Management:

    • Display image preview in the create/edit forms
    • Allow deletion of existing images via checkbox
    • If a product is deleted, the associated image files should be cleaned up

Admin Interface

Create an admin view that:

  • Lists all products with their name, price, and thumbnail preview
  • Provides forms to create and edit products with image upload capability
  • Allows searching products by name
  • Enables filtering products by price range

Test Cases

  • When uploading a valid image file (jpg, png, gif), it saves successfully with a thumbnail @test
  • When trying to upload a non-image file (txt, pdf), it is rejected with an error @test
  • When deleting a product with an image, both the image and thumbnail files are removed @test
  • Uploaded image filenames are sanitized to prevent security issues @test

Implementation

@generates

API

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView

app = Flask(__name__)
db = SQLAlchemy()

class Product(db.Model):
    """Product model with image support"""
    pass

class ProductAdmin(ModelView):
    """Admin view for Product model with image upload"""
    pass

def create_app():
    """Initialize and configure the Flask application with admin interface"""
    pass

Dependencies { .dependencies }

flask-admin { .dependency }

Provides the admin interface framework with model views and file upload capabilities.

flask-sqlalchemy { .dependency }

Provides SQLAlchemy integration for database models.

pillow { .dependency }

Provides image processing capabilities for thumbnail generation and validation.

Install with Tessl CLI

npx tessl i tessl/pypi-flask-admin

tile.json