-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
61 lines (50 loc) · 1.84 KB
/
views.py
File metadata and controls
61 lines (50 loc) · 1.84 KB
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
#sameer mahajan
#text util backend
from django.http import HttpResponse
from django.shortcuts import render
# to load the home page
def index(request):
return render(request, 'index.html')
# to perform textutils
def analyze(request):
#get text using post
djtext = request.POST.get('text', 'default')
# util data
removepunc=request.POST.get('removepunc','off')
uppercase=request.POST.get('uppercase','off')
newlineremove=request.POST.get('newlineremove','off')
extraspaceremove=request.POST.get('extraspaceremove','off')
analyzed=djtext
if removepunc=='on' or uppercase=='on' or newlineremove=='on' or extraspaceremove=='on':
# to remove punctuations
if removepunc == 'on':
punctutations='''!()-[]{};:'"\,<>./?@#$%^&*_~'''
temp=""
for char in analyzed:
if char not in punctutations:
temp=temp+char
analyzed=temp
# to turn text to upper case
if uppercase=='on':
temp=""
for i in analyzed:
temp=temp+i.upper()
analyzed=temp
# to remove new lines
if newlineremove=='on':
temp=""
for i in analyzed:
if i!='\n' and i!='\r':
temp=temp+i
analyzed=temp
# to remove extraspaces
if extraspaceremove=='on':
temp=""
for index,ch in enumerate(analyzed):
if not (djtext[index]==' ' and djtext[index+1]==' '):
temp=temp+ch
analyzed=temp
params={'purpose':'Performed operations','analyzed_text':analyzed}
return render(request,'analyze.html',params)
else:
return HttpResponse('select a option')