Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 not having links to work properly
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
murrdawg




PostPosted: Sun Apr 05, 2009 3:41 pm   Post subject: not having links to work properly

This is my dilemma, and yes, I did post it in another forum too cause I'm not sure where it belongs... But basically, I have a database that I want to be able to access the account information...


Python:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cherrypy
import sqlite3

class Root(object):
        def index(self, lang='fr', *args):
                return """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                           "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
                           <html xmlns="
http://www.w3.org/1999/xhtml">
                           <head><meta content="
text/html; charset=utf-8" http-equiv="Content-Type"/>
                           <title>Bank DB</title>
                           </head><body>
                           <h1>Bank DB</h1>
                           <h3>What do you want to do?</h3>
                           <a href="
/branch">Branches</a>
                           <a href="
/client">Clients</a>
                           </form>
                           </body></html>"
""
        index.exposed = True

        def branch(self, branchno=None, accountno=None):
                query = "SELECT * FROM branch"
                if branchno:
                        query = "SELECT * FROM account"
                        query += " WHERE branchno=\"" + branchno+"\""
                cherrypy.response.headers['Content-Type'] = 'text/html'
                results = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head><meta content="
text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>Bank DB</title>
</head><body>"
""
                results += self.exec_query("bank.db", query, "/branch?branchno=")
                results += """</body></html>"""
               
                return results
       
        branch.exposed = True

        def client(self, clientno=None):
                query = "SELECT * FROM client"
                if clientno:
                        query = "SELECT accountno FROM clientAccount"
                        query += " WHERE clientno = " + clientno
                cherrypy.response.headers['Content-Type'] = 'text/html'
                results = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head><meta content="
text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>Bank DB</title>
</head><body>"
""
                results += self.exec_query("bank.db", query, "/account?accountno=")
                results += """</body></html>"""
                return results
        client.exposed = True
       
        def account (self, accountno=None):
                query = "SELECT * FROM account"
                target = "/account?accountno="
                if accountno:
                        query = "SELECT clientno, lastname, firstname,  account.*, trans.*"
                        query += " FROM client, clientAccount, account, trans"
                        query += " WHERE account.accountno = " + accountno + " AND trans.accountno = account.accountno AND"
                        query += " clientAccount.accountno = account.accountno AND client.clientno = clientAccount.clientno"
                        target= "/client?clientno="
                cherrypy.response.headers['Content-Type'] = 'text/html'
                results = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head><meta content="
text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>Bank DB</title>
</head><body>"
""
                results += self.exec_query("bank.db", query, target)
                results += """</body></html>"""
                return results
        account.exposed = True


        def exec_query(self, database, query, linkprefix=""):
                results = """<table rules="all" width="75%" border="4" cellpadding="5"><tr>"""
                try:
                        con = sqlite3.connect(database)
                        cur = con.cursor()       
                        cur.execute(query)
                        desc = cur.description
                        for att in range(len(desc)):
                                results += "<th>" + desc[att][0] + "</th>"
                        results += "</tr>"
                        for tup in cur.fetchall():
                                results += '<tr><td><a href="' + linkprefix + unicode(tup[0]) + '">' + unicode(tup[0]) + '</a></td>'
                                for c in range(1, len(tup)):
                                        results += "<td>" + unicode(tup[c]) + "</td>"
                                results += "</tr>"
                        results += "</table>"
                except sqlite3.Error, e:
                        return unicode(e)
                con.commit()
                con.close()
                return results



cherrypy.quickstart(Root(), '/', 'bank.config')



The attached link is the code I have for this program... basically the user will see the list of branches, then click on a branch to see accounts in the branch... but when i click on an account, it doesn't show up the account information and I have no idea why. So how would I modify it so that clicking on the accountno will show the account information?



ass4.zip
 Description:
all files needed

Download
 Filename:  ass4.zip
 Filesize:  3.93 KB
 Downloaded:  124 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: