예제 #1
0
def upload_icon(request, user_profile):
    # type: (HttpRequest, UserProfile) -> HttpResponse

    if len(request.FILES) != 1:
        return json_error(_("You must upload exactly one icon."))

    icon_file = list(request.FILES.values())[0]
    upload_icon_image(icon_file, user_profile)
    do_change_icon_source(user_profile.realm, user_profile.realm.ICON_UPLOADED)
    icon_url = realm_icon_url(user_profile.realm)

    json_result = dict(icon_url=icon_url)
    return json_success(json_result)
예제 #2
0
def upload_icon(request: HttpRequest,
                user_profile: UserProfile) -> HttpResponse:

    if len(request.FILES) != 1:
        return json_error(_("You must upload exactly one icon."))

    icon_file = list(request.FILES.values())[0]
    if ((settings.MAX_ICON_FILE_SIZE * 1024 * 1024) < icon_file.size):
        return json_error(
            _("Uploaded file is larger than the allowed limit of {} MiB").
            format(settings.MAX_ICON_FILE_SIZE, ))
    upload_icon_image(icon_file, user_profile)
    do_change_icon_source(user_profile.realm, user_profile.realm.ICON_UPLOADED)
    icon_url = realm_icon_url(user_profile.realm)

    json_result = dict(icon_url=icon_url, )
    return json_success(json_result)
예제 #3
0
def upload_icon(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:

    if len(request.FILES) != 1:
        return json_error(_("You must upload exactly one icon."))

    icon_file = list(request.FILES.values())[0]
    if ((settings.MAX_ICON_FILE_SIZE * 1024 * 1024) < icon_file.size):
        return json_error(_("Uploaded file is larger than the allowed limit of %s MB") % (
            settings.MAX_ICON_FILE_SIZE))
    upload_icon_image(icon_file, user_profile)
    do_change_icon_source(user_profile.realm, user_profile.realm.ICON_UPLOADED)
    icon_url = realm_icon_url(user_profile.realm)

    json_result = dict(
        icon_url=icon_url
    )
    return json_success(json_result)
예제 #4
0
def upload_icon(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:

    if len(request.FILES) != 1:
        raise JsonableError(_("You must upload exactly one icon."))

    icon_file = list(request.FILES.values())[0]
    assert isinstance(icon_file, UploadedFile)
    assert icon_file.size is not None
    if (settings.MAX_ICON_FILE_SIZE_MIB * 1024 * 1024) < icon_file.size:
        raise JsonableError(
            _("Uploaded file is larger than the allowed limit of {} MiB").format(
                settings.MAX_ICON_FILE_SIZE_MIB,
            )
        )
    upload_icon_image(icon_file, user_profile)
    do_change_icon_source(
        user_profile.realm, user_profile.realm.ICON_UPLOADED, acting_user=user_profile
    )
    icon_url = realm_icon_url(user_profile.realm)

    json_result = dict(
        icon_url=icon_url,
    )
    return json_success(request, data=json_result)