mirror of https://github.com/tLDP/LDP
Removing woven test code
This commit is contained in:
parent
5eb72be848
commit
a9e2e0b892
|
@ -1,14 +0,0 @@
|
|||
build: tap
|
||||
|
||||
tap:
|
||||
mktap lampadas
|
||||
|
||||
start: tap
|
||||
twistd -n -f lampadas.tap
|
||||
|
||||
clean:
|
||||
rm -f *.pyc
|
||||
rm -f *.tap
|
||||
rm -f *.log
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
"""
|
||||
This is test code to implement Lampadas services on the Twisted framework.
|
||||
"""
|
|
@ -1,71 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from twisted.internet import app
|
||||
from twisted.python import usage, components
|
||||
from twisted.web.resource import Resource
|
||||
from twisted.internet import reactor
|
||||
|
||||
from twisted.web.woven import model, view, controller, interfaces
|
||||
from twisted.web.woven import widgets
|
||||
from twisted.web import domhelpers, server
|
||||
import twisted.web
|
||||
import twisted.protocols.http
|
||||
|
||||
class MList(model.ListModel):
|
||||
def __init__(self, orig, *args, **kwargs):
|
||||
print 'Initializing...'
|
||||
model.Model.__init__(self, *args, **kwargs)
|
||||
model.ListModel.__init__(self, orig)
|
||||
|
||||
class VList(view.WView):
|
||||
templateFile = 'example.xhtml'
|
||||
|
||||
#def setUp(self, request, document):
|
||||
#print 'Initializing List View: '
|
||||
|
||||
def wvfactory_list(self, request, node, model):
|
||||
#domhelpers.clearNode(node)
|
||||
return widgets.List(model)
|
||||
|
||||
class CList(controller.WController):
|
||||
pass
|
||||
|
||||
view.registerViewForModel(VList, MList)
|
||||
controller.registerControllerForModel(CList, MList)
|
||||
|
||||
|
||||
class Options(usage.Options):
|
||||
optParameters = [["port", "p", 8080,
|
||||
"Port to listen with Webserver"]]
|
||||
|
||||
class Page(twisted.web.widgets.WidgetPage):
|
||||
template = '<html><head></head><body>%%%%self.widget%%%%</body></html>'
|
||||
|
||||
class Foo:
|
||||
pass
|
||||
|
||||
foo = Foo()
|
||||
foo.list = ['foo', 'bar']
|
||||
|
||||
class Gadget(twisted.web.widgets.Gadget):
|
||||
def __init__(self):
|
||||
print 'Initializing gadget'
|
||||
twisted.web.widgets.Gadget.__init__(self)
|
||||
self.pageFactory = Page
|
||||
|
||||
def getChild(self, path, request):
|
||||
m = MList(foo.list)
|
||||
v = VList(m, 'example.xhtml')
|
||||
c = CList(m)
|
||||
c.setView(v)
|
||||
return v
|
||||
|
||||
def updateApplication(app, config):
|
||||
port = config['port']
|
||||
root = Gadget()
|
||||
site = server.Site(root)
|
||||
app.listenTCP(port, site)
|
||||
|
||||
root = Gadget()
|
||||
site = server.Site(root)
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p class="listHeader"><b>A</b></p>
|
||||
<ul view="list">
|
||||
<li id="listItem" view="Text"></li>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from twisted.web.woven import model, view, controller
|
||||
from twisted.web.woven import widgets, input
|
||||
from twisted.web import domhelpers
|
||||
|
||||
#from TwistedQuotes import quoters
|
||||
|
||||
|
||||
import cgi
|
||||
|
||||
class MQuote(model.WModel):
|
||||
def __init__(self):
|
||||
print 'Loading MQuote'
|
||||
model.WModel.__init__(self)
|
||||
#self._filename = filename
|
||||
#self._quoter = quoters.FortuneQuoter([filename])
|
||||
self.quote = "Hello, world!"
|
||||
self.title = "Quotes Galore!"
|
||||
self.newQuote = ""
|
||||
|
||||
def updateQuote(self):
|
||||
self.quote = 'Hello, world!'
|
||||
|
||||
class QuoteWidget(widgets.Widget):
|
||||
def setUp(self, request, node, data):
|
||||
"""
|
||||
Set up this Widget object before it gets rendered into HTML.
|
||||
|
||||
Since self is a Widget, I can use the higher level widget API to add a
|
||||
Text widget to self. I then rely on Widget.generateDOM to convert
|
||||
from Widgets into the Document Object Model.
|
||||
"""
|
||||
self.add(widgets.Text(cgi.escape(data)))
|
||||
|
||||
|
||||
class VQuote(view.WView):
|
||||
templateFile = "home.xhtml"
|
||||
|
||||
def setUp(self, request, document):
|
||||
"""
|
||||
Set things up for this request.
|
||||
"""
|
||||
self.model.updateQuote()
|
||||
|
||||
def wvfactory_quote(self, request, node, model):
|
||||
"""Create a widget which knows how to render my model's quote."""
|
||||
domhelpers.clearNode(node)
|
||||
return QuoteWidget(model)
|
||||
|
||||
def wvfactory_title(self, request, node, model):
|
||||
"""Create a widget which knows how to render my model's title."""
|
||||
domhelpers.clearNode(node)
|
||||
return widgets.Text(model)
|
||||
|
||||
|
||||
class NewQuoteHandler(input.SingleValue):
|
||||
def check(self, request, data):
|
||||
if data:
|
||||
return 1
|
||||
|
||||
def commit(self, request, node, newQuote):
|
||||
print "committing new quote", `newQuote`
|
||||
file = open(self.model.getQuoteFilename(), 'a')
|
||||
file.write('\n%\n' + newQuote)
|
||||
|
||||
|
||||
class CQuote(controller.WController):
|
||||
def wcfactory_newQuote(self, model):
|
||||
"""Create a handler which knows how to verify input in a form with the
|
||||
name "newQuote"."""
|
||||
return NewQuoteHandler(model)
|
||||
|
||||
|
||||
view.registerViewForModel(VQuote, MQuote)
|
||||
controller.registerControllerForModel(CQuote, MQuote)
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# -*- Python -*-
|
||||
|
||||
import home
|
||||
|
||||
#__file__ is defined to be the name of this file; this is to
|
||||
#get the sibling file "quotes.txt" which should be in the same directory
|
||||
import os
|
||||
#quotefile = os.path.join(os.path.split(__file__)[0], "quotes.txt")
|
||||
|
||||
# Construct a model object which will contain the data for display by the
|
||||
# web page
|
||||
model = home.MQuote()
|
||||
|
||||
# ResourceScript requires us to define 'resource'. This resource is used
|
||||
# to render the page.
|
||||
resource = home.CQuote(model)
|
||||
|
||||
# The CQuote controller will look up a View (VQuote) and call render()
|
||||
# on it, rendering the DOMTemplate
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<title view="title" model="title">
|
||||
Title will go here
|
||||
</title>
|
||||
<style>
|
||||
.quote {color: red;}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1 view="title" model="title">
|
||||
Title will go here
|
||||
</h1>
|
||||
|
||||
<pre view="quote" model="quote" class="quote">
|
||||
Quote will go here.
|
||||
</pre>
|
||||
|
||||
<form action="">
|
||||
<input type="text" model="newQuote" controller="newQuote" name="newQuote" />
|
||||
<input type="submit" />
|
||||
</form>
|
||||
<a href="home.rpy">Refresh</a>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<title view="title">
|
||||
<li id="listItem" view="RawText"></li>
|
||||
</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<h1 view="title">
|
||||
<li id="listItem" view="RawText"></li>
|
||||
</h1>
|
||||
<table align="right" view="section_bar"></table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" view="menu">
|
||||
<b id="emptyList">There are no sections.</b>
|
||||
<p id="listItem" view="Text">
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p view="page_items">
|
||||
<li id="emptyList">There are no embedded widgets.</li>
|
||||
<li id="listItem" view="RawText"></li>
|
||||
</p>
|
||||
|
||||
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
Footer
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Lampadas imports
|
||||
from Config import config
|
||||
|
||||
# Twisted imports
|
||||
from twisted.internet import reactor
|
||||
from twisted.enterprise import adbapi, row, reflector
|
||||
from twisted.enterprise.sqlreflector import SQLReflector
|
||||
from twisted.python import usage
|
||||
from twisted.cred.authorizer import DefaultAuthorizer
|
||||
from twisted.internet import defer
|
||||
|
||||
# Sibling imports
|
||||
from row import ROW_CLASSES
|
||||
|
||||
|
||||
class Block:
|
||||
def __init__(self, refl):
|
||||
self.refl = refl
|
||||
|
||||
def get_all(self, callback):
|
||||
self.refl.loadObjectsFrom('block').addCallback(callback)
|
||||
|
||||
def get_by_code(self, code, callback):
|
||||
w = [('block_code', reflector.EQUAL, code)]
|
||||
self.refl.loadObjectsFrom('block', whereClause=w).addCallback(callback)
|
||||
|
||||
class Page:
|
||||
def __init__(self, refl):
|
||||
self.refl = refl
|
||||
|
||||
def get_all(self, callback):
|
||||
self.refl.loadObjectsFrom('page').addCallback(callback)
|
||||
|
||||
def get_by_code(self, code, callback):
|
||||
w = [('page_code', reflector.EQUAL, code)]
|
||||
self.refl.loadObjectsFrom('page', whereClause=w).addCallback(callback)
|
||||
|
||||
class Section:
|
||||
def __init__(self, refl):
|
||||
self.refl = refl
|
||||
|
||||
def get_all(self, callback):
|
||||
self.refl.loadObjectsFrom('section').addCallback(callback)
|
||||
|
||||
def get_by_code(self, code, callback):
|
||||
w = [('section_code', reflector.EQUAL, code)]
|
||||
self.refl.loadObjectsFrom('section', whereClause=w).addCallback(callback)
|
||||
|
||||
class String:
|
||||
def __init__(self, refl):
|
||||
self.refl = refl
|
||||
|
||||
def get_all(self, callback):
|
||||
self.refl.loadObjectsFrom('string').addCallback(callback)
|
||||
|
||||
def get_by_code(self, code, callback):
|
||||
w = [('string_code', reflector.EQUAL, code)]
|
||||
self.refl.loadObjectsFrom('string', whereClause=w).addCallback(callback)
|
||||
|
||||
class Objects:
|
||||
def connect(self, callback):
|
||||
if config.db_type=='pgsql':
|
||||
db_module = 'pyPgSQL.PgSQL'
|
||||
else:
|
||||
db_module = 'pyMySQL.MySQL'
|
||||
self.dbpool = adbapi.ConnectionPool(db_module, database=config.db_name, user='www-data')
|
||||
self.refl = SQLReflector(self.dbpool, ROW_CLASSES, callback)
|
||||
|
||||
self.block = Block(self.refl)
|
||||
self.page = Page(self.refl)
|
||||
self.section = Section(self.refl)
|
||||
self.string = String(self.refl)
|
||||
|
||||
object_server = Objects()
|
|
@ -1,80 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Lampadas imports
|
||||
from Config import config
|
||||
|
||||
# Twisted imports
|
||||
from twisted.spread import pb
|
||||
from twisted.internet import reactor
|
||||
from twisted.enterprise import adbapi, row, reflector
|
||||
from twisted.enterprise.sqlreflector import SQLReflector
|
||||
from twisted.python import usage
|
||||
from twisted.cred.authorizer import DefaultAuthorizer
|
||||
from twisted.internet import defer
|
||||
|
||||
# Sibling imports
|
||||
from row import BlockRow, PageRow, PageI18nRow
|
||||
|
||||
ROW_CLASSES = [BlockRow, PageRow, PageI18nRow]
|
||||
|
||||
def loaded(object):
|
||||
print 'ObjectService loaded: ', object
|
||||
return object
|
||||
|
||||
class Page(pb.Copyable):
|
||||
def __init__(self, refl):
|
||||
print 'Initializing Page'
|
||||
refl.loadObjectsFrom('page').addCallback(self.loaded)
|
||||
|
||||
def loaded(self, pages):
|
||||
print 'Page.loaded()'
|
||||
self.pages = pages
|
||||
|
||||
def get_all(self, refl):
|
||||
refl.loadObjectsFrom('page').addCallback(loaded)
|
||||
|
||||
def get_by_code(self, refl, code):
|
||||
print 'ObjectService serving block: ', code
|
||||
w = [('block_code', reflector.EQUAL, code)]
|
||||
refl.loadObjectsFrom('block', whereClause=w).addCallback(loaded)
|
||||
|
||||
def connected(result):
|
||||
print 'Object Server Ready.'
|
||||
|
||||
class Objects(pb.Perspective):
|
||||
|
||||
def __init__(self, perspectiveName, identityName='Nobody'):
|
||||
pb.Perspective.__init__(self, perspectiveName, identityName)
|
||||
if config.db_type=='pgsql':
|
||||
self.db_module = 'pyPgSQL.PgSQL'
|
||||
else:
|
||||
self.db_module = 'pyMySQL.MySQL'
|
||||
self.dbpool = adbapi.ConnectionPool(self.db_module, database=config.db_name, user='www-data')
|
||||
self.refl = SQLReflector(self.dbpool, ROW_CLASSES, connected)
|
||||
reactor.callLater(0.5, self.load)
|
||||
|
||||
def load(self):
|
||||
print 'Objects.load()'
|
||||
self.page = Page(self.refl)
|
||||
|
||||
def perspective_page(self):
|
||||
print 'Client requested pages'
|
||||
return self.page.pages
|
||||
|
||||
class ObjectService(pb.Service):
|
||||
perspectiveClass = Objects
|
||||
|
||||
|
||||
class Options(usage.Options):
|
||||
optParameters = [['port', 'p', 8790, 'Port to listed on.']]
|
||||
|
||||
def updateApplication(app, config):
|
||||
port = config['port']
|
||||
if port:
|
||||
auth = DefaultAuthorizer(app)
|
||||
serv = ObjectService('lampadas.objects', app, auth)
|
||||
serv.createPerspective("guest").makeIdentity("guest")
|
||||
fact = pb.BrokerFactory(pb.AuthRoot(auth))
|
||||
app.listenTCP(int(port), fact)
|
||||
reactor.run()
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import object_server
|
||||
from twisted.python import usage
|
||||
from twisted.spread import pb
|
||||
from twisted.cred.authorizer import DefaultAuthorizer
|
||||
|
||||
class Options(usage.Options):
|
||||
optParameters = [["port", "p", 8790,
|
||||
"Port to listen with ObjectService"]]
|
||||
|
||||
def updateApplication(app, config):
|
||||
# port = int(config["port"])
|
||||
# fact = pb.BrokerFactory(object_server.Block())
|
||||
# app.listenTCP(port, factory)
|
||||
|
||||
# Test code, moving to use perspectives!
|
||||
port = config['port']
|
||||
if port:
|
||||
auth = DefaultAuthorizer(app)
|
||||
serv = object_server.ObjectService('lampadas.objects', app, auth)
|
||||
serv.createPerspective("guest").makeIdentity("guest")
|
||||
fact = pb.BrokerFactory(pb.AuthRoot(auth))
|
||||
app.listenTCP(int(port), fact)
|
||||
|
||||
|
||||
# appl = app.Application('pbsimple')
|
||||
# appl.listenTCP(8789, pb.BrokerFactory(Block()))
|
||||
# appl.run()
|
|
@ -1,30 +0,0 @@
|
|||
register("Lampadas Object Broker",
|
||||
"lampadas.pbtap",
|
||||
description="Lampadas Documentation Management object server.",
|
||||
type="tap",
|
||||
tapname="lampadas")
|
||||
|
||||
register("Lampadas Data Objects",
|
||||
"lampadas.pbobjects",
|
||||
description="Lampadas Data Object Server.",
|
||||
type="tap",
|
||||
tapname="objects")
|
||||
|
||||
register("Lampadas Website",
|
||||
"lampadas.web",
|
||||
description="Lampadas Website.",
|
||||
type="tap",
|
||||
tapname="lampadasweb")
|
||||
|
||||
register("Lampadas Woven Website",
|
||||
"lampadas.woven",
|
||||
description="Lampadas Woven Website.",
|
||||
type="tap",
|
||||
tapname="lampadaswoven")
|
||||
|
||||
register("Woven Example",
|
||||
"lampadas.example",
|
||||
description="Woven Example.",
|
||||
type="tap",
|
||||
tapname="example")
|
||||
|
|
@ -1,168 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from twisted.enterprise import row
|
||||
from types import *
|
||||
from Globals import trim
|
||||
from BaseClasses import LampadasCollection
|
||||
|
||||
def rowFactory(Klass, userData, kw):
|
||||
newObject = Klass()
|
||||
for key in kw.keys():
|
||||
value = kw[key]
|
||||
if type(value) is StringType:
|
||||
value = trim(value)
|
||||
kw[key] = value
|
||||
newObject.__dict__.update(kw)
|
||||
return newObject
|
||||
|
||||
class Block(row.RowObject):
|
||||
rowFactoryMethod = [rowFactory]
|
||||
rowTableName = 'block'
|
||||
rowKeyColumns = [('block_code', 'varchar')]
|
||||
rowColumns = [('block_code', 'varchar'),
|
||||
('block', 'varchar'),
|
||||
('created', 'timestamp'),
|
||||
('updated', 'timestamp')]
|
||||
|
||||
class Document(row.RowObject):
|
||||
rowFactoryMethod = [rowFactory]
|
||||
rowTableName = 'document'
|
||||
rowKeyColumns = [('doc_id', 'int')]
|
||||
rowColumns = [('doc_id', 'int'),
|
||||
('lang', 'varchar'),
|
||||
('title', 'varchar'),
|
||||
('short_title', 'varchar'),
|
||||
('type_code', 'varchar'),
|
||||
('format_code', 'varchar'),
|
||||
('dtd_code', 'varchar'),
|
||||
('dtd_version', 'varchar'),
|
||||
('version', 'varchar'),
|
||||
('last_update', 'timestamp'),
|
||||
('isbn', 'varchar'),
|
||||
('pub_status_code', 'varchar'),
|
||||
('review_status_code', 'varchar'),
|
||||
('tickle_date', 'timestamp'),
|
||||
('pub_date', 'timestamp'),
|
||||
('tech_review_status_code', 'varchar'),
|
||||
('maintained', 'bool'),
|
||||
('maintainer_wanted', 'bool'),
|
||||
('license_code', 'varchar'),
|
||||
('license_version', 'varchar'),
|
||||
('copyright_holder', 'varchar'),
|
||||
('abstract', 'varchar'),
|
||||
('short_desc', 'varchar'),
|
||||
('rating', 'int'),
|
||||
('sk_seriesid', 'int'),
|
||||
('replaced_by_id', 'int'),
|
||||
('lint_time', 'timestamp'),
|
||||
('pub_time', 'timestamp'),
|
||||
('mirror_time', 'timestamp'),
|
||||
('first_pub_date', 'timestamp'),
|
||||
('encoding', 'varchar'),
|
||||
('created', 'timestamp'),
|
||||
('updated', 'timestamp')]
|
||||
|
||||
class Page(row.RowObject):
|
||||
rowFactoryMethod = [rowFactory]
|
||||
rowTableName = 'page'
|
||||
rowKeyColumns = [('page_code', 'varchar')]
|
||||
rowColumns = [('page_code', 'varchar'),
|
||||
('section_code', 'varchar'),
|
||||
('sort_order', 'int'),
|
||||
('template_code', 'varchar'),
|
||||
('data', 'varchar'),
|
||||
('only_dynamic', 'bool'),
|
||||
('only_registered', 'bool'),
|
||||
('only_admin', 'bool'),
|
||||
('only_sysadmin', 'bool')]
|
||||
|
||||
def __init__(self):
|
||||
self.title = LampadasCollection()
|
||||
self.menu_name = LampadasCollection()
|
||||
self.page = LampadasCollection()
|
||||
self.version = LampadasCollection()
|
||||
|
||||
def addI18n(self, i18n):
|
||||
lang = i18n.lang
|
||||
self.title[lang] = i18n.title
|
||||
self.menu_name[lang] = i18n.menu_name
|
||||
self.page[lang] = i18n.page
|
||||
self.version[lang] = i18n.version
|
||||
|
||||
class PageI18n(row.RowObject):
|
||||
rowFactoryMethod = [rowFactory]
|
||||
rowTableName = 'page_i18n'
|
||||
rowKeyColumns = [('page_code', 'varchar'),
|
||||
('lang', 'varchar')]
|
||||
rowColumns = [('page_code', 'varchar'),
|
||||
('lang', 'varchar'),
|
||||
('title', 'text'),
|
||||
('menu_name', 'text'),
|
||||
('page', 'text'),
|
||||
('version', 'varchar'),
|
||||
('created', 'timestamp'),
|
||||
('updated', 'timestamp')]
|
||||
rowForeignKeys = [('page', [('page_code', 'varchar')], [('page_code', 'varchar')], 'addI18n', 1)]
|
||||
|
||||
class Section(row.RowObject):
|
||||
rowFactoryMethod = [rowFactory]
|
||||
rowTableName = 'section'
|
||||
rowKeyColumns = [('section_code', 'varchar')]
|
||||
rowColumns = [('section_code', 'varchar'),
|
||||
('sort_order', 'int'),
|
||||
('only_dynamic', 'bool'),
|
||||
('created', 'timestamp'),
|
||||
('updated', 'timestamp')]
|
||||
|
||||
def __init__(self):
|
||||
self.section_name = LampadasCollection()
|
||||
|
||||
def addI18n(self, i18n):
|
||||
lang = i18n.lang
|
||||
self.section_name[lang] = i18n.section_name
|
||||
|
||||
class SectionI18n(row.RowObject):
|
||||
rowFactoryMethod = [rowFactory]
|
||||
rowTableName = 'section_i18n'
|
||||
rowKeyColumns = [('section_code', 'varchar'),
|
||||
('lang', 'varchar')]
|
||||
rowColumns = [('section_code', 'varchar'),
|
||||
('lang', 'varchar'),
|
||||
('section_name', 'varchar'),
|
||||
('created', 'timestamp'),
|
||||
('updated', 'timestamp')]
|
||||
rowForeignKeys = [('section', [('section_code', 'varchar')], [('section_code', 'varchar')], 'addI18n', 1)]
|
||||
|
||||
class String(row.RowObject):
|
||||
rowFactoryMethod = [rowFactory]
|
||||
rowTableName = 'string'
|
||||
rowKeyColumns = [('string_code', 'varchar')]
|
||||
rowColumns = [('string_code', 'varchar'),
|
||||
('created', 'timestamp'),
|
||||
('updated', 'timestamp')]
|
||||
|
||||
def __init__(self):
|
||||
self.string = LampadasCollection()
|
||||
self.version = LampadasCollection()
|
||||
|
||||
def addI18n(self, i18n):
|
||||
lang = i18n.lang
|
||||
self.string[lang] = i18n.string
|
||||
self.version[lang] = i18n.version
|
||||
|
||||
class StringI18n(row.RowObject):
|
||||
rowFactoryMethod = [rowFactory]
|
||||
rowTableName = 'string_i18n'
|
||||
rowKeyColumns = [('string_code', 'varchar'),
|
||||
('lang', 'varchar')]
|
||||
rowColumns = [('string_code', 'varchar'),
|
||||
('lang', 'varchar'),
|
||||
('string', 'varchar'),
|
||||
('version', 'varchar'),
|
||||
('created', 'timestamp'),
|
||||
('updated', 'timestamp')]
|
||||
rowForeignKeys = [('string', [('string_code', 'varchar')], [('string_code', 'varchar')], 'addI18n', 1)]
|
||||
|
||||
|
||||
ROW_CLASSES = [Block, Document, Page, PageI18n, Section, SectionI18n, String, StringI18n]
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
This is a test client, that requests a Perspective
|
||||
into the Lampadas Object Service.
|
||||
"""
|
||||
|
||||
from twisted.python import log
|
||||
log.discardLogs()
|
||||
from twisted.internet import reactor
|
||||
from twisted.spread import pb
|
||||
|
||||
def connected(perspective):
|
||||
print 'Connected.'
|
||||
perspective.callRemote('load').addCallbacks(success, failure)
|
||||
perspective.callRemote('page').addCallbacks(success, failure)
|
||||
|
||||
def connect_failure(error):
|
||||
print "Error connecting to ObjectService.."
|
||||
reactor.stop()
|
||||
|
||||
def success(block):
|
||||
print 'ObjectService gave me block: ' + block.code
|
||||
reactor.stop()
|
||||
|
||||
def failure(error):
|
||||
print "Failed to obtain a block from the ObjectService."
|
||||
reactor.stop()
|
||||
|
||||
def gotRoot(root):
|
||||
print 'Got root: ', root
|
||||
print dir(root)
|
||||
|
||||
def gotNoRoot(error):
|
||||
print 'Failed to obtain root: ', error
|
||||
|
||||
pb.connect("localhost", # host name
|
||||
8790, # port number
|
||||
"guest", # identity name
|
||||
"guest", # password
|
||||
"lampadas.objects", # service name
|
||||
"guest", # perspective name (usually same as identity)
|
||||
30 # timeout of 30 seconds before connection gives up
|
||||
).addCallbacks(connected, # what to do when we get connected
|
||||
connect_failure) # and what to do when we can't
|
||||
|
||||
pb.getObjectAt('localhost', 8790, 30).addCallbacks(gotRoot, gotNoRoot)
|
||||
reactor.run() # start the main loop
|
|
@ -1,53 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from twisted.internet import app
|
||||
from twisted.web import server, widgets
|
||||
from twisted.python import usage
|
||||
from twisted.web.resource import Resource
|
||||
from twisted.internet import reactor
|
||||
from objects import object_server
|
||||
|
||||
class Options(usage.Options):
|
||||
optParameters = [["port", "p", 8080,
|
||||
"Port to listen with Webserver"]]
|
||||
|
||||
class Page(widgets.WidgetPage):
|
||||
template = '<html><head></head><body>%%%%self.widget%%%%</body></html>'
|
||||
|
||||
class Gadget(widgets.Gadget):
|
||||
def __init__(self):
|
||||
print 'Initializing gadget'
|
||||
widgets.Gadget.__init__(self)
|
||||
self.pageFactory = Page
|
||||
self.putWidget('hello', HelloWorld())
|
||||
self.putWidget('', HelloWorld())
|
||||
print 'connecting object_server...'
|
||||
object_server.connect(self.connected)
|
||||
|
||||
def connected(self, message):
|
||||
print 'object server is connected, loading pages...'
|
||||
object_server.page.get_all(self.loaded)
|
||||
|
||||
def loaded(self, pages):
|
||||
print 'Pages loaded:'
|
||||
for row in pages:
|
||||
page = WebPage()
|
||||
page.row = row
|
||||
self.putWidget(page.row.page_code, page)
|
||||
|
||||
class WebPage(widgets.Widget):
|
||||
def display(self, request):
|
||||
return [self.row.page_code]
|
||||
|
||||
class HelloWorld(widgets.Widget):
|
||||
def display(self, request):
|
||||
return ['Hello, world!']
|
||||
|
||||
def updateApplication(app, config):
|
||||
port = config['port']
|
||||
root = Gadget()
|
||||
site = server.Site(root)
|
||||
app.listenTCP(port, site)
|
||||
|
||||
root = Gadget()
|
||||
site = server.Site(root)
|
|
@ -1,391 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from twisted.internet import app
|
||||
from twisted.web import server
|
||||
from twisted.python import usage, components
|
||||
from twisted.web.resource import Resource
|
||||
from twisted.internet import reactor
|
||||
from objects import object_server
|
||||
|
||||
from twisted.web.woven import model, view, controller, interfaces
|
||||
from twisted.web.woven import widgets
|
||||
from twisted.web import domhelpers
|
||||
import cgi
|
||||
import twisted.web
|
||||
|
||||
from Globals import state, VERSION
|
||||
from URLParse import URI
|
||||
from BaseClasses import LampadasCollection
|
||||
|
||||
# Custom Widgets
|
||||
class I18nTextWidget(widgets.Text):
|
||||
def __init__(self, text, raw=1, lang='EN'):
|
||||
widgets.Text.__init__(self, text, raw=raw)
|
||||
self.lang = lang
|
||||
|
||||
def getData(self):
|
||||
return widgets.Text.getData(self)[self.lang]
|
||||
|
||||
class I18nListWidget(widgets.List):
|
||||
def __init__(self, model=None, submodel=None, setup=None, lang='EN'):
|
||||
widgets.List.__init__(self, model, submodel, setup)
|
||||
self.lang = lang
|
||||
|
||||
def getData(self):
|
||||
return widgets.List.getData(self)[self.lang]
|
||||
|
||||
class SectionBarWidget(widgets.Widget):
|
||||
def generateDOM(self, request, node):
|
||||
document = widgets.document
|
||||
|
||||
self.cleanNode(node)
|
||||
|
||||
tr_node = document.createElement('tr')
|
||||
node.appendChild(tr_node)
|
||||
|
||||
for key in sections.sort_by('sort_order'):
|
||||
td_node = document.createElement('td')
|
||||
tr_node.appendChild(td_node)
|
||||
a_node = document.createElement('a')
|
||||
td_node.appendChild(a_node)
|
||||
|
||||
section = sections[key].object
|
||||
href = '%ssection/%s%s' % (state.uri.base, section.section_code, state.uri.lang_ext)
|
||||
name = section.section_name[state.uri.lang]
|
||||
|
||||
a_node.setAttribute('href', href)
|
||||
text_node = document.createTextNode(name)
|
||||
a_node.appendChild(text_node)
|
||||
return self.node
|
||||
|
||||
# Holds an MVC triad as well as the original row object in a neat package.
|
||||
class MVC:
|
||||
def __init__(self, rowobject, business_object, object_model, object_view, object_controller):
|
||||
self.row = rowobject
|
||||
self.object = business_object
|
||||
self.model = object_model
|
||||
self.view = object_view
|
||||
self.controller = object_controller
|
||||
self.__dict__.update(rowobject.__dict__)
|
||||
self.object.__dict__.update(rowobject.__dict__)
|
||||
|
||||
# Parse strings, replacing tokens and text with appropriate widgets.
|
||||
def replace_token(token):
|
||||
if token=='uri.base':
|
||||
return state.uri.base
|
||||
elif token=='uri.lang_ext':
|
||||
return state.uri.lang_ext
|
||||
elif token=='version':
|
||||
return VERSION
|
||||
elif token=='':
|
||||
return ''
|
||||
|
||||
print 'Cannot replace token: ', token
|
||||
return '<font color="red">%s</font>' % token
|
||||
|
||||
def build_items(object, text):
|
||||
object.items = []
|
||||
counter = 0
|
||||
temp = text.replace('\|', 'DCM_PIPE')
|
||||
for piece in temp.split('|'):
|
||||
counter += 1
|
||||
is_text = counter % 2
|
||||
if is_text:
|
||||
piece = piece.replace('DCM_PIPE', '\|')
|
||||
if piece > '':
|
||||
object.items.append(piece)
|
||||
else:
|
||||
if strings.has_key(piece):
|
||||
object.items.append(strings[piece].string[lang])
|
||||
elif blocks.has_key(piece):
|
||||
object.items.append(blocks[piece].block[lang])
|
||||
else:
|
||||
newstring = replace_token(piece)
|
||||
object.items.append(newstring)
|
||||
return object.items
|
||||
|
||||
def build_lang_items(object, text):
|
||||
object.items = LampadasCollection()
|
||||
for lang in text.keys():
|
||||
counter = 0
|
||||
items = []
|
||||
temp = text[lang].replace('\|', 'DCM_PIPE')
|
||||
for piece in temp.split('|'):
|
||||
counter += 1
|
||||
is_text = counter % 2
|
||||
if is_text:
|
||||
piece = piece.replace('DCM_PIPE', '\|')
|
||||
if piece > '':
|
||||
items.append(piece)
|
||||
else:
|
||||
if strings.has_key(piece):
|
||||
items.append(strings[piece].string[lang])
|
||||
elif blocks.has_key(piece):
|
||||
items.append(blocks[piece].block[lang])
|
||||
else:
|
||||
newstring = replace_token(piece)
|
||||
items.append(newstring)
|
||||
object.items[lang] = items
|
||||
return object.items
|
||||
|
||||
# Collections of MVC triads.
|
||||
# Each collection has its own MVC, and each object in the collection does as well.
|
||||
class Blocks(LampadasCollection, model.WModel):
|
||||
pass
|
||||
|
||||
class Block:
|
||||
pass
|
||||
|
||||
class Pages(LampadasCollection, model.WModel):
|
||||
pass
|
||||
|
||||
class Page:
|
||||
pass
|
||||
|
||||
class Sections(LampadasCollection, model.WModel):
|
||||
pass
|
||||
|
||||
class Section:
|
||||
pass
|
||||
|
||||
class Strings(LampadasCollection, model.WModel):
|
||||
pass
|
||||
|
||||
class String:
|
||||
pass
|
||||
|
||||
blocks = Blocks()
|
||||
pages = Pages()
|
||||
sections = Sections()
|
||||
strings = Strings()
|
||||
|
||||
class MBlock(model.WModel):
|
||||
def __init__(self, rowobject):
|
||||
model.WModel.__init__(self)
|
||||
self.rowobject = rowobject
|
||||
self.block_code = rowobject.block_code
|
||||
self.block = rowobject.block
|
||||
|
||||
class VBlock(view.WView):
|
||||
def wvfactory_block_code(self, request, node, model):
|
||||
domhelpers.clearNode(node)
|
||||
return widgets.Text(model)
|
||||
|
||||
def wvfactory_block(self, request, node, model):
|
||||
domhelpers.clearNode(node)
|
||||
return widgets.Text(model)
|
||||
|
||||
def wvfactory_block_items(self, request, node, model):
|
||||
block_object = blocks[self.model.block_code].object
|
||||
build_items(block_object, block_object.block)
|
||||
return widgets.List(block_object.items)
|
||||
|
||||
class CBlock(controller.WController):
|
||||
pass
|
||||
|
||||
view.registerViewForModel(VBlock, MBlock)
|
||||
controller.registerControllerForModel(CBlock, MBlock)
|
||||
|
||||
|
||||
class MPage(model.WModel):
|
||||
def __init__(self, rowobject):
|
||||
model.WModel.__init__(self)
|
||||
self.__dict__.update(rowobject.__dict__)
|
||||
|
||||
class VPage(widgets.Widget):
|
||||
|
||||
templateFile = 'index.xhtml'
|
||||
|
||||
def setUp(self, request, document):
|
||||
pass
|
||||
|
||||
def wvfactory_title(self, request, node, model):
|
||||
page_object = pages[self.model.page_code]
|
||||
build_lang_items(page_object.title, page_object.title)
|
||||
return widgets.List(page_object.title.items[self.lang])
|
||||
|
||||
return I18nTextWidget(model, lang=self.lang)
|
||||
|
||||
def wvfactory_page_code(self, request, node, model):
|
||||
return widgets.Text(model)
|
||||
|
||||
def wvfactory_page(self, request, node, model):
|
||||
return I18nTextWidget(model, lang=self.lang)
|
||||
|
||||
def wvfactory_page_items(self, request, node, model):
|
||||
page_object = pages[self.model.page_code].object
|
||||
build_lang_items(page_object, page_object.page)
|
||||
return widgets.List(page_object.items[self.lang])
|
||||
|
||||
def wvfactory_menu(self, request, node, model):
|
||||
return widgets.List(sections.keys())
|
||||
|
||||
def wvfactory_section_bar(self, request, node, model):
|
||||
return SectionBarWidget()
|
||||
|
||||
class CPage(controller.WController):
|
||||
pass
|
||||
|
||||
view.registerViewForModel(VPage, MPage)
|
||||
controller.registerControllerForModel(CPage, MPage)
|
||||
|
||||
|
||||
class MString(model.WModel):
|
||||
def __init__(self, rowobject):
|
||||
model.WModel.__init__(self)
|
||||
self.__dict__.update(rowobject.__dict__)
|
||||
|
||||
class VString(widgets.Widget):
|
||||
|
||||
templateFile = 'index.xhtml'
|
||||
|
||||
def setUp(self, request, document):
|
||||
pass
|
||||
|
||||
def wvfactory_string_code(self, request, node, model):
|
||||
return widgets.Text(model)
|
||||
|
||||
def wvfactory_string(self, request, node, model):
|
||||
return I18nTextWidget(model, lang=self.lang)
|
||||
|
||||
def wvfactory_string_items(self, request, node, model):
|
||||
string_object = strings[self.model.string_code].object
|
||||
build_lang_items(string_object, string_object.string)
|
||||
return widgets.List(string_object.items[self.lang])
|
||||
|
||||
def wvfactory_version(self, request, node, model):
|
||||
return I18nTextWidget(model, lang=self.lang)
|
||||
|
||||
class CString(controller.WController):
|
||||
pass
|
||||
|
||||
view.registerViewForModel(VString, MString)
|
||||
controller.registerControllerForModel(CString, MString)
|
||||
|
||||
|
||||
class MSection(model.DictionaryModel):
|
||||
def __init__(self, orig, *args, **kwargs):
|
||||
model.Model.__init__(self, *args, **kwargs)
|
||||
model.DictionaryModel.__init__(self, orig)
|
||||
|
||||
class VSection(widgets.Widget):
|
||||
def wvfactory_title(self, request, node, model):
|
||||
return widgets.List(model)
|
||||
|
||||
class CSection(controller.WController):
|
||||
pass
|
||||
|
||||
view.registerViewForModel(VSection, MSection)
|
||||
controller.registerControllerForModel(CSection, MSection)
|
||||
|
||||
|
||||
class MList(model.ListModel):
|
||||
def __init__(self, orig, *args, **kwargs):
|
||||
model.Model.__init__(self, *args, **kwargs)
|
||||
model.ListModel.__init__(self, orig)
|
||||
|
||||
class VList(widgets.Widget):
|
||||
def wvfactory_list(self, request, node, model):
|
||||
#domhelpers.clearNode(node)
|
||||
return widgets.List(model)
|
||||
|
||||
class CList(controller.WController):
|
||||
pass
|
||||
|
||||
view.registerViewForModel(VList, MList)
|
||||
controller.registerControllerForModel(CList, MList)
|
||||
|
||||
|
||||
class Options(usage.Options):
|
||||
optParameters = [["port", "p", 8080,
|
||||
"Port to listen with Webserver"]]
|
||||
|
||||
class WidgetPage(twisted.web.widgets.WidgetPage):
|
||||
template = '<html><head></head><body>%%%%self.widget%%%%</body></html>'
|
||||
|
||||
class Gadget(twisted.web.widgets.Gadget):
|
||||
def __init__(self):
|
||||
twisted.web.widgets.Gadget.__init__(self)
|
||||
self.tables_loaded = 0
|
||||
self.pageFactory = WidgetPage
|
||||
object_server.connect(self.connected)
|
||||
|
||||
def connected(self, message):
|
||||
object_server.section.get_all(self.loaded_sections)
|
||||
object_server.string.get_all(self.loaded_strings)
|
||||
object_server.block.get_all(self.loaded_blocks)
|
||||
|
||||
def loaded_blocks(self, blockrows):
|
||||
for blockrow in blockrows:
|
||||
block_object = Block()
|
||||
block_model = MBlock(blockrow)
|
||||
block_view = VBlock(block_model)
|
||||
block_controller = CBlock(block_model)
|
||||
block_controller.setView(block_view)
|
||||
block_mvc = MVC(blockrow, block_object, block_model, block_view, block_controller)
|
||||
blocks[blockrow.block_code] = block_mvc
|
||||
print 'Blocks loaded.'
|
||||
self.tables_loaded += 1
|
||||
if self.tables_loaded==3:
|
||||
self.load_pages()
|
||||
|
||||
def load_pages(self):
|
||||
object_server.page.get_all(self.loaded_pages)
|
||||
|
||||
def loaded_pages(self, pagerows):
|
||||
for pagerow in pagerows:
|
||||
page_object = Page()
|
||||
page_model = MPage(pagerow)
|
||||
page_view = VPage(page_model)
|
||||
page_controller = CPage(page_model)
|
||||
page_controller.setView(page_view)
|
||||
page_mvc = MVC(pagerow, page_object, page_model, page_view, page_controller)
|
||||
pages[pagerow.page_code] = page_mvc
|
||||
print 'Pages loaded.'
|
||||
|
||||
def loaded_sections(self, sectionrows):
|
||||
for sectionrow in sectionrows:
|
||||
section_object = Section()
|
||||
section_model = MSection(sectionrow)
|
||||
section_view = VSection(section_model)
|
||||
section_controller = CSection(section_model)
|
||||
section_controller.setView(section_view)
|
||||
section_mvc = MVC(sectionrow, section_object, section_model, section_view, section_controller)
|
||||
sections[sectionrow.section_code] = section_mvc
|
||||
print 'Sections loaded.'
|
||||
self.tables_loaded += 1
|
||||
if self.tables_loaded==3:
|
||||
self.load_pages()
|
||||
|
||||
def loaded_strings(self, stringrows):
|
||||
for stringrow in stringrows:
|
||||
string_object = String()
|
||||
string_model = MString(stringrow)
|
||||
string_view = VString(string_model)
|
||||
string_controller = CString(string_model)
|
||||
string_controller.setView(string_view)
|
||||
string_mvc = MVC(stringrow, string_object, string_model, string_view, string_controller)
|
||||
strings[stringrow.string_code] = string_mvc
|
||||
print 'Strings loaded.'
|
||||
self.tables_loaded += 1
|
||||
if self.tables_loaded==3:
|
||||
self.load_pages()
|
||||
|
||||
def getChild(self, path, request):
|
||||
state.uri = URI(request.path)
|
||||
if pages.has_key(state.uri.page_code):
|
||||
resource = pages[state.uri.page_code].view
|
||||
else:
|
||||
resource = pages['404'].view
|
||||
resource.lang = state.uri.lang
|
||||
return resource
|
||||
|
||||
def updateApplication(app, config):
|
||||
port = config['port']
|
||||
root = Gadget()
|
||||
site = server.Site(root)
|
||||
app.listenTCP(port, site)
|
||||
|
||||
root = Gadget()
|
||||
site = server.Site(root)
|
||||
|
Loading…
Reference in New Issue