Sunday, July 11, 2021

django - webpage to input text and remove punctuation from it.

 urls.py:

from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.index, name="index"),

path('index',views.index,name="index"),
path('removePunctuation',views.removePunc,name="removePunctuation")
]

views.py

def index(request):
# return HttpResponse("Hello")
return render(request,'index.html')


from django.http import HttpResponse
from django.shortcuts import render

def removePunc(request):
text=request.GET.get('text','default')
check=request.GET.get('removepunc','off')
if check == "on":
puncList= '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
newText=''
for char in text:
if char not in puncList:
newText=newText + char

return HttpResponse(newText)
else:
return HttpResponse(text)

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>template is working</title>
</head>
<body>
<h1>Welcome to text analyzer. please enter your text.</h1>
<form action="/removePunctuation" methlod="get">
<textarea name="text" style="margin: 0px; width: 1307px; height: 111px;"></textarea><br/>
<input type="checkbox" name="removepunc">Remove Punctuation<br/>
<button type="submit">Analyze Text</button>
</form>
</body>
</html>

Web pages:


You can create another template and show the removed punctuation text there.

template:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Analyzing Your Text...</title>
</head>
<body>
<h1>Your Analyzed Text - {{ purpose }}</h1>
<p>
    {{ analyzed_text }}

</p>
</body>
</html>


params = {'purpose': 'Removed Punctuations', 'analyzed_text': newText}
        return render(request, 'analyze.html', params)




django - webpage to have personal navigations

 urls.py:

from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.index, name="index"),
path('navigation',views.navigationBar,name="navigationBar")
]

views.py:

from django.http import HttpResponse
from django.shortcuts import render

def navigationBar(request):
return render(request, 'navigationUrls.html')

templates/navigationUrls.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Personal Navigation</title>
</head>
<body>
<h1>Personal Navigations:<br/></h1>
<a href="https://soalicious.blogspot.com/" target="_blank">My Blog Page</a><br/>
<a href="https://www.facebook.com/" target="_blank">Facebook Login Page</a><br/>
<a href="https://twitter.com/?lang=en" target="_blank">Twitter Page</a><br/>
<a href="https://www.instagram.com" target="_blank">Instagram Page</a>
</body>
</html>

WebPage:





Saturday, July 10, 2021

django - homepage - fetch form textarea value from template to views

 template - index.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>template is working</title>
</head>
<body>
<h1>Welcome to text analyzer. please enter your text.</h1>
<form action="/textAnalyze" methlod="get">
<textarea name="text" style="margin: 0px; width: 1307px; height: 111px;"></textarea>
<button type="submit">Analyze Text</button>
</form>
</body>
</html>

urls.py:

from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.index, name="index"),
path('about/',views.about, name="about"),
path('textAnalyze',views.textAnalyze, name="textAnalyze")
]

views.py:

from django.http import HttpResponse
from django.shortcuts import render

def index(request):
params = {"name":"Sri","role":"develoepr"}
# return HttpResponse("Hello")
return render(request,'index.html',params)

def about(request):
return HttpResponse("<h1>about</h1>")
def textAnalyze(request):
ttext = request.GET.get('text','default')
print(ttext)
return HttpResponse(ttext)

web page:

suppose you entered "abcd" in the textarea, then it will go to the views.py and print the inputted data.



django - how to use templates

 Step1: Open settings.py and write templates in the DIR of template section as below:


Step2: Create a templates folder and create a index.html file in it as below:

Contents of index.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>template is working</title>
</head>
<body>
<h1>from index page, Hello</h1>
</body>
</html>

Step3: in the views.py, import the render module from shortcuts and call the template as below:

from django.http import HttpResponse
from django.shortcuts import render

def index(request):
# return HttpResponse("Hello")
return render(request,'index.html')

def about(request):
return HttpResponse("<h1>about</h1>")

The server will run automatically:

You can also create a dictionary and send the same to the template while rendering from views.py and use them in the tempate.

views.py:

from django.http import HttpResponse
from django.shortcuts import render

def index(request):
params = {"name":"Sri","role":"develoepr"}
# return HttpResponse("Hello")
return render(request,'index.html',params)


template - index.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>template is working</title>
</head>
<body>
<h1>from index page, Hello</h1>
{{name}}
</body>
</html>


web page:






Thursday, July 8, 2021

OIC - Configre rest trigger to get CSV file

Here I will show you how to configure a rest trigger to binary mode to get csv file. The media type will be text/plain.

You can also get binary file as 

  • Octet-stream
  • Pdf
  • Msword
  • Zip
  • Jpeg,png,bmp,gif
  • Other media type like text/plain

Implementation Steps:

Step1: Create an app driven integration and choose verb as POST, Configure a request payload for this endpoint and /csvData as relative resource URI.

Step2: In the request section, select the request payload format as Binary and media type as Other media Type and media type as text/plain.

Step3: Drag and drop a stage action and read the file 

Choose stage file operarion as Read Entire File.

Configure the file reference as Yes

Specify the Filr reference: /nssrcmpr:execute/nsmpr2:streamReference

Step4: Provide a sample csv file, record and recordset names.

Test.csv

Name,Id

"Sri", 1

Step5: Take a logger action and select Log as always, logger message as readfile/readresponse/empRecordSet.

Step6: Add the tracking as streamReference and save and activate.

Step7: Once the integrarion activated, do the following:

  • click on run and Test, 
  • go to body and select File button and select your file and test. 
  • Go to the monitoring section and open activity stream, you can see the logger contains the csv file data.

Test from Postman:

You can also test this rest from postman following the below steps:

Step1: From the integration take the endpoint uri and open in postman with post verb,

Step2:  Go to the authorization tab and select basic auth and provide OIC instance access credentials.

Step3: Go to the header tab and add Content-Type as text/plain.

Step4: Go to the Body tab and select binary and choose the test.csv file and hit the send button.


OIC - dynamic email send with html table content.

Here, i will explain the steps how we can send the dynamic email with html table content.

Steps:

Step1: create an app driven integration and drag and drop a rest trigger connection and configure the request json as below:

{

"EmployeeDetails":{

"Employee": [{

"Name": "asd",

"Id": "as123"

}]

}

}

Step2: take an assign and create a variable like emailContent with

"<table><tr><th>Name</th><th>Id</th></tr>"

Step3: take a for each action and map with fkr each employee

Repeating element: /nssrccmpr:execute/nsmpr3:request-wrapper/nsmpr3:EmployeeDetails/nsmpr3:Employee

Step4: in the for each action, in the emailContent variable add the follow:

concat($emailContent, "<tr><td>", Name_xpath,"</td><td>",Id_xpath,"</td></tr>")

Step5: outside of the loop, take assign and add the close table tag in the emailContent variable.

Concat($emailContent, "</table>">

Step6: take notification action and provide details for From, To and Subject. And then create a paramter as body and assign the variable $emailContent. And write the beloe code in the Body section.

<html>

<head>

You can place any style script here

</head>

<body>

<p>Below are the emp details:</p>

{body}

</body>

</html>

Step7: add the tracking, save and activate and test it.



Django - create your first project and runservers and urls and views

Create a project:
Open your pycharm and create  a project with proper name like djangoCodeSource using system interpreter.

Start the project:
Go to pycharm terminal and cd to the project path and run the following cmd.

django-admin
django-admin startproject myFirstSite

now the folder structure will look like as below:



Runserver:
Python manage.py runserver

C:\Users\Srinanda\Desktop\python\djangoCodeSource\myFirstSite>python manage.py runserver
Django version 3.2.5, using settings 'myFirstSite.settings'
Starting development server at http://127.0.0.1:8000/




Create views:
On your project create a python file views.py and create the code:

from django.http import HttpResponse
def index(request):
    Return HttpResponse("hello")




urls.py:

from . import views

urlpatterns=[
path('admins/', admin.site.urls)
path('',views.index, name='index')
path('about/',views.about, name='about')

]






Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...