|
@@ -23,7 +23,7 @@ from apps.account.models import Branch
|
|
|
from apps.WechatApplet.models import WechatApplet
|
|
|
from .base import OrderUpdate
|
|
|
from util.format import Formater
|
|
|
-from util.file_operation import PathAndRename, resizePicture
|
|
|
+from util.file_operation import PathAndRename, resizePicture, UploadFile, DeleteFile
|
|
|
from django.http import JsonResponse as DJR
|
|
|
|
|
|
|
|
@@ -419,33 +419,58 @@ def activity_code(request):
|
|
|
return JSONError(u'获取失败!')
|
|
|
|
|
|
|
|
|
-def ueditor_image(request):
|
|
|
+# def ueditor_image(request):
|
|
|
+# try:
|
|
|
+# upload_path = PathAndRename("upload/")
|
|
|
+#
|
|
|
+# data = {}
|
|
|
+# if request.FILES.getlist('upfile'):
|
|
|
+# document = request.FILES.getlist('upfile')[0]
|
|
|
+# type = document.name.split('.')[-1]
|
|
|
+# name = timezone.now().strftime('%Y%m%d%H%M%S%f')
|
|
|
+# filename = "%s-%s.%s" % (
|
|
|
+# upload_path.path, name, type)
|
|
|
+# filename = filename.lower()
|
|
|
+# full_filename = "%s/%s" % (settings.MEDIA_ROOT, filename)
|
|
|
+# with open(full_filename, 'wb+') as destination:
|
|
|
+# for chunk in document.chunks():
|
|
|
+# destination.write(chunk)
|
|
|
+#
|
|
|
+# resizePicture(full_filename, 500)
|
|
|
+# data = {
|
|
|
+# "state": "SUCCESS",
|
|
|
+# "original": "%s.%s" % (name, type),
|
|
|
+# "title": "%s.%s" % (name, type),
|
|
|
+# "url": 'https://jpm.zzly.vip' + settings.MEDIA_URL + filename
|
|
|
+# }
|
|
|
+# return DJR(data, safe=False)
|
|
|
+# except CustomError as e:
|
|
|
+# return JSONError(e.get_error_msg())
|
|
|
+# except Exception as e:
|
|
|
+# traceback.print_exc()
|
|
|
+# return JSONError(u'图片上传失败!')
|
|
|
+
|
|
|
+
|
|
|
+@token_required
|
|
|
+@login_required()
|
|
|
+def upload_image(request):
|
|
|
+ id = request.GET.get('id')
|
|
|
+ poster = request.FILES.get('image', None)
|
|
|
try:
|
|
|
- upload_path = PathAndRename("upload/")
|
|
|
-
|
|
|
- data = {}
|
|
|
- if request.FILES.getlist('upfile'):
|
|
|
- document = request.FILES.getlist('upfile')[0]
|
|
|
- type = document.name.split('.')[-1]
|
|
|
- name = timezone.now().strftime('%Y%m%d%H%M%S%f')
|
|
|
- filename = "%s-%s.%s" % (
|
|
|
- upload_path.path, name, type)
|
|
|
- filename = filename.lower()
|
|
|
- full_filename = "%s/%s" % (settings.MEDIA_ROOT, filename)
|
|
|
- with open(full_filename, 'wb+') as destination:
|
|
|
- for chunk in document.chunks():
|
|
|
- destination.write(chunk)
|
|
|
-
|
|
|
- resizePicture(full_filename, 500)
|
|
|
- data = {
|
|
|
- "state": "SUCCESS",
|
|
|
- "original": "%s.%s" % (name, type),
|
|
|
- "title": "%s.%s" % (name, type),
|
|
|
- "url": 'https://jpm.zzly.vip' + settings.MEDIA_URL + filename
|
|
|
- }
|
|
|
- return DJR(data, safe=False)
|
|
|
+ if not poster:
|
|
|
+ raise CustomError(u'未找到上传文件!')
|
|
|
+ activity = Activity.getById(id)
|
|
|
+ if activity.delete:
|
|
|
+ raise CustomError(u'该活动已删除')
|
|
|
+ with transaction.atomic():
|
|
|
+ filename = UploadFile(poster, "upload/", width=500)
|
|
|
+ if activity.pic:
|
|
|
+ DeleteFile(activity.pic)
|
|
|
+ activity.pic = filename
|
|
|
+ activity.save()
|
|
|
+ return JSONResponse({})
|
|
|
except CustomError as e:
|
|
|
return JSONError(e.get_error_msg())
|
|
|
except Exception as e:
|
|
|
traceback.print_exc()
|
|
|
- return JSONError(u'图片上传失败!')
|
|
|
+ return JSONError(u'上传失败!')
|