mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
添加了富文本编辑器上传图片的功能,上传路径在setting_loacl和server里暂时在static/src/upload_image/
This commit is contained in:
parent
70d3fcf323
commit
9b83a2e249
@ -28,6 +28,8 @@ DATABASES = {
|
||||
DEBUG = True
|
||||
|
||||
# 同理 这是 web 服务器的上传路径
|
||||
TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/')
|
||||
TEST_CASE_DIR = os.path.join(BASE_DIR, 'test_case/')
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
IMAGE_UPLOAD_DIR = os.path.join(BASE_DIR, 'static/src/upload_image/')
|
@ -35,3 +35,5 @@ DEBUG = True
|
||||
TEST_CASE_DIR = '/root/test_case/'
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
IMAGE_UPLOAD_DIR = '/var/mnt/source/OnlineJudeg/static/src/upload_image/'
|
||||
|
@ -19,6 +19,7 @@ from problem.views import TestCaseUploadAPIView, ProblemTagAdminAPIView, Problem
|
||||
from submission.views import SubmissionAPIView, SubmissionAdminAPIView, SubmissionShareAPIView
|
||||
from contest_submission.views import ContestSubmissionAPIView, ContestSubmissionAdminAPIView
|
||||
from monitor.views import QueueLengthMonitorAPIView
|
||||
from utils.views import SimditorImageUploadAPIView
|
||||
|
||||
from contest_submission.views import contest_problem_my_submissions_list_page
|
||||
|
||||
@ -112,4 +113,5 @@ urlpatterns = [
|
||||
url(r'^help/$', TemplateView.as_view(template_name="utils/help.html"), name="help_page"),
|
||||
|
||||
url(r'^api/submission/share/$', SubmissionShareAPIView.as_view(), name="submission_share_api"),
|
||||
url(r'^api/admin/up_load_image/$', SimditorImageUploadAPIView.as_view(), name="simditor_upload_image"),
|
||||
]
|
||||
|
@ -143,6 +143,16 @@ Uploader = (function(superClass) {
|
||||
processData: false,
|
||||
contentType: false,
|
||||
type: 'POST',
|
||||
beforeSend: function(){
|
||||
var name = "csrftoken=";
|
||||
var ca = document.cookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == ' ') c = c.substring(1);
|
||||
if (c.indexOf(name) != -1) name = c.substring(name.length, c.length);
|
||||
}
|
||||
arguments[0].setRequestHeader("X-CSRFToken", name);
|
||||
},
|
||||
headers: {
|
||||
'X-File-Name': encodeURIComponent(file.name)
|
||||
},
|
||||
|
@ -8,7 +8,7 @@ define("editor", ["simditor"], function(Simditor){
|
||||
toolbarFloat: false,
|
||||
defaultImage: null,
|
||||
upload: {
|
||||
url: "",
|
||||
url: "/api/admin/up_load_image/",
|
||||
params: null,
|
||||
fileKey: "image",
|
||||
connectionCount: 3,
|
||||
|
27
utils/views.py
Normal file
27
utils/views.py
Normal file
@ -0,0 +1,27 @@
|
||||
# coding=utf-8
|
||||
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from django.conf import settings
|
||||
|
||||
from utils.shortcuts import rand_str
|
||||
|
||||
|
||||
class SimditorImageUploadAPIView(APIView):
|
||||
def post(self, request):
|
||||
if "image" not in request.FILES:
|
||||
return Response(data={
|
||||
"success": False,
|
||||
"msg": "上传失败",
|
||||
"file_path": "/"})
|
||||
img = request.FILES["image"]
|
||||
|
||||
image_name = rand_str() + '.' + str(request.FILES["image"].name.split('.')[-1])
|
||||
image_dir = settings.IMAGE_UPLOAD_DIR + image_name
|
||||
with open(image_dir, "wb") as imageFile:
|
||||
for chunk in img:
|
||||
imageFile.write(chunk)
|
||||
return Response(data={
|
||||
"success": True,
|
||||
"msg": "error message",
|
||||
"file_path": "/static/upload_image/" + image_name})
|
Loading…
Reference in New Issue
Block a user