Beispiel #1
0
def add_carousel_view(request):
    """
    添加轮播图片
    """
    form = AddCarouselForm(request.POST, request.FILES)
    if not form.is_valid():
        messages.error(request, "</br>".join(form_error(form)))
        return HttpResponseRedirect(reverse('carousel_list'))
    try:
        filestream = request.FILES.get('path')
        key, img_path = upload_data(filestream, 'blog')
        img_type = int(form.cleaned_data.get('img_type'))
        CarouselImg.objects.create(
            name=form.cleaned_data.get('name'),
            description=form.cleaned_data.get('description'),
            path=img_path,
            link=form.cleaned_data.get('link'),
            weights=form.cleaned_data.get('weights'),
            img_type=img_type,
        )
        messages.success(request, '添加成功')
        if img_type == CarouselImgType.BANNER:
            cache.delete_pattern('tmp_carouse_imgs')  # 清除缓存
        elif img_type == CarouselImgType.ADS:
            cache.delete_pattern('tmp_ads_imgs')  # 清除缓存
        return HttpResponseRedirect(reverse('carousel_list'))
    except Exception as e:
        messages.error(request, '添加失败: %s' % e)
        return HttpResponseRedirect(reverse('carousel_list'))
Beispiel #2
0
def upload_file(request):
    """
    editor.md上传图片接口
    """
    filestream = request.FILES.get('editormd-image-file')
    if not filestream:
        return render_json({"success": 0, "message": u"请选择文件", "url": ""})

    key, img_path = upload_data(filestream, 'blog')
    return render_json({"success": 1, "message": u"上传成功", "url": img_path})
Beispiel #3
0
def upload_file(request):
    """
    editor.md上传图片接口
    """
    filestream = request.FILES.get('editormd-image-file')
    if not filestream:
        return render_json({"success": 0, "message": u"请选择文件", "url": ""})

    key, img_path = upload_data(filestream, 'blog')
    return render_json({"success": 1, "message": u"上传成功", "url": img_path})
Beispiel #4
0
def upload_rich_file(request):
    """
    wangEditor上传图片接口, 支持批量上传
    """
    files = request.FILES
    if not files:
        return render_json({"errno": 1, "data": []})

    img_path_list = []
    for item in files:
        key, img_path = upload_data(files.get(item), 'blog')
        img_path_list.append(img_path)

    return render_json({"errno": 0, "data": img_path_list})
Beispiel #5
0
def upload_rich_file(request):
    """
    wangEditor上传图片接口, 支持批量上传
    """
    files = request.FILES
    if not files:
        return render_json({"errno": 1, "data": []})

    img_path_list = []
    for item in files:
        key, img_path = upload_data(files.get(item), 'blog')
        img_path_list.append(img_path)

    return render_json({"errno": 0, "data": img_path_list})