# HG changeset patch # User k0s # Date 1256966126 14400 # Node ID e37d117a9deb0de36512e47684209fdcd4cba195 # Parent 62c961bb91e690861c64a0499ab0babfe96ac8bb preferences form now works diff -r 62c961bb91e6 -r e37d117a9deb bitsyblog/bitsyblog.py --- a/bitsyblog/bitsyblog.py Sat Oct 31 00:30:47 2009 -0400 +++ b/bitsyblog/bitsyblog.py Sat Oct 31 01:15:26 2009 -0400 @@ -255,6 +255,12 @@ """ write a blog entry and other POST requests """ + + # GENSHI: data dictionary + request.environ['data'] = { 'site_name': self.site_name, + 'request': request, + 'link': self.link, + 'logo': self.logo(request) } # find user + path user, path = self.userpath(request) @@ -797,56 +803,31 @@ template = self.loader.load('post.html') return template.generate(**data).render() - def preferences_form(self, request, user): - prefs = request.user.settings - form = Form() - - # date format - format = prefs.get('Date format', self.date_format) - value = datetime.datetime.now().strftime(format) - form.add_element('textfield', 'Date format', value=value, - help='how to display dates in your blog post subject') - - # subject - subject = prefs.get('Subject', self.subject) - subject = subject.split('%(date)s', 1) - func = lambda name: value - form.add_elements('Subject', - ['textfield', func, 'textfield' ], - [ (), (), ()], # this is horrible! - [ dict(value=subject[0]), - {}, - dict(value=subject[1]) ], - help='how to display the subject line of your blog post' - ) - - # CSS files - css_files = [ i['name'] for i in prefs['CSS'] ] - form.add_element('menu', 'Stylesheet', css_files, - help='which CSS file should be the default') - - # or upload a CSS file - form.add_element('file_upload', 'CSS file', - help='upload a CSS file to theme your webpage') - - # Friends -- can see secret posts - users = [ i for i in list(self.users.users()) - if i != user ] - if users: - users.sort(key=str.lower) - form.add_element('checkboxes', 'Friends', - users, prefs.get('Friends', set()), - help='friends can see your secret posts') - - return form def preferences(self, request, user, errors=None, message=None): """user preferences form""" - body = self.preferences_form(request, user)(errors) - if message: - body = '%s\n%s' % ( markup.p(markup.strong(message)), body ) - return self.render(request, body, title='preferences') - + + # genshi data + self.site_nav(request) + data = request.environ['data'] + data['user'] = user + data['stylesheets'] = self.stylesheets(request) + + # form data + prefs = request.user.settings + data['date_format'] = prefs.get('Date format', self.date_format) + data['now'] = datetime.datetime.now().strftime(data['date_format']) + subject = prefs.get('Subject', self.subject) + data['subject'] = subject.split('%(date)s', 1) + data['css_files'] = [ i['name'] for i in prefs['CSS' ] ] + data['users'] = [ i for i in list(self.users.users()) + if i != user ] + data['message'] = message + + # render the template + template = self.loader.load('preferences.html') + return template.generate(**data).render() + class BitsierBlog(BitsyBlog): """single user version of bitsyblog""" diff -r 62c961bb91e6 -r e37d117a9deb bitsyblog/templates/post.html --- a/bitsyblog/templates/post.html Sat Oct 31 00:30:47 2009 -0400 +++ b/bitsyblog/templates/post.html Sat Oct 31 01:15:26 2009 -0400 @@ -6,7 +6,12 @@ xmlns:xi="http://www.w3.org/2001/XInclude"> post - ${user} - + + + diff -r 62c961bb91e6 -r e37d117a9deb bitsyblog/templates/preferences.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bitsyblog/templates/preferences.html Sat Oct 31 01:15:26 2009 -0400 @@ -0,0 +1,79 @@ + + + + + preferences - ${user} + + + + + + + + + + + +
+ ${message} +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ Date format: + + +
+ Subject: + + ${now} + +
+ Stylesheet: + + +
CSS file:
Friends: + + ${_user}
+
+
+ + + +
+ +