Mercurial > hg > bitsyblog
changeset 17:e5cbc53cacf8
now have stylesheets
author | k0s <k0scist@gmail.com> |
---|---|
date | Sun, 25 Oct 2009 18:35:48 -0400 |
parents | 2bd6b2b543dc |
children | c293bcbe6e03 |
files | bitsyblog/bitsyblog.py bitsyblog/templates/blog.html bitsyblog/user.py |
diffstat | 3 files changed, 23 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py Sun Oct 25 18:11:25 2009 -0400 +++ b/bitsyblog/bitsyblog.py Sun Oct 25 18:35:48 2009 -0400 @@ -511,9 +511,8 @@ def render(self, request, body, title=None, feedtitle=None): """layout the page in a unified way""" - stylesheets = () + _title = [ self.site_name ] user = getattr(request, 'user', None) - _title = [ self.site_name ] if user: stylesheets = request.user['CSS'] stylesheets = [ (("/%s" % self.user_url(request, user.name, 'css', css['filename'])), @@ -533,6 +532,17 @@ 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: + stylesheets = request.user['CSS'] + stylesheets = [ (self.user_url(request, user.name, 'css', css['filename']), + css['name']) for css in stylesheets ] + else: + stylesheets = [(self.link(request, "css/site.css"), "Default")] + return stylesheets + + def site_nav(self, request): """returns HTML for site navigation""" @@ -605,44 +615,6 @@ print >> retval, '</div>' return retval.getvalue() -# def blog_entry(self, request, user, entry): -# """given the content string, return a marked-up blog entry""" -# # XXX no need to pass user - -# # user preferences -# prefs = request.user.settings -# format = prefs.get('Date format', self.date_format) -# subject = prefs.get('Subject', self.subject) - -# role = self.role(user, request) - -# subject = subject % { 'date' : entry.date.strftime(format) } -# subject = cgi.escape(subject) -# html = StringIO() -# blog_id = entry.datestamp() -# print >> html, '<div id="%s" class="blog-entry">' % blog_id -# print >> html, '<a name="%s" />' % blog_id -# print >> html, '<div class="subject">' -# print >> html, '<a href="/%s">%s</a>' % (self.user_url(request, user, blog_id), subject) -# if (entry.privacy == 'secret') and (role == 'friend'): -# print >> html, '<em>secret</em>' -# print >> html, '</div>' -# print >> html, self.cooker(entry.body) - -# if role == 'author': -# print >> html, '<div><form action="/%s" method="post">' % self.user_url(request, entry.user, blog_id) -# print >> html, self.privacy_settings(entry.privacy) -# print >> html, '<input type="submit" name="submit" value="Change Privacy" />' -# print >> html, '</form></div>' -# if entry.privacy != 'public': -# title = "You can give this URL so people may see this %s post without logging in" % entry.privacy -# print >> html, '<div>' -# print >> html, '<span title="%s">Mangled URL:</span>' % title -# print >> html, markup.link(self.mangledurl(request, entry)) -# print >> html, '</div>' - -# print >> html, '</div>' -# return html.getvalue() def write_blog(self, user, blog, path, n_links, request): """return the user's blog in HTML""" @@ -662,7 +634,7 @@ data = request.environ['data'] data['user'] = user data['role'] = self.role(user, request) - data['stylesheets'] = () # TODO + 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 @@ -675,22 +647,10 @@ # render the template template = self.loader.load('blog.html') return template.generate(**data).render() - -# # XXX no need to pass path or user! -# retval = StringIO() -# print >> retval, self.navigation(user, blog, path, n_links, 0) -# for entry in blog: -# print >> retval, self.blog_entry(request, user, entry) -# feedtitle=None -# if request.path_info.strip('/') == user: -# feedtitle = "%s's blog" % user -# title = None -# if len(blog) == 1: -# format = request.user.settings.get('Date format', self.date_format) -# title = blog[0].date.strftime(format) -# return self.render(request, retval.getvalue(), title=title, feedtitle=feedtitle) def restructuredText(self, string): + """renders a string with restructured text""" + origstring = string settings = { 'report_level': 5 } string = string.strip()
--- a/bitsyblog/templates/blog.html Sun Oct 25 18:11:25 2009 -0400 +++ b/bitsyblog/templates/blog.html Sun Oct 25 18:35:48 2009 -0400 @@ -8,11 +8,11 @@ <head> <title>${user} - ${site_name}</title> - <py:for each="index, sheet in enumerate(stylesheets)"> - <link href="${link(request, ('css', sheet))}" + <py:for each="index, (href, sheet) in enumerate(stylesheets)"> + <link href="${href}" type="text/css" rel="${index and 'alternate stylesheet' or 'stylesheet'}" - title="sheet.rsplit('.', 1)[0]"/> + title="${sheet}"/> </py:for> </head> @@ -28,7 +28,7 @@ <ul> <li py:for="index in range(_n_links)" py:with="synopsis = blog[index].title()"> - <a href="#${blog[index].datestamp()}">${blog[index].date.strftime(date_format)}</a><py:if test="synopsis">: ${escape(synopsis)}</py:if> + <a href="#${blog[index].datestamp()}">${blog[index].date.strftime(date_format)}</a><py:if test="synopsis">: ${synopsis}</py:if> </li> </ul> <a py:if="_n_links != len(blog)" href="${request.path}?n=all">more</a>
--- a/bitsyblog/user.py Sun Oct 25 18:11:25 2009 -0400 +++ b/bitsyblog/user.py Sun Oct 25 18:35:48 2009 -0400 @@ -97,9 +97,10 @@ css_files.insert(0, css_files.pop(index)) except ValueError: pass - return [ dict(filename=i, name=i.rsplit('.css',1)[0], - css=file(os.path.join(css_dir, i)).read()) - for i in css_files ] + retval = [ dict(filename=i, name=i.rsplit('.css',1)[0], + css=file(os.path.join(css_dir, i)).read()) + for i in css_files ] + return retval ### interfaces for BitsyUsers