# HG changeset patch # User Jeff Hammel # Date 1273025721 25200 # Node ID 1182315b18acbe80cc632e7af3a6468eb14094b7 # Parent 837cfc05d4d9abd50bdf3545a51dd954298cfb82 add rudimentary code for handlers diff -r 837cfc05d4d9 -r 1182315b18ac taginthemiddle/handlers.py --- a/taginthemiddle/handlers.py Tue May 04 18:46:05 2010 -0700 +++ b/taginthemiddle/handlers.py Tue May 04 19:15:21 2010 -0700 @@ -70,16 +70,51 @@ methods = set(['GET']) @classmethod - def match( + def match(cls, app, request): + + # check the method + if request.method not in cls.methods: + return None + + # check the path + if request.path_info.endswith('/%s' % app.tags_url): + try: + return cls(app, request) + except HandlerMatchException: + return None + class ViewTags(GenshiHandler): # TODO: RSS template = 'tags.html' methods = set(['GET']) + def __init__(self, app, request): + GenshiHandler.__init__(self, app, request) + path = request.path_info.split('/') + try: + index = path.find(app.tags_url) + except ValueError: + raise HandlerMatchException + self.tags = path[index+1:] + if not self.tags: + raise HandlerMatchException + + @classmethod def match(cls, app, request): - pass - + # check the method + if request.method not in cls.methods: + return None + + try: + return cls(app, request) + except HandlerMatchException: + return None + + def Get(self): + if self.request.GET.get('format') == 'rss': + pass # TODO + return GenshiHandler.Get(self) class PostTags(Handler): methods = set(['POST']) diff -r 837cfc05d4d9 -r 1182315b18ac taginthemiddle/middleware.py --- a/taginthemiddle/middleware.py Tue May 04 18:46:05 2010 -0700 +++ b/taginthemiddle/middleware.py Tue May 04 19:15:21 2010 -0700 @@ -5,7 +5,7 @@ import os -from handlers import Index +from handlers import TagCloud, ViewTags, PostTags from model import Tags from genshi.template import TemplateLoader @@ -21,8 +21,9 @@ 'template_dirs': '', 'patterns': '*' 'tags_file': None, - 'url': 'tags' - 'post_url': '.tags' + 'tags_url': 'tags', + 'post_url': '.tags', + 'author': None, # for RSS } def __init__(self, app, **kw): @@ -33,11 +34,11 @@ setattr(self, key, kw.get(key, self.defaults[key])) self.auto_reload = self.auto_reload.lower() == 'true' assert self.tags_file is not None - self.tags + self.tags = Tags(self.tags_file) self.patterns = self.patterns.strip().split() # request handlers - self.handlers = [ Cloud ] + self.handlers = [ TagCloud, ViewTags, PostTags ] # template loader self.template_dirs = self.template_dirs.split() diff -r 837cfc05d4d9 -r 1182315b18ac taginthemiddle/model.py --- a/taginthemiddle/model.py Tue May 04 18:46:05 2010 -0700 +++ b/taginthemiddle/model.py Tue May 04 19:15:21 2010 -0700 @@ -2,6 +2,7 @@ tags have: - a list of resources they're applied to - a time they're applied + - for multi-user tags, the author should be passed (fudge for now) for now just assume auth is on and that anyone authenticated may tag e.g. a tags file @@ -63,4 +64,5 @@ return self.tags[tag].remove(url) self.urls[url].remove(tag) + del self.times[(tag, url)] self.write()