Mercurial > hg > TagInTheMiddle
changeset 2:1182315b18ac
add rudimentary code for handlers
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 04 May 2010 19:15:21 -0700 |
parents | 837cfc05d4d9 |
children | c2bb8f873aee |
files | taginthemiddle/handlers.py taginthemiddle/middleware.py taginthemiddle/model.py |
diffstat | 3 files changed, 46 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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'])
--- 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()
--- 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()