Skip to content

This is a better backend #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 52 additions & 61 deletions textutils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,65 @@ def index(request):
return render(request, 'index.html')


def analyze(request):
#Get the text
djtext = request.POST.get('text', 'default')
ef analyze(request):
# Get the text
djtext = request.POST.get('text', 'Nothing Enterrred')
djtext_list = list(djtext)
del djtext

# Check checkbox values
removepunc = request.POST.get('removepunc', 'off')
fullcaps = request.POST.get('fullcaps', 'off')
newlineremover = request.POST.get('newlineremover', 'off')
extraspaceremover = request.POST.get('extraspaceremover', 'off')
numberremover = request.POST.get('numberremover','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}
djtext = analyzed

if(fullcaps=="on"):
analyzed = ""
for char in djtext:
analyzed = analyzed + char.upper()

params = {'purpose': 'Changed to Uppercase', 'analyzed_text': analyzed}
djtext = analyzed

if(extraspaceremover=="on"):
analyzed = ""
for index, char in enumerate(djtext):
# It is for if a extraspace is in the last of the string
if char == djtext[-1]:
if not(djtext[index] == " "):
analyzed = analyzed + char

elif not(djtext[index] == " " and djtext[index+1]==" "):
analyzed = analyzed + char

params = {'purpose': 'Removed NewLines', 'analyzed_text': analyzed}
djtext = analyzed

if (newlineremover == "on"):
analyzed = ""
for char in djtext:
if char != "\n" and char!="\r":
analyzed = analyzed + char

params = {'purpose': 'Removed NewLines', 'analyzed_text': analyzed}

if (numberremover == "on"):
analyzed = ""
numbers = '0123456789'

for char in djtext:
if char not in numbers:
analyzed = analyzed + char

params = {'purpose': 'Removed NewLines', 'analyzed_text': analyzed}
djtext = analyzed


if(removepunc != "on" and newlineremover!="on" and extraspaceremover!="on" and fullcaps!="on" and numberremover != "on"):
return HttpResponse("please select any operation and try again")

# creating needs
params = {'purpose': '', 'analyzed_text': ""}
punctuations = list('''!()-[]{};:'"\,<>./?@#$%^&*_~''')
removal_list = []

# main for loop
for index in range(len(djtext_list)):
char = djtext_list[index]
removal = False

if removepunc == "on":
if djtext_list[index] in punctuations:
removal = True
if index == 0:
params['purpose'] = params['purpose'] + \
", Removed Punctuations"

if fullcaps == "on":

djtext_list[index] = djtext_list[index].upper()
if index == 0:
params['purpose'] = params['purpose'] + ", Capitalised Text"

if(extraspaceremover == "on"):
if index + 2 < len(djtext_list):
if (djtext_list[index] == " " and djtext_list[index+1] == " "):
removal = True
if index == 0:
params['purpose'] = params['purpose'] + \
", Unneeded spaces removed"

if (newlineremover == "on"):

if djtext_list[index] == "\n" and djtext_list[index + 1] == "\n":
removal = True
if index == 0:
params['purpose'] = params['purpose'] + ", New lines removed"

if removal:
removal_list.append(char)

djtext_list = [e for e in djtext_list if e not in removal_list]

params['analyzed_text'] = "".join(djtext_list)
params['purpose'] = params['purpose'].lstrip(",")

return render(request, 'analyze.html', params)

def about(request):
return render(request, 'about.html')
return render(request, 'about.html')