-
Notifications
You must be signed in to change notification settings - Fork 0
/
Views.txt
68 lines (45 loc) · 1.58 KB
/
Views.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from django.shortcuts import render
from django.http import HttpResponse
import os
import csv # µ¼ÈëcsvÕâ¸ö¿â
from itertools import islice
from .models import Exceptions
# Create your views here.
def upfile(request):
return render(request,'myApp/upfile.html')
def savefile(request):
if request.method == "POST":
myFile = request.FILES.get("myfile", None)
if not myFile:
return HttpResponse("no files for upload!")
destination = open(os.path.join("D:\\01\\project\\static", myFile.name), 'wb+')
for chunk in myFile.chunks():
destination.write(chunk)
destination.close()
with open("D:\\01\\project\\static\\"+myFile.name, "r", encoding="utf-8") as f:
reader = csv.reader(f)
reader = list(reader)
for line in islice(reader, 1, None):
exc = Exceptions.createException(line[0], line[1], line[2],0)
exc.save()
return HttpResponse("yes")
def ajaxsearch(request):
return render(request,'myApp/search.html')
from django.http import JsonResponse
def searchexc(request):
a=str(request.GET.get('a'))
exc=Exceptions.objects.get(name=a)
list = []
# for qaz in exc:
list.append([exc.description, exc.example])
exc.hit = exc.hit + 1
exc.save()
return JsonResponse({"data": list})
def chart(request):
return render(request, 'myApp/chart.html',)
def showchart(request):
excs=Exceptions.objects.all()
list=[]
for exc in excs:
list.append([exc.name,exc.hit])
return JsonResponse({"data":list})