StorePage.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 » StorePage.py
import os, sys

from MiddleKit.Run.MySQLObjectStore import MySQLObjectStore
from SitePage import SitePage


class StorePage(SitePage):


  ## Init ##

  def __init__(self):
    SitePage.__init__(self)
    self._store = None


  ## Access ##

  def modelFilename(self):
    req = self.request()
    filename = req.field('modelFilename', None)
    if filename:
      self.response().setCookie('modelFilename', filename)
    else:
      filename = req.cookie('modelFilename', None)
    return filename

  def store(self):
    if not self._store:
      self.saveFieldsToCookies()
      modelFilename = self.modelFilename()
      # MK will need access to the Python classes for the model.
      # We expect to find them with the actual model file,
      # so we update sys.path appropriately:
      extraDir = os.path.dirname(modelFilename)
      # We need the parent directory of the model package:
      extraDir = os.path.dirname(extraDir)
      if extraDir not in sys.path:
        sys.path.insert(1, extraDir)
      req = self.request()
      self._store = MySQLObjectStore(host=req.value('host'),
        user=req.value('user'), passwd=req.value('password'))
      self._store.readModelFileNamed(modelFilename)
      self._store.connect()
      recentModels = self.request().cookie('recentModels', [])
      if recentModels:
        recentModels = recentModels.split(';')
      if modelFilename not in recentModels:
        recentModels.append(modelFilename)
        recentModels = ';'.join(recentModels)
        self.response().setCookie('recentModels', ';'.join(recentModels))
    return self._store


  ## Writing page parts ##

  def writeTopBar(self):
    names = os.path.split(self.modelFilename())
    self.writeln('<p><a href="SelectModel" class="SelectLink">SELECT</a>'
      ' <span class=StatusBar>%s - %s</span></p>' % (names[1], names[0]))
    req = self.request()
    self.writeln('<p><a href="SelectDatabase" class="SelectLink">SELECT</a>'
      ' <span class="StatusBar">db=%s, host=%s, user=%s</span></p>'
      % (req.value('database'), req.value('host'), req.value('user')))

  def writeSideBar(self):
    self.writeKlasses()

  def writeKlasses(self):
    # @@ 2000-11-27 ce: move this to MixIns???
    curClassName = self.request().field('class', None)
    klasses = self.store().model().klasses()
    names = klasses.keys()
    names.sort()
    modelFilename = self.urlEncode(self.modelFilename())
    for name in names:
      urlName = self.urlEncode(name)
      if name == curClassName:
        style = 'CurClassLink'
      else:
        style = 'ClassLink'
      self.writeln('<p><a href="BrowseObjects?class=%s" class"=%s">'
        '%s</a></p>' % (name, style, urlName))

  def writeContent(self):
    self.writeln('<p>Woops. Forgot to override writeContent().</p>')
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.