changeset 4905:6e313bdf6b69 routing

routing: Add new roundup.web namespace with router component This branch is to untangle hardcoded Roundup URL scheme, make it more readable and customizable with extensions. Right now it doesn't seem possible to write extension that renders static HTML page at /about without modifying Roundup DB, and this web component should not depend on DB schema.
author anatoly techtonik <techtonik@gmail.com>
date Tue, 15 Jul 2014 13:33:43 +0300
parents 3b632a25b1b3
children b860ede03056
files roundup/web/NOTES.md roundup/web/router.py
diffstat 2 files changed, 80 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roundup/web/NOTES.md	Tue Jul 15 13:33:43 2014 +0300
@@ -0,0 +1,48 @@
+
+Engineering notes for Roundup components for web.
+
+
+### Logical structure of web components
+
+An attempt to see what components are present in
+web request processing.
+
+    +-----------+
+    |           |
+    | Router    |
+    └─----------+                     (pure logic)
+    ----------------------------------------------
+    +-----------+    
+    |           |    
+    | Login     |    
+    └-----------+   (logic + templates + messages)
+    ----------------------------------------------
+    +-----------+
+    ¦           ¦
+    ¦ User DB   ¦
+    └-----------+                       (messages)
+
+
+Every component consists of messages (data), logic
+(code) and representation (templates). Message
+definition (data) also takes into account actions
+that make component work. Templates are mostly
+needed for human readability. 
+
+
+### Router
+
+Status for Roundup URL map check:
+
+    [ ] urlmap component
+
+    /_file/(.*) 
+      StaticFileHandler
+       [ ] /_file
+       [ ] /_file/
+       [ ] /_file/name
+    /@@file/(.*)
+      StaticFileHandler
+       [ ] /@@file
+       [ ] /@@file/
+       [ ] /@@file/name
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roundup/web/router.py	Tue Jul 15 13:33:43 2014 +0300
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+"""
+The purpose of router is to make Roundup URL scheme configurable
+and allow extensions add their own handlers and URLs to tracker.
+
+Public domain work by:
+  anatoly techtonik <techtonik@gmail.com>
+"""
+
+import re
+
+
+class Router(object):
+
+    def __init__(self, urlmap=[]):
+        """
+        `urlmap` is a list (pattern, handler, pattern, ...)
+        """
+        self.urlmap = urlmap
+
+    def get_handler(self, urlpath):
+        """
+        `urlpath` is a part of url /that/looks?like=this
+
+        returns tuple (handler, arguments) or (None, ())
+        """
+        for i in range(0, len(self.urlmap), 2):
+            pattern, handler = self.urlmap[i], self.urlmap[i+1]
+            match = re.match(pattern, urlpath)
+            if match:
+                return handler, match.groups()
+        return (None, ())

Roundup Issue Tracker: http://roundup-tracker.org/