# HG changeset patch # User Tero Marttila # Date 1234034470 -7200 # Node ID 71ab68f31a1c98e5361d2da6f72dfc2f5dafce87 # Parent 82df0bb66ca765cd22041ef5959b6bfcde75ba3a the handlers work now diff -r 82df0bb66ca7 -r 71ab68f31a1c lib/template.py --- a/lib/template.py Sat Feb 07 21:02:33 2009 +0200 +++ b/lib/template.py Sat Feb 07 21:21:10 2009 +0200 @@ -79,13 +79,20 @@ except : raise TemplateError("Template broken: %r" % (name, ), status='500 Internal Server Error', details=exceptions.text_error_template().render()) - def render (name, **params) : + def render (self, name, **params) : """ Render a template, using lookup() on the given name """ return render(self.lookup(name), **params) + def render_to_response (self, name, **params) : + """ + Render a template, returning a http.Response object + """ + + return http.Response(self.render(name, **params)) + @classmethod def load (cls, path) : """ diff -r 82df0bb66ca7 -r 71ab68f31a1c sites/irclogs.qmsk.net/__init__.py --- a/sites/irclogs.qmsk.net/__init__.py Sat Feb 07 21:02:33 2009 +0200 +++ b/sites/irclogs.qmsk.net/__init__.py Sat Feb 07 21:21:10 2009 +0200 @@ -6,5 +6,5 @@ import urls # our RequestHandler -handler = urls.build_mapper() +handler = urls.mapper diff -r 82df0bb66ca7 -r 71ab68f31a1c sites/irclogs.qmsk.net/handlers.py --- a/sites/irclogs.qmsk.net/handlers.py Sat Feb 07 21:02:33 2009 +0200 +++ b/sites/irclogs.qmsk.net/handlers.py Sat Feb 07 21:21:10 2009 +0200 @@ -2,18 +2,26 @@ Our URL action handlers """ +from lib import template + +templates = template.TemplateLoader("sites/irclogs.qmsk.net/templates") + def index (request) : """ The topmost index page, display a list of available channels, perhaps some general stats """ - - pass + + return templates.render_to_response("index") def channel_view (request, channel) : """ The main channel view page, display the most important info, and all requisite links """ + return templates.render_to_response("channel", + channel_name = channel, + ) + pass def channel_last (request, channel, lines, type) : diff -r 82df0bb66ca7 -r 71ab68f31a1c sites/irclogs.qmsk.net/templates/channel.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sites/irclogs.qmsk.net/templates/channel.tmpl Sat Feb 07 21:21:10 2009 +0200 @@ -0,0 +1,2 @@ +

Channel ${channel_name}

+ diff -r 82df0bb66ca7 -r 71ab68f31a1c sites/irclogs.qmsk.net/urltree.py --- a/sites/irclogs.qmsk.net/urltree.py Sat Feb 07 21:02:33 2009 +0200 +++ b/sites/irclogs.qmsk.net/urltree.py Sat Feb 07 21:21:10 2009 +0200 @@ -263,7 +263,7 @@ """ # start with the defaults - kwargs = self.defaults() + kwargs = self.defaults.copy() # then add all the values for label_value in label_values : @@ -403,7 +403,7 @@ # found something? if not match : - raise URLError("No child found for label") + raise URLError("No child found for label: %s + %s + %s" % (self.get_url(), label, '/'.join(str(l) for l in label_path))) # ok, recurse into the match url, label_value = match.match(label_path) @@ -414,7 +414,30 @@ # return the match return url, label_value - + + def get_url (self) : + """ + Returns the URL for this node, by iterating over our parents + """ + + # URL segments in reverse order + segments = [''] + + # start with ourself + node = self + + # iterate up to root + while node : + segments.append(str(node.label)) + + node = node.parent + + # reverse + segments.reverse() + + # return + return '/'.join(segments) + def dump (self, indent=0) : """ Returns a multi-line string representation of this Node @@ -470,15 +493,13 @@ Returns an (URL, [LabelValue]) tuple. """ - # normalize the URL - url = os.path.normpath(url) - # split it into labels path = url.split('/') - - # ensure that it starts with a / - root_label = path.pop(0) - assert self.root.label.match(root_label), "URL must begin with root" + + # empty URL is empty + if url : + # ensure that it doesn't start with a / + assert not self.root.label.match(path[0]), "URL must not begin with root" # just match starting at root return self.root.match(path) @@ -488,10 +509,13 @@ Looks up the request's URL, and invokes its handler """ - # get the request's URL path - url, label_values = self.match(request.get_page_name()) + # get the requested URL + request_url = request.get_page_name() + + # find the URL+values to use + url, label_values = self.match(request_url) # let the URL handle it - url.execute(request, label_values) + return url.execute(request, label_values)