-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
73 lines (56 loc) · 2.26 KB
/
views.py
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
69
70
71
72
73
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
return render(request, 'index.html')
# return HttpResponse("Home")
def analyze(request):
#Get the text
djtext = request.GET.get('text', 'default')
print(djtext)
# Check checkbox values
removepunc = request.GET.get('removepunc', 'off')
fullcaps = request.GET.get('fullcaps', 'off')
newlineremover = request.GET.get('newlineremover', 'off')
extraspaceremover = request.GET.get('extraspaceremover', 'off')
#Check which checkbox is on
if removepunc == "on":
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
analyzed = ""
for char in djtext:
if char not in punctuations:
analyzed = analyzed + char
params = {'purpose':'Removed Punctuations', 'analyzed_text': analyzed}
return render(request, 'analyze.html', params)
elif(fullcaps=="on"):
analyzed = ""
for char in djtext:
analyzed = analyzed + char.upper()
params = {'purpose': 'Changed to Uppercase', 'analyzed_text': analyzed}
# Analyze the text
return render(request, 'analyze.html', params)
elif(extraspaceremover=="on"):
analyzed = ""
for index, char in enumerate(djtext):
if not(djtext[index] == " " and djtext[index+1]==" "):
analyzed = analyzed + char
params = {'purpose': 'Removed NewLines', 'analyzed_text': analyzed}
# Analyze the text
return render(request, 'analyze.html', params)
elif (newlineremover == "on"):
analyzed = ""
for char in djtext:
if char != "\n":
analyzed = analyzed + char
params = {'purpose': 'Removed NewLines', 'analyzed_text': analyzed}
# Analyze the text
return render(request, 'analyze.html', params)
else:
return HttpResponse("Error")
#def capfirst(request):
# return HttpResponse("capitalize first")
#def newlineremove(request):
# return HttpResponse("newline remove first")
#def spaceremove(request):
# return HttpResponse("space remover back")
#def charcount(request):
# return HttpResponse("charcount ")