# HG changeset patch # User k0s # Date 1257053303 14400 # Node ID 4ac11f7992c6390a3e78653447d332d05ea6e0e7 # Parent 9be583a7731d0234013192bb1385ec22b603c42d index page now works and so does rss diff -r 9be583a7731d -r 4ac11f7992c6 bitsyblog/bitsyblog.py --- a/bitsyblog/bitsyblog.py Sat Oct 31 23:30:45 2009 -0400 +++ b/bitsyblog/bitsyblog.py Sun Nov 01 01:28:23 2009 -0400 @@ -102,7 +102,8 @@ request.environ['data'] = { 'site_name': self.site_name, 'request': request, 'link': self.link, - 'logo': self.logo(request) } + 'logo': self.logo(request), + 'user_url': self.user_url } res = self.response_functions.get(request.method, self.error())(request) return res(environ, start_response) @@ -226,9 +227,6 @@ blog = list(reversed(blog)) n_links = self.number_of_links(request, user) - # don't display navigation for short blogs - if len(blog) < 2: - n_links = 0 # write the blog content = self.write_blog(user, blog, request.path_info, n_links, request) @@ -519,29 +517,6 @@ ### methods that write HTML - def render(self, request, body, title=None, feedtitle=None): - """layout the page in a unified way""" - _title = [ self.site_name ] - user = getattr(request, 'user', None) - if user: - stylesheets = request.user['CSS'] - stylesheets = [ (("/%s" % self.user_url(request, user.name, 'css', css['filename'])), - css['name']) for css in stylesheets ] - _title.insert(0, request.user.name) - else: - stylesheets = (("/css/site.css", "Default"),) - - if title: - _title.insert(0, title) - - title = ' - '.join(_title) - head_markup = () - if feedtitle: - head_markup = ( '' % feedtitle, - '' % feedtitle,) - - return markup.wrap(self.site_nav(request)+body, title, stylesheets, head_markup=head_markup) - def stylesheets(self, request): user = getattr(request, 'user', None) if user: @@ -575,61 +550,28 @@ def index(self, request, n_links): data = request.environ['data'] + data['n_links'] = n_links self.site_nav(request) + + # get the blogs + blogs = {} + for user in self.users: + blog = self.blog(user, ('public',), n_links) + if blog: + blogs[user] = blog + users = blogs.keys() + + # display latest active user first + users.sort(key=lambda user: blogs[user][0].date, reverse=True) + + data['blogs'] = blogs + data['users'] = users + data['date_formats'] = dict([(user, self.users[user].settings.get('Date format', self.date_format)) for user in users]) + + # render the template template = self.loader.load('index.html') return template.generate(**request.environ['data']).render() -# retval = StringIO() -# print >> retval, '

bitsyblog

' - -# # get the blogs -# blogs = {} -# for user in self.users: -# blog = self.blog(user, ('public',), n_links) -# if blog: -# blogs[user] = blog -# users = blogs.keys() - -# # display latest active user first -# users.sort(key=lambda user: blogs[user][0].date, reverse=True) - -# # display users' blogs -# for user in users: -# print >> retval, '
' % user -# print >> retval, '%s' % (user, user) -# blog = blogs[user] -# print >> retval, self.navigation(user, blog, '/%s' % user, n_links) -# print >> retval, '
' - -# return self.render(request, retval.getvalue(), feedtitle=self.site_name) - - def navigation(self, user, blog, path, n_links, n_char=80): - prefs = self.users[user].settings - - if n_links == 0 or not len(blog): - return '' - retval = StringIO() - print >> retval, '' - return retval.getvalue() - def write_blog(self, user, blog, path, n_links, request): """return the user's blog in HTML""" @@ -652,7 +594,6 @@ data['stylesheets'] = self.stylesheets(request) data['subject'] = request.user.settings.get('Subject', self.subject) data['date_format'] = request.user.settings.get('Date format', self.date_format) - data['user_url'] = self.user_url data['mangledurl'] = self.mangledurl # blog data @@ -739,11 +680,12 @@ subject = prefs.get('Subject', self.subject) date_format = prefs.get('Date format', self.date_format) title = entry.title() - return PyRSS2Gen.RSSItem(title=title, #subject % { 'date': entry.date.strftime(date_format) }, - link=self.permalink(entry), + link = self.permalink(request, entry) + return PyRSS2Gen.RSSItem(title=title, + link=link, description=unicode(entry.body, errors='replace'), author=user, - guid=PyRSS2Gen.Guid(self.permalink(entry)), + guid=PyRSS2Gen.Guid(link), pubDate=entry.date) @@ -791,7 +733,6 @@ data = request.environ['data'] data['user'] = user data['stylesheets'] = self.stylesheets(request) - data['user_url'] = self.user_url # render the template template = self.loader.load('post.html') diff -r 9be583a7731d -r 4ac11f7992c6 bitsyblog/templates/blog.html --- a/bitsyblog/templates/blog.html Sat Oct 31 23:30:45 2009 -0400 +++ b/bitsyblog/templates/blog.html Sun Nov 01 01:28:23 2009 -0400 @@ -24,7 +24,7 @@