from django import forms
from django.core.files.storage import FileSystemStorage
from django.http import HttpRequest


class UploadForm(forms.Form):
    """Example of file upload form."""

    image = forms.ImageField(max_length=128, required=True, label="image")

    @staticmethod
    def save_uploaded_file(request: HttpRequest) -> str:
        """
        Custom method to process the upload of the image.

        Args:
            request: HTTP request.

        Returns:
            URL of the new uploaded image.

        """
        storage = FileSystemStorage()
        image = request.FILES["image"]
        name = storage.save(None, image)
        return storage.url(name)
