comparison commentator/middleware.py @ 3:d0d8524d9495

finish basic API...still doesnt expire results correctly
author k0s <k0scist@gmail.com>
date Fri, 26 Feb 2010 11:06:48 -0500
parents 689b9d928dc8
children 451169e51935
comparison
equal deleted inserted replaced
2:689b9d928dc8 3:d0d8524d9495
95 95
96 # make string template of the groups 96 # make string template of the groups
97 groups_dict = dict([(str(index+1), value) 97 groups_dict = dict([(str(index+1), value)
98 for index, value in enumerate(url_match.groups())]) 98 for index, value in enumerate(url_match.groups())])
99 99
100 last_modified = None
100 for element in tree.findall(self.xpath_pattern): 101 for element in tree.findall(self.xpath_pattern):
101 102
102 # get url 103 # get url
103 str_dict = groups_dict.copy() 104 str_dict = groups_dict.copy()
104 for key in element.keys(): 105 for key in element.keys():
105 str_dict[key] = element.get(key) 106 str_dict[key] = element.get(key)
106 uri = self.mapping.substitute(str_dict) 107 uri = self.mapping.substitute(str_dict)
107 108
108 # get comments
109 # TODO
110
111 # genshi data 109 # genshi data
112 data = {} 110 data = {}
113 data['comments'] = self.model.comments(uri) 111 data['comments'] = self.model.comments(uri)
112 if data['comments']:
113 last_modified = data['comments'][-1]['date']
114 data['action'] = '%s/%s' % (uri, self.url) 114 data['action'] = '%s/%s' % (uri, self.url)
115 data['date_format'] = self.date_format 115 data['date_format'] = self.date_format
116 data['request'] = request 116 data['request'] = request
117 117
118 # render template 118 # render template
119 template = self.loader.load(self.template) 119 template = self.loader.load(self.template)
120 comments = template.generate(**data).render() 120 comments = template.generate(**data).render()
121 comments = etree.fromstring(comments) 121 comments = etree.fromstring(comments)
122 element.append(comments) 122 element.append(comments)
123 123
124 if last_modified:
125 import pdb; pdb.set_trace()
124 return tree 126 return tree