# -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2021, Shuup Commerce Inc. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import unicode_literals
from django import forms
from django.conf import settings
from django.core.exceptions import ValidationError
from django.http.response import HttpResponseForbidden, JsonResponse
from django.utils.translation import ugettext_lazy as _
from shuup.core.shop_provider import get_shop
from shuup.utils.filer import ensure_media_file, filer_file_to_json_dict, filer_image_from_upload, get_or_create_folder
[docs]def file_size_validator(value):
size = getattr(value, "size", None)
if size and settings.SHUUP_FRONT_MAX_UPLOAD_SIZE and settings.SHUUP_FRONT_MAX_UPLOAD_SIZE < size:
raise ValidationError(
_("Maximum file size reached (%(size)s MB).")
% {"size": settings.SHUUP_FRONT_MAX_UPLOAD_SIZE / 1000 / 1000},
code="file_max_size_reached",
)
return value