#-*- coding:utf-8 -*-
# jQuery File Tree
# Python/Django connector script
# By Martin Skou
#
import os
import urllib
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
def index(request):
if not request.user.is_superuser:
return HttpResponse(u"不要乱来")
return render(request, 'codemirror/index.html', {"foo": "bar"},
content_type="text/html")
def openfile(request):
if not request.user.is_superuser:
return HttpResponse(u"不要乱来")
path = request.GET['path']
@csrf_exempt
def savefile(request):
if not request.user.is_superuser:
return HttpResponse(u"不要乱来")
path = request.POST['path']
con = request.POST['con']
f = open(path, 'wr')
f.write(con.encode('utf-8'))
f.close()
return HttpResponse('成功')
@csrf_exempt
def createfile(request):
if not request.user.is_superuser:
return HttpResponse(u"不要乱来")
path = request.GET['path']
f = open(path, 'wr')
f.write('')
f.close()
return HttpResponse('成功')
@csrf_exempt
def dirlist(request):
if not request.user.is_superuser:
return HttpResponse(u"不要乱来")
r=['
']
try:
r=['
']
d=urllib.unquote(request.POST.get('dir','c:\\temp'))
for f in os.listdir(d):
ff=os.path.join(d,f)
if os.path.isdir(ff):
r.append('