SelectDatabase.py :  » Web-Frameworks » Webware » Webware-1.0.2 » MiddleKit » WebBrowser » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Webware 
Webware » Webware 1.0.2 » MiddleKit » WebBrowser » SelectDatabase.py
from MiscUtils.DataTable import DataTable
from MiscUtils.Funcs import hostName
from SitePage import SitePage


class SelectDatabase(SitePage):

  def writeSideBar(self):
    self.writeln('<a href="?showHelp=1" class="SideBarLink">Help</a>')

  def writeContent(self):
    self.saveFieldsToCookies()
    self.writeDBForm(action='BrowseClasses')
    self.writeRecentDatabases()
    self.writeKnownDatabases()
    if self.request().hasField('showHelp'):
      self.writeHelp()

  def writeDBForm(self, method='get', action=''):
    if method:
      method = 'method="%s"' % method
    if action:
      action = 'action="%s"' % action
    source = '''\
name,type,comment,value
database,text,"e.g., MySQL"
host,text
user,text
password,password
'''
    fields = DataTable()
    fields.readString(source)
    req = self.request()
    wr = self.writeln

    self.writeHeading('Enter database connection info:')
    wr('<form %(method)s %(action)s>' % locals())
    wr('<table border="0" cellpadding="2" cellspacing="0">')
    for field in fields:
      field['value'] = req.value(field['name'], '')
      wr('<tr><td>%(name)s:</td><td></td><td>'
        '<input type="%(type)s" name="%(name)s" value="%(value)s">'
        '</td><td>%(comment)s</td></tr>' % field)
    wr('<tr><td colspan="2">&nbsp;</td><td align="right">'
      '<input type="submit" value="OK"></td><td>&nbsp;</td></tr>')
    wr('</table></form>')

  def writeRecentDatabases(self):
    self.writeHeading('Select a recent database:')
    self.writeln('<p>None</p>')

  def writeKnownDatabases(self):
    self.writeHeading('Select a known database:')
    knownDBs = self.setting('KnownDatabases')
    hostName = HostName()
    if not hostName:
      hostName = '_default_'
    dbs = knownDBs.get(hostName, []) + knownDBs.get('_all_', [])
    if dbs:
      for db in dbs:
        self.writeDB(db)
    else:
      self.writeln('<p>None</p>')

  def writeDB(self, db):
    # Set title
    title = '%(database)s on %(host)s' % db
    if db.get('user', ''):
      title += ' with ' + db['user']

    # Build up args for links
    args = []
    for key in self.dbKeys():
      if db.has_key(key):
        args.append('%s=%s' % (key, db[key]))
    args = '&'.join(args)

    # If the db connection info specifies a password, then
    # the user can click through immediately.
    # Otherwise, the click goes back to the same page with
    # the fields filled out so that the user can enter the password.
    if db.get('password', None):
      self.write('<p><a href="BrowseClasses?%s">%s</a>'
        ' (password included)' % (args, title))
    else:
      self.writeln('<p><a href="?%s">%s</a>'
        ' (password required)' % (args, title))

  def dbKeys(self):
    """Get keys for database connections.

    Returns a list of the valid keys that can be used for a
    "database connection dictionary". These dictionaries are
    found in the config file and in the recent list.

    """
    return ['database', 'host', 'user', 'password']
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.