changeset 26:e37d117a9deb

preferences form now works
author k0s <k0scist@gmail.com>
date Sat, 31 Oct 2009 01:15:26 -0400
parents 62c961bb91e6
children 4101fdb16ab2
files bitsyblog/bitsyblog.py bitsyblog/templates/post.html bitsyblog/templates/preferences.html
diffstat 3 files changed, 113 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- 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"""
--- 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">
   <head>
     <title>post - ${user}</title>
-<!--    <link href="${link(request, 'css/site.css')}" type="text/css" rel="stylsheet" title="Default"/> -->
+    <py:for each="index, (href, sheet) in enumerate(stylesheets)">
+      <link href="${href}"
+            type="text/css" 
+            rel="${index and 'alternate stylesheet' or 'stylesheet'}"
+            title="${sheet}"/>
+    </py:for>
   </head>
   <body>
     <xi:include href="navigation.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 @@
+<!DOCTYPE html
+    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:py="http://genshi.edgewall.org/"
+      xmlns:xi="http://www.w3.org/2001/XInclude">
+
+  <head>
+    <title>preferences - ${user}</title>
+
+    <py:for each="index, (href, sheet) in enumerate(stylesheets)">
+      <link href="${href}"
+            type="text/css" 
+            rel="${index and 'alternate stylesheet' or 'stylesheet'}"
+            title="${sheet}"/>
+    </py:for>
+
+  </head>
+
+  <body>
+    
+    <xi:include href="navigation.html" />
+
+    <div py:if="message">
+      <strong>${message}</strong>
+    </div>
+
+    <form method="post" enctype="multipart/form-data">
+      <table>
+        <tr>
+          <td>
+            <span title="how to display dates in your blog post subject"><strong>Date format:</strong></span>
+          </td>
+          <td>
+            <input type="text" name="Date format" value="${now}" size="22"/>
+          </td>
+        </tr>
+
+        <tr>
+          <td>
+            <span title="how to display the subject line of your blog post"><strong>Subject:</strong></span>
+          </td>
+          <td><input type="text" name="Subject-0" value="${subject[0]}" size="${len(subject[0])}"/>
+            ${now}
+            <input type="text" name="Subject-2" value="${subject[1]}" size="${len(subject[1])}"/>
+          </td>
+        </tr>
+
+        <tr>
+          <td>
+            <span title="which CSS file should be the default"><strong>Stylesheet:</strong></span>
+          </td>
+          <td>
+            <select name="Stylesheet">
+              <option py:for="css_file in css_files">${css_file}</option>
+            </select>
+          </td>
+        </tr>
+
+        <tr>
+          <td><span title="upload a CSS file to theme your webpage"><strong>CSS file:</strong></span></td>
+          <td><input type="file" name="CSS file"/></td>
+        </tr>
+
+        <tr py:if="users">
+          <td><span title="friends can see your secret posts"><strong>Friends:</strong></span></td>
+          <td>
+            <py:for each="_user in users">
+              <input type="checkbox" name="Friends" value="${_user}"/>${_user}<br/>
+            </py:for>
+          </td>
+        </tr>
+      </table>
+
+      <input type="submit" name="submit" value="Submit"/>
+
+    </form>
+  </body>
+</html>