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')

]






Tuesday, July 6, 2021

OIC - Integration properties

Why we need Integration properties and uses:

  • OIC allows us to externalize the properties whose values can be updated without modifying the integration.
  • Developer can define the properties with their default values.
  • Max 10 perperties can be created per integration.
  • These properties values cant be modified inside the integration using any action like assign.
  • This feature is available in both app driven and scheduled orchestration. 
  • You can update the integration properties value from outside of the regular integration design time.
  • To override the integration properties, for scheduled integration - it must be in active state and for app driven - it must be in draft or configured state.
  • Integration properties are user defined properties available for usage by activities like Notification, Log etc. as read only data.

Use case
: we will create 2 intergration properties To and From to use them to notify email in a app driven orchestration.


Steps:

Step1: Create an app driven integrarion and drag and drop a rest trigger connection and set response as below:

{

"status": "messgae sent"

}

Step2: Click on the rest trigger and click on more actions and click on edit integration properties.

Add the parametes From and To and set their default values.

Close

Step3: Drag and drop Notification from action and assign these 2 paramaters From and To and provide some default value to subject and body.

Step4: Save and add a tracking like rest method etc.

Save and it will be now in configure state.

Step5: Go to the integration actions and click on update property values. Click on respective parameter and update with new value if needed. And submit it.

Step6: Activate and test.


OIC - Replace existing connection with the new connection in OIC integration

Why do we need this?

  • This new update allows us to replace any existing connection used in an integration with another connection of same Type and Role. In earlier version, first we need to delete the exisitng connection used in the integration amd then create  a new connecrion for that. So lot of changes needed in the downstream flow or integrations.
  • Sometimes we may need to change the connection name used in an integration.

In simple, it saves a lot time and reduces rework.


Steps to follow:

Step1: Deactivate the integration.

Step2: Click on the actions(hamburger sign) and then click Configure.

Step3: Select the connection which you want to replace and click the replace button to select the new connection of the same type and role. For instance suppose your connection type is rest and role is trigger so you have to choose same rest type and role for the new connection. 

Step4: Done and click save and close.

Step5: Activate your integration ans check from open details if the new connection is showing and then test.

Note: Suppose all your integrations are in a package then whole package components will be showing in the actions --configure step and you can change the connection used for the entire package too.

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...