Example #1
0
File: nextbus.py Project: ctb/meep
class RootDirectory(Directory):

    _q_exports = ['', 'get_next_bus', 'html']

    html = StaticDirectory(os.path.abspath('./html'))

    def _q_index(self):
        request = quixote.get_request()
        return quixote.redirect('./html/index.html')

    def get_next_bus(self):
        request = quixote.get_request()
        response = quixote.get_response()
        response.set_content_type('application/json')
        form = request.form

        #return """{"route_num": "22", "stop_number": 2586, "route_name": "HASLETT-MERIDIAN MALL-MSU", "time": "6:17a"}"""

        lat = form['lat']
        lon = form['lon']
        stop_number = get_closest_stop(lat, lon)
        data = get_next_bus_time(stop_number)
        data['stop_number'] = stop_number

        x = json.dumps(data)
        return x
Example #2
0
    def __init__(self, coord, push_list=[]):
        self.coord = coord            # PonyBuildCoordinator w/results etc.

        # get notified of new results by the coordinator...
        self.coord.add_listener(self)

        if push_list:
            print '** PuSH servers:', push_list
        else:
            print '** PuSH disabled'
        self.push_list = list(push_list)
        self.rss2 = RSS2FeedDirectory(coord)
        self.p = PackageDirectory(coord)
        self.img = StaticDirectory(os.path.join(templatesdir, 'img'))
        self.css = StaticFile(os.path.join(templatesdir, 'style.css'))
Example #3
0
class Root(Directory):
    """ This is the application root.
    """
    _q_exports = [
        '', 'static', 'connect', 'disconnect', 'create_channel', 'subscribe',
        'unsubscribe', 'publish'
    ]

    static = StaticDirectory(os.path.join(os.getcwd(), 'static'))

    def _q_index(self):
        # serve the index.html at /
        p = os.path.join(os.getcwd(), 'index.html')
        index = StaticFile(path=p, mime_type="text/html")
        return index()

    def connect(self):
        # accept all connect requests and assume they are from 'guest'
        return json.dumps([True, {"name": "guest"}])

    def disconnect(self):
        return [True, {}]

    def create_channel(self):
        # accept all create channel requests. in this example,
        # only one channel is ever created: 'chan1'
        return json.dumps([
            True, {
                "history_size": 0,
                "reflective": True,
                "presenceful": True
            }
        ])

    def subscribe(self):
        return json.dumps([True, {}])

    def unsubscribe(self):
        return json.dumps([True, {}])

    def publish(self):
        return json.dumps([True, {}])
Example #4
0
class DatabaseNamespace(UI):
    _q_exports = ["_q_index", "main", "dumpreq", "srcdir"]

    srcdir = StaticDirectory(curdir, list_directory=1)

    ## 	def __init__ (self, db):
    ## 		UI.__init__(self,db)
    # self.db = db

    def _q_index(self, request):
        body = """This is the main menu. Hello world!"""
        for (name, mb) in self.getMainWindow().getMenuBars().items():
            body += self.renderMenuBar(mb)
        return wholepage(self.db.getLabel(), body)

    def _q_lookup(self, request, name):
        name = name.upper()
        try:
            table = self.db.tables[name]
        except KeyError, e:
            raise TraversalError("No table named '%s'" % name)
        #rpt = table.report()
        return TableNamespace(table)
Example #5
0
 def __call__(self, req):
     return StaticDirectory.__call__(self)
Example #6
0
 def _q_lookup(self, req, name):
     return StaticDirectory._q_lookup(self, name)
Example #7
0
 def _q_index(self, req):
     return StaticDirectory._q_index(self)
Example #8
0

def error(request):
    raise ValueError, "this is a Python exception"


def publish_error(request):
    raise PublishError(public_msg="Publishing error raised by publish_error")


def _q_lookup(request, component):
    return IntegerUI(request, component)


def _q_resolve(component):
    # _q_resolve() is a hook that can be used to import only
    # when it's actually accessed.  This can be used to make
    # start-up of your application faster, because it doesn't have
    # to import every single module when it starts running.
    if component == 'form_demo':
        from quixote.demo.forms import form_demo
        return form_demo


# Get current directory
import os
from quixote.demo import forms
curdir = os.path.dirname(forms.__file__)
srcdir = StaticDirectory(curdir, list_directory=1)
q_ico = StaticFile(os.path.join(curdir, 'q.ico'))
Example #9
0
 def _q_resolve(self, name):
     if name == "static":
         return StaticDirectory(get_publisher().context.app_options.get(
             "server", "static_content"))