Web-Applications: TurboGears

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
Introduction to Model-View-Controller (MVC) Web Programming with TurboGears Leif Oppermann,
1 Chapter 12 Working With Access 2000 on the Internet.
Macromedia Dreamweaver 4 Advanced Level Course. Add Rollovers Rollovers or mouseovers are possibly the most popular effects used in designing Web pages.
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Web-Applications: TurboGears II BCHB Lecture 26 12/03/2014BCHB Edwards.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
ITIS 1210 Introduction to Web-Based Information Systems Chapter 24 How Websites Work with Databases How Websites Work with Databases.
Relational Databases: Object Relational Mappers – SQLObject II BCHB Lecture 23 11/20/2013BCHB Edwards.
JavaScript & jQuery the missing manual Chapter 11
Server-side Scripting Powering the webs favourite services.
© Cheltenham Computer Training 2001 Macromedia Dreamweaver 4 - Slide No 1 Macromedia Dreamweaver 4 Advanced Level Course.
Relational Databases: Basic Concepts BCHB Lecture 21 11/12/2014BCHB Edwards.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
HTML Hyper Text Markup Language A simple introduction.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
Chapter 6 Server-side Programming: Java Servlets
Web Design Part I. Click Menu Site to create a new site root.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
Relational Databases: Basic Concepts BCHB Lecture 21 By Edwards & Li Slides:
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Web-Applications: TurboGears II BCHB Lecture 26 12/7/2015BCHB Edwards.
Web-Applications: TurboGears BCHB Lecture 25 12/02/2015BCHB Edwards.
ASP. ASP is a powerful tool for making dynamic and interactive Web pages An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are.
Tomcat Setup BCIS 3680 Enterprise Programming. One-Click Tomcat Setup 2  This semester we’ll try to set up Tomcat with a PowerShell script.  Preparation.
National College of Science & Information Technology.
Finally getting to html and CSS… Tim Berners-Lee, the writer of the software program that makes him the inventor of the WWW, defines the Internet as a.
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
Week 1: Introduction to HTML and Web Design
Advanced HTML Tags:.
MicrosoftTM SharePoint Content Management SystemTutorial
Intro to WordPress (Using XAMPP)
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Relational Databases: Basic Concepts
Jim Fawcett CSE686 – Internet Programming Spring 2012
Web-Applications: TurboGears II
Play Framework: Introduction
Basic XHTML Tables XHTML tables—a frequently used feature that organizes data into rows and columns. Tables are defined with the table element. Table.
Introduction to Programming the WWW I
PHP Training at GoLogica in Bangalore
PHP / MySQL Introduction
BASIC PHP and MYSQL Edward S. Flores.
Intro to PHP & Variables
Testing REST IPA using POSTMAN
MVC Framework, in general.
Essentials of Web Pages
Chapter 27 WWW and HTTP.
Title: Tech Training Certificate: Ace of Initiative Program
SiteBuilder 2 Introduction.
Relational Databases: Object Relational Mappers – SQLObject II
Secure Web Programming
Web-Applications: TurboGears II
Relational Databases: Basic Concepts
Relational Databases: Basic Concepts
Web-Applications: TurboGears II
Relational Databases: Object Relational Mappers – SQLObject II
Web-Applications & AJAX
Relational Databases: Object Relational Mappers – SQLObject II
Web Programming and Design
Web Application Development Using PHP
Presentation transcript:

Web-Applications: TurboGears BCHB524 Lecture 26 BCHB524 - Edwards

Web-Applications Use the web-browser as the user-interface All application specific functionality comes directly from the web-server No installation impediments for the user Fast way to provide your tools to others with little operating system or user-interface barrier Natural way to supply views into complex datasets that cannot feasibly be installed elsewhere. BCHB524 - Edwards

Web-Servers Respond to requests: with static: and dynamic: content. http://google.com http://edwardslab.bmcb.georgetown.edu/ with static: files, images, etc... and dynamic: your facebook page, google search results content. BCHB524 - Edwards

Web-servers A URL is made up of many parts. port # (80 if omitted) http://hoyataxa.georgetown.edu:8080/index.html protocol (http,https) computer name resource BCHB524 - Edwards

resource/request parameters Web-servers A URL is made up of many parts. A dynamic resource may return different results depending on its parameters Additional request parameters may not be visible in the URL Cookies, POST requests port # (80 if omitted) resource/request parameters http://hoyataxa.georgetown.edu:8080/taxa?taxid=9606&format=XML protocol (http,https) computer name resource BCHB524 - Edwards

Web-server Web-servers return data in HTML format for display by the web-browser. Any program can request URL resources and store (and display) the response. Any program can handle the URL request and return data in whatever format they like. TurboGears provides a pythonic web-framework for building dynamic data-driven web-application servers. BCHB524 - Edwards

TurboGears One of many web-stacks which simplify development of web-apps Model-View-Controller (MVC) paradigm Model stores the data/information required View decides how to format/display the results Controller takes requests and determines the data to output BCHB524 - Edwards

TurboGears http://www.turbogears.org Your class virtual image has version 1.1.3 Current TurboGears version is 1.5/2.3 TurboGears admin script is: tg-admin TurboGears has been installed as an external package in the class virtual image. BCHB524 - Edwards

Hoya Taxa TurboGears web-application for navigating the NCBI taxonomy of organisms Simple view and navigation of the data stored in a relational database Read-only (no modification of the data) No users (no login or accounts) No fancy javascript (AJAX or otherwise) BCHB524 - Edwards

Application creation TurboGears provides an administration script to construct an initial web-application shell In the terminal: tg-admin and then: tg-admin quickstart -o Answer the questions (what you type is in red): Enter project name: HoyaTaxa Enter package name [hoyataxa]: Do you ...? [no] BCHB524 - Edwards

Start web-app and check Check that the web-application shell is working... In the terminal: [student@localhost ~]$ cd HoyaTaxa [student@localhost ~]$ python start-hoyataxa.py Start a web-browser and access the url: http://localhost:8080/ Lots of stuff is printed to the terminal BCHB524 - Edwards

Start web-app and check BCHB524 - Edwards

Start web-app and check BCHB524 - Edwards

Tour the primary files Lets take a tour of the HoyaTaxa folder: Controller: hoyataxa/controllers.py (Data) Model: hoyataxa/model.py View / Template: hoyataxa/templates/welcome.html hoyataxa/templates/master.html BCHB524 - Edwards

Trace the execution path Spend some time understanding how these files interact. Things to notice: Request is translated to function call in controller Dynamic content (date and time) is passed from the controller function to the template Lots of crazy stuff in the welcome.html and master.html templates, but we can remove a lot. Edit controllers.py, welcome.html, and master.html to make an "empty" application. BCHB524 - Edwards

Edit welcome.html In welcome.html: Delete everything between the <body></body> HTML tags. Delete everything in the <?python ?> block Reload the web-site use the reload button in web-browser Check the result... Still have some stuff from master.html but otherwise empty. master.html is intended to provide common design elements (titles, menus) on every page BCHB524 - Edwards

Edit welcome.html Now looks like this BCHB524 - Edwards

Edit controllers.py In the index method in controllers.py: Delete the flash function call Reload the web-site and check the effect... Remove the time and date variable Notice that the server program "restarts" every time you change controllers.py. BCHB524 - Edwards

Edit controllers.py Root class declaration should look like this: BCHB524 - Edwards

Edit master.html In master.html (reload after each change) Remove <?python ?> block. Remove everything in the <body> </body> block, except for the id="content" block. Find the footer and remove the footer image. Find the sidebar and menus and remove them. Add a new header "div" as first element inside id="content". <div align="center"> <font size="+6">Hoya Taxa</font> </div> Change the footer as you like BCHB524 - Edwards

Edit master.html Relevant section should look like this: BCHB524 - Edwards

Empty web-app Rather than making the changes one step at a time… Download TGEmpty.zip from course data directory to your home directory. [student@localhost ~]$ cd ~/HoyaTaxa/hoyataxa [student@localhost ~]$ unzip –o ~/TGEmpty.zip [student@localhost ~]$ cd .. [student@localhost ~]$ python start-hoyataxa.py BCHB524 - Edwards

Empty web-app Empty web-application shell looks like: BCHB524 - Edwards

Dynamic title In controllers.py, let's send a dynamic title to the welcome.html template. BCHB524 - Edwards

Dynamic title In welcome.html, change "Welcome to TurboGears" to ${title}. BCHB524 - Edwards

Dynamic Title BCHB524 - Edwards

Set up the model... Edit the model.py file add the necessary imports and SQLObject classes # Extra imports from sqlobject from sqlobject import ForeignKey, MultipleJoin class Taxonomy(SQLObject):     taxid = IntCol(alternateID=True)     scientific_name = StringCol()     rank = StringCol()     parent = ForeignKey("Taxonomy")     names = MultipleJoin("Name")     children = MultipleJoin("Taxonomy",joinColumn='parent_id') class Name(SQLObject):     taxonomy = ForeignKey("Taxonomy")     name = StringCol()     name_class = StringCol() # Extra imports from sqlobject from sqlobject import ForeignKey, MultipleJoin class Taxonomy(SQLObject): taxid = IntCol(alternateID=True) scientific_name = StringCol() rank = StringCol() parent = ForeignKey("Taxonomy") names = MultipleJoin("Name") children = MultipleJoin("Taxonomy",joinColumn='parent_id') class Name(SQLObject): taxonomy = ForeignKey("Taxonomy") name = StringCol() name_class = StringCol() BCHB524 - Edwards

Set up the model... Create the model: In the terminal: [student@localhost ~]$ tg-admin sql create Check that the sqlite database has been created in devdata.sqlite. Use sqlitestudio to check it No data in it! Download devdata.sqlite from course data-directory BCHB524 - Edwards

Check the data in the model... In the terminal: [student@localhost ~]$ tg-admin shell >>> print Taxonomy.byTaxid(9606) >>> t = Taxonomy.byTaxid(9606) >>> print t.names BCHB524 - Edwards

Let's add some functionality In controllers.py, let's add a new request Add necessary imports from model Add new method taxa with parameter taxid Use taxid to lookup Taxonomy object Create dynamic title string Send the title and taxa object to taxa.html template Access this page/resource as: http://localhost:8080/taxa?taxid=9606 http://localhost:8080/taxa/9606 Try it! BCHB524 - Edwards

Let's add some functionality In controllers.py, let's add a new request @expose(template="hoyataxa.templates.taxa") def taxa(self,taxid): """"Return the Taxonomy object.""" t = Taxonomy.byTaxId(int(taxid)) title = "Taxonomy: "+taxid return dict(title=title, taxa=t) BCHB524 - Edwards

Let's add some functionality Need to create taxa.html too Save welcome.html as taxa.html Change taxa.html BCHB524 - Edwards

Let's add some functionality Not pretty, but now we have dynamic title and dynamic content... BCHB524 - Edwards

Lets make it pretty Place the following HTML between the body tags in taxa.html: <P/> <table> <tr><th>Scientific Name</th><td>${taxa.scientific_name}</td></tr> <tr><th>NCBI Taxonomy ID</th><td>${taxa.taxid}</td></tr> <tr><th>Rank</th><td>${taxa.rank}</td></tr> <tr><th>Parent</th><td>${taxa.parent}</td></tr> </table> <P/> <table> <tr><th>Scientific Name</th><td>${taxa.scientific_name}</td></tr> <tr><th>NCBI Taxonomy ID</th><td>${taxa.taxid}</td></tr> <tr><th>Rank</th><td>${taxa.rank}</td></tr> <tr><th>Parent</th><td>${taxa.parent}</td></tr> </table> BCHB524 - Edwards

Let's make it pretty BCHB524 - Edwards

Fix the parent value BCHB524 - Edwards

Fix the parent value BCHB524 - Edwards

And make it clickable <A href="${tg.url('/taxa',taxid=taxa.parent.taxid)}">${taxa.parent.taxid}</A> BCHB524 - Edwards

And make it clickable BCHB524 - Edwards

List all the children <tr py:for="c in taxa.children"> <th>Child</th> <td>${c.scientific_name} (<A href="${tg.url('/taxa',taxid=c.taxid)}">${c.taxid}</A>) </td> </tr> BCHB524 - Edwards

List all children BCHB524 - Edwards

List all names <tr py:for="n in taxa.names"> <th>Name</th> <td> ${n.name} (${n.name_class}) </td> </tr> BCHB524 - Edwards

List all names BCHB524 - Edwards

Remove the scientific name py:if="n.name_class != 'scientific name'" BCHB524 - Edwards

Remove scientific name BCHB524 - Edwards

Let's add the lineage lineage = [] t1 = t while t1.taxid != 1: if t1.rank != 'no rank': lineage.append(t1) t1 = t1.parent lineage.reverse() return dict(title=t.scientific_name, taxa=t, lineage=lineage) BCHB524 - Edwards

Let’s add the lineage <tr><th>Lineage</th><td>${'; '.join([t.scientific_name for t in lineage])}</td></tr> BCHB524 - Edwards

Let’s add the lineage BCHB524 - Edwards

Next time We can now display a taxonomy record nicely if the user types a URL ...and then navigate about its heirachy. Need to be able to search the names based on a user query. Search form, list of matching results, etc... XML output for web-services. BCHB524 - Edwards