summaryrefslogtreecommitdiffstats
path: root/core/uploads.py
blob: 0160e2e8670d18e44bffd2684de2de69a2424693 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import os
import secrets

from django.utils import timezone


def upload_namer(prefix, instance, filename):
    """
    Names uploaded images, obscuring their original name with a random UUID.
    """
    now = timezone.now()
    _, old_extension = os.path.splitext(filename)
    new_filename = secrets.token_urlsafe(20)
    return f"{prefix}/{now.year}/{now.month}/{now.day}/{new_filename}{old_extension}"