CMPT165_27_OnlineCatalog2

CMPT165_27_OnlineCatalog2 - Online catalog 2.0 Bigger and...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
–1 Online catalog 2.0 Bigger and more complicated © Colin Stewart, 2009 The catalog, so far The catalog, so far • our movie catalog has 6 scripts, which generate 7 different pages to the user Details page search.py Search page searchForm.py Not Found page search.py Confirm page add.py Success page addSuccess.py Home page home.py Add page addForm.py
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
–2 The catalog, so far The catalog, so far home.py Home page addForm.py Add page add.py addSuccess.py searchForm.py Search page search.py Details page Confirm page cancel Success page Not Found page couldn't find movie • note that search.py produces a different page in different situations Extra features Extra features • in this lecture, we'll add some extra features to the movie catalog • we'll make the following modifications: h movies can't be added if they have the same name and year as another movie already in the catalog h the user can delete movies in the catalog h the user can edit movies in the catalog h a password is required before the user can add/delete/edit a movie
Background image of page 2
–3 Digital catalog features Digital catalog features • a side point: all digital catalogs (a.k.a databases ) will be able to do the following: h add data h edit data h delete data h search for data • almost all features in a database are associated with one of these four things No repeated movies No repeated movies • first, we'll revise our code so that newly added movies cannot have the same name as an existing movie in the catalog • to show how this will work, let's add the movie "Moon" h this movie is not yet in the catalog, so it will be added successfully:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
–4 No repeated movies No repeated movies • now, if we try to add a movie called "Moon" again, it will not be added b Add Page generated by addForm.py Fail Page generated by add.py No repeated movies No repeated movies home.py Home page addForm.py Add page add.py addSuccess.py searchForm.py Search page search.py Details page Fail page already in catalog Confirm page cancel Success page Not Found page couldn't find movie
Background image of page 4
–5 No repeated movies No repeated movies • the script add.py now produces different pages under different circumstances • here it is, revised (changes in bold): import cgi form = cgi.FieldStorage() print 'Content-type: text/html' print print '<html>\n<head>\n</head>' print '<body>' title = form[ "title" ].value year = form[ "year" ].value genre = form[ "genre" ].value #continued on next slide No repeated movies No repeated movies #continued from previous slide f = File( "movieCatalog.data" ) movieInCatalog = False if f.exists() == True : f.startRead() movieList = f.read() f.close() for movie in movieList: #search for the title if movie[0].lower() == title.lower(): movieInCatalog = True if movieInCatalog == True : print '<h1>Add failed</h1>' print '<p>There is already a movie in the ' + \ 'catalog called "' + title + '".</p>' #continued on next slide
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
–6 No repeated movies No repeated movies #continued from previous slide else
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

CMPT165_27_OnlineCatalog2 - Online catalog 2.0 Bigger and...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online