lecture # 32.1 lab 10: server 1

25
Lecture # 32.1 Lab 10: Server 1

Upload: ali-newton

Post on 02-Jan-2016

55 views

Category:

Documents


4 download

DESCRIPTION

Lecture # 32.1 Lab 10: Server 1. Lab 10 Server 1. Add and delete names. Lab 10 Server 1. from a pull-down/select list. Lab 10 Server 1. and store them in a name database:. Server. Name Database. Lab 10 Server 1. DEMO. Here are the Steps A through G:. - PowerPoint PPT Presentation

TRANSCRIPT

Lecture # 32.1

Lab 10: Server 1

Lab 10 Server 1

Add and delete names

Lab 10 Server 1

from a pull-down/select list

Lab 10 Server 1

and store them in a name database:

ServerServer

Name DatabaseName Database

Lab 10 Server 1

DEMO

Here are the Steps A through G:

A. Modify the HTML File: MyFamilyHistory.html

B. Set Up the cgi file

C. Set Up the Database

D. Making life easier (use a “dictionary”)

E. Processing the Form (write python functions)

F. Modify the generateHTMLPage function

G. Test it and Link it Up

Here are the Steps A through G:

A. Modify the HTML File: MyFamilyHistory.html

B. Set Up the cgi file

C. Set Up the Database

D. Making life easier (use a “dictionary”)

E. Processing the Form (write python functions)

F. Modify the generateHTMLPage function

G. Test it and Link it Up

A: Modify the HTML File: MyFamilyHistory.html

1.

1. Set the action attribute in to:

1. Name all necessary widgets. For example

1. Insert the list of people (string %listOfPeople%)

CopyCopy

MyFamilyHistory.htmlMyFamilyHistory.htmlHTML_CSS Server1

YourAccountName

Here are the Steps A through G:

A. Modify the HTML File: MyFamilyHistory.html

B. Set Up the cgi file

C. Set Up the Database

D. Making life easier (use a “dictionary”)

E. Processing the Form (write python functions)

F. Modify the generateHTMLPage function

G. Test it and Link it Up

B: Set up the cgi file

Copy the MFH.cgi file from HTML_CSS folder to the Server1 folder

CopyCopy

MFH.htmlMFH.htmlHTML_CSS Server1

Here are the Steps A through G:

A. Modify the HTML File: MyFamilyHistory.html

B. Set Up the cgi file

C. Set Up the Database

D. Making life easier (use a “dictionary”)

E. Processing the Form (write python functions)

F. Modify the generateHTMLPage function

G. Test it and Link it Up

C: Set up the Database – Step 1

1.

Modify initializeWithNames.py so that it has your names

Run createDB.py and initializeWithNames.py by double

clicking on them, in that order

CopyCopy

createDB.pycreateDB.pyHTML_CSS Server1

initializeWithNames.pyinitializeWithNames.py

C: Set up the Database – Step 2

2. Modify MFH.cgi to include theses four lines at the end:

openDB() {Opens External DB; copies names to Internal DB}

processForm() {Adds/Deletes names to/from Internal DB} print generateHTMLPage(variables) {Generates new html

page to be sent back to Client}

closeDB() {Copies names from Internal DB to External DB}

Add the following python constructs for the Internal DB:

names = [] {[] defines names as an empty list} mothers = {} {{} declare mothers and fathers as fathers = {} empty dictionaries}

C: Set up the Database – Step 3

3. Modify MFH.cgi to read and write from the database:

Insert the line “import squlite3”

Insert the functions openDB() and closeDB():

Here are the Steps A through G:

A. Modify the HTML File: MyFamilyHistory.html

B. Set Up the cgi file

C. Set Up the Database

D. Making life easier (use a “dictionary”)

E. Processing the Form (write python functions)

F. Modify the generateHTMLPage function

G. Test it and Link it Up

D: Making life easier (use a dictionary)

Organize the keywords with the text that is to replace the keywords in the html document using a dictionary.  

To define and initialize this dictionary put the following in the cgi file right after the cgitb.enable() statement:

•variables ={"%newName%":          "",            "%errorMessageArea%": "",            "%listOfPeople%":     "”}

Here are the Steps A through G:

A. Modify the HTML File: MyFamilyHistory.html

B. Set Up the cgi file

C. Set Up the Database

D. Making life easier (use a “dictionary”)

E. Processing the Form (write python functions)

F. Modify the generateHTMLPage function

G. Test it and Link it Up

E: Processing the Form – Step 1

1. Create the processForm() function called by the main routine

and insert it after the openDB() function

E: Processing the Form – Step 2

2. Create the addPerson() function called by the function

processForm() function

E: Processing the Form – Step 3

3. Create the deleteSelectedPerson() function called by the

function processForm() :

E: Processing the Form – Step 4

4. Create the createListOfPeople() function called by the

function processForm() :

Here are the Steps A through G:

A. Modify the HTML File: MyFamilyHistory.html

B. Set Up the cgi file

C. Set Up the Database

D. Making life easier (use a “dictionary”)

E. Processing the Form (write python functions)

F. Modify the generateHTMLPage function

G. Test it and Link it Up

F: Modify the generateHTMLPage function

Modify the generateHTMLPage() function to replace the

keywords %newName%, %errorMessageArea% and

%listOfPeople% in the html document with the

corresponding values in the dictionary in variables.

Do this using the replace method:

Here are the Steps A through G:

A. Modify the HTML File: MyFamilyHistory.html

B. Set Up the cgi file

C. Set Up the Database

D. Making life easier (use a “dictionary”)

E. Processing the Form (write python functions)

F. Modify the generateHTMLPage function

G. Test it and Link it Up

G: Test it and link it up

Make sure the “Add Person” and the “Delete Person”

buttons work.

Also make sure that a list of names now appears in the

selection list.