Mercurial > hg > bitsyblog
annotate bitsyblog/bitsyblog.py @ 20:1554cb56aa2f
got index working, just doesnt do anything
| author | k0s <k0scist@gmail.com> | 
|---|---|
| date | Sun, 25 Oct 2009 21:36:33 -0400 | 
| parents | 8931c5b7e632 | 
| children | 7cdb3eecc045 | 
| rev | line source | 
|---|---|
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 1 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 2 a tiny tiny blog. | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 3 this is the view class and is more bitsyblog than anything | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 4 else can claim to be | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 5 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 6 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 7 ### global variables | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 8 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 9 # who can view which blog posts | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 10 roles = { 'public': ( 'public', ), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 11 'friend': ( 'public', 'secret' ), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 12 'author': ( 'public', 'secret', 'private' ), } | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 13 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 14 ### imports | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 15 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 16 import dateutil.parser # XXX separate, for now | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 17 import parser # bitsyblog dateutil parser | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 18 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 19 import cgi | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 20 import datetime | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 21 import docutils | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 22 import docutils.core | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 23 import inspect | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 24 import markup | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 25 import os | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 26 import PyRSS2Gen | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 27 import re | 
| 4 | 28 | 
| 29 import utils # local import | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 30 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 31 from blog import FileBlog | 
| 4 | 32 from cStringIO import StringIO | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 33 from docutils.utils import SystemMessage | 
| 15 | 34 from genshi.builder import Markup | 
| 9 | 35 from genshi.template import TemplateLoader | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 36 from lxml import etree | 
| 4 | 37 from markup.form import Form | 
| 9 | 38 from paste.fileapp import FileApp | 
| 6 | 39 from pkg_resources import resource_filename | 
| 15 | 40 from urlparse import urlparse | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 41 from user import FilespaceUsers | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 42 from webob import Request, Response, exc | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 43 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 44 ### exceptions | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 45 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 46 class BlogPathException(Exception): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 47 """exception when trying to retrieve the blog""" | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 48 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 49 ### the main course | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 50 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 51 class BitsyBlog(object): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 52 """a very tiny blog""" | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 53 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 54 ### class level variables | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 55 defaults = { 'date_format': '%H:%M %F', | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 56 'file_dir': os.path.dirname(__file__), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 57 'subject': '[ %(date)s ]:', | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 58 'n_links': 5, # number of links for navigation | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 59 'site_name': 'bitsyblog', | 
| 15 | 60 'auto_reload': 'True', | 
| 6 | 61 'help_file': None, | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 62 } | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 63 | 
| 15 | 64 | 
| 65 cooked_bodies = {} | |
| 66 | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 67 def __init__(self, **kw): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 68 for key in self.defaults: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 69 setattr(self, key, kw.get(key, self.defaults[key])) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 70 self.n_links = int(self.n_links) # could be a string from the .ini | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 71 self.response_functions = { 'GET': self.get, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 72 'POST': self.post, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 73 'PUT': self.put | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 74 } | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 75 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 76 # abstract attributes | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 77 self.users = FilespaceUsers(self.file_dir) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 78 self.blog = FileBlog(self.file_dir) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 79 self.cooker = self.restructuredText | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 80 | 
| 9 | 81 # template renderer | 
| 82 self.loader = TemplateLoader(resource_filename(__name__, 'templates'), | |
| 83 auto_reload=self.auto_reload.lower()=='true') | |
| 84 | |
| 85 # static file renderer | |
| 86 | |
| 87 # helpfile | |
| 3 | 88 if self.help_file and os.path.exists(self.help_file): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 89 help = file(self.help_file).read() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 90 self.help = docutils.core.publish_string(help, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 91 writer_name='html', | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 92 settings_overrides={'report_level': 5}) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 93 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 94 # for BitsyAuth | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 95 self.newuser = self.users.new | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 96 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 97 ### methods dealing with HTTP | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 98 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 99 def __call__(self, environ, start_response): | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 100 request = Request(environ) | 
| 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 101 res = self.response_functions.get(request.method, self.error())(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 102 return res(environ, start_response) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 103 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 104 def get_response(self, text, content_type='text/html'): | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 105 # XXX to deprecate | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 106 res = Response(content_type=content_type, body=text) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 107 return res | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 108 | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 109 def logo(self, request): | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 110 _logo = 'bitsyblog.png' # TODO: should go to self.logo | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 111 logo = os.path.join(self.file_dir, _logo) | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 112 if os.path.exists(logo): | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 113 return self.link(request, _logo) | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 114 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 115 def get_index(self, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 116 """returns material pertaining to the root of the site""" | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 117 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 118 path = request.path_info.strip('/') | 
| 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 119 n_links = self.number_of_links(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 120 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 121 ### the front page | 
| 19 
8931c5b7e632
* fixing up index to display [in progress]
 k0s <k0scist@gmail.com> parents: 
17diff
changeset | 122 if not path: | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 123 return self.get_response(self.index(request, n_links)) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 124 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 125 ### feeds | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 126 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 127 n_posts = self.number_of_posts(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 128 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 129 # site rss | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 130 if path == 'rss': | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 131 if n_posts is None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 132 n_posts = 10 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 133 return self.get_response(self.site_rss(request, n_posts), content_type='text/xml') | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 134 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 135 # site atom | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 136 if path == 'atom': | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 137 if n_posts is None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 138 n_posts = 10 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 139 return self.get_response(self.atom(request, self.blog.latest(self.users.users(), n_posts)), content_type='text/xml') | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 140 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 141 ### help | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 142 if path == 'help' and hasattr(self, 'help'): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 143 return self.get_response(self.help) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 144 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 145 ### static files | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 146 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 147 # site.css | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 148 if path == 'css/site.css': | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 149 css_file = os.path.join(self.file_dir, 'site.css') | 
| 9 | 150 return self.get_response(file(css_file).read(), content_type='text/css') # should use FileApp | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 151 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 152 # logo | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 153 if path == 'bitsyblog.png': | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 154 logo = os.path.join(self.file_dir, 'bitsyblog.png') | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 155 if not self.logo(request): | 
| 19 
8931c5b7e632
* fixing up index to display [in progress]
 k0s <k0scist@gmail.com> parents: 
17diff
changeset | 156 raise exc.HTTPNotFound | 
| 9 | 157 return self.get_response(file(logo, 'rb').read(), content_type='image/png') # should use FileApp | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 158 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 159 def get_user_space(self, user, path, request): | 
| 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 160 """returns a part of the user space""" | 
| 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 161 | 
| 14 
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
 k0s <k0scist@gmail.com> parents: 
12diff
changeset | 162 # request.user = self.users[user] # user whose blog is viewed | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 163 check = self.check_user(user, request) # is this the authenticated user? | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 164 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 165 feed = None # not an rss/atom feed by default (flag) | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 166 n_posts = self.number_of_posts(request, user) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 167 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 168 # special paths | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 169 if path == [ 'post' ]: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 170 if check is not None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 171 return check | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 172 return self.get_response(self.form_post(request, user)) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 173 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 174 if path == [ 'preferences' ]: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 175 if check is not None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 176 return check | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 177 return self.get_response(self.preferences(request, user)) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 178 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 179 if path == [ 'rss' ]: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 180 feed = 'rss' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 181 path = [] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 182 if n_posts is None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 183 n_posts = 10 # TODO: allow to be configurable | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 184 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 185 if path == [ 'atom' ]: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 186 feed = 'atom' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 187 path = [] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 188 if n_posts is None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 189 n_posts = 10 # TODO: allow to be configurable | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 190 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 191 if len(path) == 2: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 192 if path[0] == 'css': | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 193 for i in request.user.settings['CSS']: | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 194 # find the right CSS file | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 195 if i['filename'] == path[1]: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 196 return self.get_response(i['css'], content_type='text/css') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 197 else: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 198 return exc.HTTPNotFound('CSS "%s" not found' % path[1]) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 199 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 200 role = self.role(user, request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 201 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 202 # get the blog | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 203 try: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 204 blog = self.get_blog(user, path, role, n_items=n_posts) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 205 except BlogPathException, e: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 206 return exc.HTTPNotFound(str(e)) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 207 except exc.HTTPException, e: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 208 return e.wsgi_response | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 209 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 210 if feed == 'rss': | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 211 content = self.rss(request, user, blog) # XXX different signatures | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 212 return self.get_response(content, content_type='text/xml') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 213 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 214 if feed == 'atom': | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 215 content = self.atom(request, blog, user) # XXX different signatures | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 216 return self.get_response(content, content_type='text/xml') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 217 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 218 # reverse the blog if necessary | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 219 if request.GET.get('sort') == 'forward': | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 220 blog = list(reversed(blog)) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 221 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 222 n_links = self.number_of_links(request, user) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 223 # don't display navigation for short blogs | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 224 if len(blog) < 2: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 225 n_links = 0 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 226 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 227 # write the blog | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 228 content = self.write_blog(user, blog, request.path_info, n_links, request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 229 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 230 # return the content | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 231 return self.get_response(content) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 232 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 233 def get(self, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 234 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 235 display the blog or respond to a get request | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 236 """ | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 237 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 238 # GENSHI: data dictionary | 
| 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 239 request.environ['data'] = { 'site_name': self.site_name, | 
| 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 240 'request': request, | 
| 16 | 241 'link': self.link, | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 242 'logo': self.logo(request) } | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 243 | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 244 # front matter of the site | 
| 19 
8931c5b7e632
* fixing up index to display [in progress]
 k0s <k0scist@gmail.com> parents: 
17diff
changeset | 245 index = self.get_index(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 246 if index is not None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 247 return index | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 248 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 249 ### user space | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 250 user, path = self.userpath(request) | 
| 9 | 251 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 252 return self.get_user_space(user, path, request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 253 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 254 def post(self, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 255 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 256 write a blog entry and other POST requests | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 257 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 258 # TODO: posting to '/' ? | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 259 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 260 # find user + path | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 261 user, path = self.userpath(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 262 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 263 check = self.check_user(user) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 264 if check is not None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 265 return check | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 266 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 267 if len(path): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 268 if path == [ 'preferences' ]: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 269 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 270 # make the data look like we want | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 271 settings = {} | 
| 9 | 272 settings['Date format'] = request.POST.get('Date format') | 
| 273 settings['Subject'] = '%(date)s'.join((request.POST['Subject-0'], request.POST['Subject-2'])) | |
| 274 settings['Stylesheet'] = request.POST['Stylesheet'] | |
| 275 settings['CSS file'] = request.POST.get('CSS file') | |
| 276 settings['Friends'] = ', '.join(request.POST.getall('Friends')) | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 277 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 278 errors = self.users.write_settings(user, **settings) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 279 if errors: # re-display form with errors | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 280 return self.get_response(self.preferences(request, user, errors)) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 281 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 282 return self.get_response(self.preferences(request, user, message='Changes saved')) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 283 elif len(path) == 1 and self.isentry(path[0]): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 284 entry = self.blog.entry(user, path[0], roles['author']) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 285 if entry is None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 286 return exc.HTTPNotFound("Blog entry %s not found %s" % path[0]) | 
| 9 | 287 privacy = request.POST.get('privacy') | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 288 datestamp = entry.datestamp() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 289 if privacy: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 290 self.blog.delete(user, datestamp) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 291 self.blog.post(user, datestamp, entry.body, privacy) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 292 return exc.HTTPSeeOther("Settings updated", location='/%s/%s' % (user, datestamp)) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 293 else: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 294 return exc.HTTPMethodNotAllowed("Not sure what you're trying to do") | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 295 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 296 # get the body of the post | 
| 9 | 297 body = request.body | 
| 298 body = request.POST.get('form-post', body) | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 299 body = body.strip() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 300 if not body: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 301 return exc.HTTPSeeOther("Your post has no content! No blog for you", | 
| 9 | 302 location='/%s' % self.user_url(request, user, 'post')) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 303 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 304 # determine if the post is secret or private | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 305 privacy = request.GET.get('privacy') or request.POST.get('privacy') or 'public' | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 306 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 307 # write the file | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 308 now = utils.datestamp(datetime.datetime.now()) | 
| 9 | 309 location = "/%s" % self.user_url(request, user, now) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 310 self.blog.post(user, now, body, privacy) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 311 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 312 # point the user at the post | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 313 return exc.HTTPSeeOther("Post blogged by bitsy", location=location) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 314 | 
| 9 | 315 def put(self, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 316 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 317 PUT several blog entries from a file | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 318 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 319 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 320 # find user + path | 
| 9 | 321 user, path = self.userpath(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 322 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 323 if user not in self.users.users(): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 324 return exc.HTTPNotFound("No blog found for %s" % user) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 325 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 326 if len(path): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 327 return exc.HTTPMethodNotAllowed("Not sure what you're trying to do") | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 328 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 329 # find the dates + entries in the file | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 330 regex = '\[.*\]:' | 
| 9 | 331 entries = re.split(regex, request.body)[1:] | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 332 dates = [ date.strip().strip(':').strip('[]').strip() | 
| 9 | 333 for date in re.findall(regex, request.body) ] | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 334 dates = [ dateutil.parser.parse(date) for date in dates ] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 335 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 336 # write to the blog | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 337 for i in range(len(entries)): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 338 datestamp = utils.datestamp(dates[i]) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 339 self.blog.post(user, datestamp, entries[i], 'public') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 340 | 
| 6 | 341 # TODO: redirect to index page | 
| 342 return exc.HTTPOk("%s posts blogged" % len(entries)) | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 343 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 344 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 345 def error(self): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 346 """deal with non-supported methods""" | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 347 methods = ', '.join(self.response_functions.keys()[:1]) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 348 methods += ' and %s' % self.response_functions.keys()[-1] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 349 return exc.HTTPMethodNotAllowed("Only %s operations are allowed" % methods) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 350 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 351 ### auth/auth functions | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 352 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 353 def passwords(self): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 354 return self.users.passwords() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 355 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 356 def authenticated(self, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 357 """return authenticated user""" | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 358 # XXX needed? | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 359 return request.environ.get('REMOTE_USER') | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 360 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 361 def check_user(self, user, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 362 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 363 determine authenticated user | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 364 returns None on success | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 365 """ | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 366 authenticated = self.authenticated(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 367 if authenticated is None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 368 return exc.HTTPUnauthorized('Unauthorized') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 369 elif user != authenticated: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 370 return exc.HTTPForbidden("Forbidden") | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 371 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 372 def role(self, user, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 373 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 374 determine what role the authenticated member has | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 375 with respect to the user | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 376 """ | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 377 auth = self.authenticated(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 378 if not auth: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 379 return 'public' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 380 if auth == user: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 381 return 'author' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 382 else: | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 383 if auth in request.user.settings['Friends']: | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 384 return 'friend' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 385 else: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 386 return 'public' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 387 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 388 ### user methods | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 389 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 390 def userpath(self, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 391 """user who's blog one is viewing""" | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 392 path = request.path_info.strip('/').split('/') | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 393 name = path[0] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 394 path = path[1:] | 
| 14 
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
 k0s <k0scist@gmail.com> parents: 
12diff
changeset | 395 if name: | 
| 
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
 k0s <k0scist@gmail.com> parents: 
12diff
changeset | 396 if name not in self.users: | 
| 
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
 k0s <k0scist@gmail.com> parents: 
12diff
changeset | 397 exc.HTTPNotFound("No blog found for %s" % user) | 
| 
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
 k0s <k0scist@gmail.com> parents: 
12diff
changeset | 398 request.user = self.users[name] | 
| 
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
 k0s <k0scist@gmail.com> parents: 
12diff
changeset | 399 else: | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 400 name = None | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 401 return name, path | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 402 | 
| 15 | 403 ### methods | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 404 | 
| 15 | 405 def link(self, request, path=(), permanant=False): | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 406 if isinstance(path, basestring): | 
| 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 407 path = [ path ] | 
| 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 408 path = [ i.strip('/') for i in path ] | 
| 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 409 if permanant: | 
| 15 | 410 application_url = request.application_url | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 411 else: | 
| 15 | 412 | 
| 413 application_url = urlparse(request.application_url)[2] | |
| 414 path = [ application_url ] + list(path) | |
| 415 return '/'.join(path) | |
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 416 | 
| 15 | 417 def user_url(self, request, user, *args, **kw): | 
| 418 """link to a user resource""" | |
| 419 permalink = kw.get('permalink', False) | |
| 420 path = [ user ] | |
| 421 path.extend(args) | |
| 422 return self.link(request, path, permalink) | |
| 423 | |
| 424 def permalink(self, request, blogentry): | |
| 425 """permalink for a blog entry""" | |
| 426 return self.user_url(request, blogentry.user, blogentry.datestamp(), permalink=True) | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 427 | 
| 9 | 428 def mangledurl(self, request, blogentry): | 
| 15 | 429 """return a mangled url for obfuscated sharing""" | 
| 9 | 430 return self.user_url(request, blogentry.user, 'x%x' % (int(blogentry.datestamp()) * self.users.secret(blogentry.user)), permalink=True) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 431 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 432 def unmangleurl(self, url, user): | 
| 15 | 433 """unmangle a url for obfuscated sharing""" | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 434 url = url.strip('x') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 435 try: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 436 value = int(url, 16) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 437 except ValueError: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 438 return None | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 439 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 440 # XXX once one has a mangled url, one can obtain the secret | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 441 value /= self.users.secret(user) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 442 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 443 entry = str(value) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 444 if self.isentry(entry): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 445 return self.blog.entry(user, entry, ['public', 'secret', 'private']) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 446 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 447 ### blog retrival methods | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 448 | 
| 15 | 449 def isentry(self, string): # TODO -> blog.py | 
| 450 """returns whether the string is a blog entry""" | |
| 451 return (len(string) == len(''.join(utils.timeformat))) and string.isdigit() | |
| 452 | |
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 453 def number_of_posts(self, request, user=None): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 454 """return the number of blog posts to display""" | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 455 # determine number of posts to display (None -> all) | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 456 n_posts = request.GET.get('posts', None) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 457 if n_posts is not None: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 458 try: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 459 n_posts = int(n_posts) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 460 if n_links > 0 and n_links > n_posts: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 461 n_links = n_posts # don't display more links than posts | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 462 except (TypeError, ValueError): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 463 n_posts = None | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 464 return n_posts | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 465 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 466 def number_of_links(self, request, user=None): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 467 """return the number of links to display in the navigation""" | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 468 n_links = request.GET.get('n') | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 469 if n_links == 'all': | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 470 return -1 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 471 try: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 472 n_links = int(n_links) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 473 except (TypeError, ValueError): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 474 n_links = self.n_links | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 475 return n_links | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 476 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 477 def get_blog(self, user, path, role='public', n_items=None): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 478 """retrieve the blog entry based on the path""" | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 479 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 480 notfound = "blog entry not found" | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 481 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 482 # get permissions | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 483 allowed = roles[role] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 484 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 485 # entire blog | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 486 if not path: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 487 return self.blog(user, allowed, n_items) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 488 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 489 # mangled urls | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 490 if len(path) == 1 and path[0].startswith('x'): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 491 entry = self.unmangleurl(path[0], user) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 492 if entry: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 493 return [ entry ] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 494 else: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 495 raise BlogPathException(notfound) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 496 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 497 # individual blog entry | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 498 if (len(path) == 1) and self.isentry(path[0]): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 499 blog = self.blog.entry(user, path[0], allowed) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 500 if not blog: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 501 raise BlogPathException(notfound) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 502 return [ blog ] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 503 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 504 # parse the path into a date path | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 505 n_date_vals = 3 # year, month, date | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 506 if len(path) > n_date_vals: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 507 raise BlogPathException(notfound) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 508 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 509 # ensure the path conforms to expected values (ints): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 510 try: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 511 [ int(i) for i in path] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 512 except ValueError: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 513 raise BlogPathException(notfound) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 514 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 515 # get the blog | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 516 return self.blog.entries(user, allowed, *path) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 517 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 518 ### methods that write HTML | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 519 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 520 def render(self, request, body, title=None, feedtitle=None): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 521 """layout the page in a unified way""" | 
| 17 | 522 _title = [ self.site_name ] | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 523 user = getattr(request, 'user', None) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 524 if user: | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 525 stylesheets = request.user['CSS'] | 
| 9 | 526 stylesheets = [ (("/%s" % self.user_url(request, user.name, 'css', css['filename'])), | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 527 css['name']) for css in stylesheets ] | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 528 _title.insert(0, request.user.name) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 529 else: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 530 stylesheets = (("/css/site.css", "Default"),) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 531 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 532 if title: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 533 _title.insert(0, title) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 534 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 535 title = ' - '.join(_title) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 536 head_markup = () | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 537 if feedtitle: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 538 head_markup = ( '<link rel="alternate" type="application/atom+xml" title="%s" href="atom" />' % feedtitle, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 539 '<link rel="alternate" type="application/rss+xml" title="%s" href="rss" />' % feedtitle,) | 
| 15 | 540 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 541 return markup.wrap(self.site_nav(request)+body, title, stylesheets, head_markup=head_markup) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 542 | 
| 17 | 543 def stylesheets(self, request): | 
| 544 user = getattr(request, 'user', None) | |
| 545 if user: | |
| 546 stylesheets = request.user['CSS'] | |
| 547 stylesheets = [ (self.user_url(request, user.name, 'css', css['filename']), | |
| 548 css['name']) for css in stylesheets ] | |
| 549 else: | |
| 550 stylesheets = [(self.link(request, "css/site.css"), "Default")] | |
| 551 return stylesheets | |
| 552 | |
| 553 | |
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 554 def site_nav(self, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 555 """returns HTML for site navigation""" | 
| 15 | 556 | 
| 557 links = [(self.link(request), '/'), ] | |
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 558 user = self.authenticated(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 559 if user: | 
| 15 | 560 links.extend([(self.user_url(request, user), user), | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 561 (self.user_url(request, user, 'post'), 'post'), | 
| 15 | 562 (self.user_url(request, user, 'preferences'), 'preferences'), | 
| 563 (self.link(request, 'logout'), 'logout')]) | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 564 else: | 
| 15 | 565 links.extend([(self.link(request, 'login'), 'login'), | 
| 566 (self.link(request, 'join'), 'join')]) | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 567 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 568 if hasattr(self, 'help'): | 
| 15 | 569 links.append((self.link(request, 'help'), 'help')) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 570 | 
| 15 | 571 request.environ['data']['links'] = links | 
| 572 | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 573 | 
| 19 
8931c5b7e632
* fixing up index to display [in progress]
 k0s <k0scist@gmail.com> parents: 
17diff
changeset | 574 def index(self, request, n_links): | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 575 data = request.environ['data'] | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 576 self.site_nav(request) | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 577 template = self.loader.load('index.html') | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 578 return template.generate(**request.environ['data']).render() | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 579 | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 580 # retval = StringIO() | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 581 # print >> retval, '<h1><img src="bitsyblog.png" alt="bitsyblog"/></h1>' | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 582 | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 583 # # get the blogs | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 584 # blogs = {} | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 585 # for user in self.users: | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 586 # blog = self.blog(user, ('public',), n_links) | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 587 # if blog: | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 588 # blogs[user] = blog | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 589 # users = blogs.keys() | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 590 | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 591 # # display latest active user first | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 592 # users.sort(key=lambda user: blogs[user][0].date, reverse=True) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 593 | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 594 # # display users' blogs | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 595 # for user in users: | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 596 # print >> retval, '<div id="%s" class="user">' % user | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 597 # print >> retval, '<a href="%s">%s</a>' % (user, user) | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 598 # blog = blogs[user] | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 599 # print >> retval, self.navigation(user, blog, '/%s' % user, n_links) | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 600 # print >> retval, '</div>' | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 601 | 
| 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 602 # return self.render(request, retval.getvalue(), feedtitle=self.site_name) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 603 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 604 def navigation(self, user, blog, path, n_links, n_char=80): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 605 prefs = self.users[user].settings | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 606 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 607 if n_links == 0 or not len(blog): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 608 return '' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 609 retval = StringIO() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 610 print >> retval, '<div class="navigation">' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 611 more = '' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 612 if (n_links != -1) and (len(blog) > n_links): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 613 more = '<a href="%s?n=all">more</a>' % path | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 614 blog = blog[:n_links] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 615 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 616 entries = [] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 617 for entry in blog: | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 618 blog_id = entry.datestamp() | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 619 format = prefs.get('Date format', self.date_format) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 620 datestamp = entry.date.strftime(format) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 621 synopsis = entry.title() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 622 if synopsis: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 623 synopsis = ': %s' % cgi.escape(synopsis) | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 624 entries.append(markup.link("%s#%s" % (path, blog_id), datestamp) + synopsis) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 625 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 626 print >> retval, markup.listify(entries) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 627 print >> retval, more | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 628 print >> retval, '</div>' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 629 return retval.getvalue() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 630 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 631 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 632 def write_blog(self, user, blog, path, n_links, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 633 """return the user's blog in HTML""" | 
| 15 | 634 | 
| 635 # XXX probably should go elsewhere | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 636 for entry in blog: | 
| 15 | 637 if (user, entry.datestamp()) not in self.cooked_bodies: | 
| 638 self.cooked_bodies[(user, entry.datestamp())] = self.cooker(entry.body) | |
| 639 entry.cooked_body = Markup(self.cooked_bodies[(user, entry.datestamp())]) | |
| 640 | |
| 641 # site nav | |
| 642 # XXX def site_nav() puts directly in request.environ['data'] | |
| 643 # should return instead | |
| 644 self.site_nav(request) | |
| 645 | |
| 646 # user data -> should be moved up the chain | |
| 647 data = request.environ['data'] | |
| 648 data['user'] = user | |
| 649 data['role'] = self.role(user, request) | |
| 17 | 650 data['stylesheets'] = self.stylesheets(request) | 
| 15 | 651 data['subject'] = request.user.settings.get('Subject', self.subject) | 
| 652 data['date_format'] = request.user.settings.get('Date format', self.date_format) | |
| 653 data['user_url'] = self.user_url | |
| 654 data['mangledurl'] = self.mangledurl | |
| 655 | |
| 656 # blog data | |
| 657 data['blog'] = blog | |
| 658 data['n_links'] = n_links | |
| 659 | |
| 660 # render the template | |
| 661 template = self.loader.load('blog.html') | |
| 662 return template.generate(**data).render() | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 663 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 664 def restructuredText(self, string): | 
| 17 | 665 """renders a string with restructured text""" | 
| 666 | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 667 origstring = string | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 668 settings = { 'report_level': 5 } | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 669 string = string.strip() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 670 try: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 671 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 672 parts = docutils.core.publish_parts(string.strip(), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 673 writer_name='html', | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 674 settings_overrides=settings) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 675 body = parts['body'] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 676 except SystemMessage, e: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 677 lines = [ cgi.escape(i.strip()) for i in string.split('\n') ] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 678 body = '<br/>\n'.join(lines) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 679 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 680 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 681 retval = '<div class="blog-body">%s</div>' % body | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 682 return retval | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 683 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 684 # this should be reenabled if 'system-message's again appear in the markup | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 685 try: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 686 foo = etree.fromstring(retval) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 687 except etree.XMLSyntaxError: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 688 return retval | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 689 # should cleanup the <div class="system-message"> | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 690 for i in foo.getiterator(): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 691 if dict(i.items()).get('class') == 'system-message': | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 692 i.clear() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 693 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 694 return etree.tostring(foo) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 695 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 696 | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 697 ### feeds | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 698 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 699 def site_rss(self, request, n_items=10): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 700 blog = self.blog.latest(list(self.users.users()), n_items) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 701 title = self.site_name + ' - rss' | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 702 link = request.application_url | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 703 description = "latest scribblings on %s" % self.site_name | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 704 lastBuildDate = datetime.datetime.now() | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 705 items = [ self.rss_item(request, entry.user, entry) for entry in blog ] | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 706 rss = PyRSS2Gen.RSS2(title=title, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 707 link=link, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 708 description=description, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 709 lastBuildDate=lastBuildDate, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 710 items=items) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 711 return rss.to_xml() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 712 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 713 def rss(self, request, user, blog): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 714 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 715 rss feed for a user's blog | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 716 done with PyRSS2Gen: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 717 http://www.dalkescientific.com/Python/PyRSS2Gen.html | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 718 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 719 title = "%s's blog" % user | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 720 link = os.path.split(request.url)[0] | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 721 description = "latest blog entries for %s on %s" % (user, self.site_name) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 722 lastBuildDate = datetime.datetime.now() # not sure what this means | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 723 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 724 items = [ self.rss_item(request, user, entry) for entry in blog ] | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 725 rss = PyRSS2Gen.RSS2(title=title, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 726 link=link, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 727 description=description, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 728 lastBuildDate=lastBuildDate, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 729 items=items) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 730 return rss.to_xml() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 731 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 732 def rss_item(self, request, user, entry): | 
| 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 733 if hasattr(request, 'user') and request.user.name == user: | 
| 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 734 prefs = request.user.settings | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 735 else: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 736 prefs = self.users[user].settings | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 737 subject = prefs.get('Subject', self.subject) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 738 date_format = prefs.get('Date format', self.date_format) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 739 title = entry.title() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 740 return PyRSS2Gen.RSSItem(title=title, #subject % { 'date': entry.date.strftime(date_format) }, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 741 link=self.permalink(entry), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 742 description=unicode(entry.body, errors='replace'), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 743 author=user, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 744 guid=PyRSS2Gen.Guid(self.permalink(entry)), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 745 pubDate=entry.date) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 746 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 747 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 748 def atom(self, request, blog, author=None): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 749 retval = StringIO() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 750 print >> retval, """<?xml version="1.0" encoding="utf-8"?> | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 751 <feed xmlns="http://www.w3.org/2005/Atom"> | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 752 """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 753 if author: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 754 title = "%s's blog" % author | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 755 link = request.host_url + '/' + author | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 756 else: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 757 title = self.site_name + ' - atom' | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 758 link = request.application_url | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 759 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 760 date = blog[0].date.isoformat() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 761 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 762 print >> retval, '<title>%s</title>' % title | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 763 print >> retval, '<link href="%s" />' % link | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 764 print >> retval, '<updated>%s</updated>' % date | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 765 if author: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 766 print >> retval, """ | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 767 <author> | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 768 <name>%s</name> | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 769 </author>""" % author | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 770 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 771 for entry in blog: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 772 print >> retval, '<entry>' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 773 print >> retval, '<title>%s</title>' % cgi.escape(entry.title()) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 774 print >> retval, '<link href="%s" />' % self.permalink(entry) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 775 print >> retval, '<updated>%s</updated>' % entry.date.isoformat() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 776 print >> retval, '<summary>%s</summary>' % cgi.escape(entry.body) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 777 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 778 print >> retval, '</entry>' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 779 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 780 print >> retval, '</feed>' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 781 return retval.getvalue() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 782 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 783 ### forms and accompanying display | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 784 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 785 def form_post(self, request, user): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 786 retval = StringIO() | 
| 9 | 787 print >> retval, '<form action="/%s" method="post">' % self.user_url(request, user) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 788 print >> retval, '<textarea cols="80" rows="25" name="form-post"></textarea><br/>' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 789 print >> retval, self.privacy_settings() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 790 print >> retval, '<input type="submit" name="submit" value="Post" />' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 791 print >> retval, '</form>' | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 792 return self.render(request, retval.getvalue()) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 793 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 794 def preferences_form(self, request, user): | 
| 15 | 795 prefs = request.user.settings | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 796 form = Form() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 797 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 798 # date format | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 799 format = prefs.get('Date format', self.date_format) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 800 value = datetime.datetime.now().strftime(format) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 801 form.add_element('textfield', 'Date format', value=value, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 802 help='how to display dates in your blog post subject') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 803 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 804 # subject | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 805 subject = prefs.get('Subject', self.subject) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 806 subject = subject.split('%(date)s', 1) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 807 func = lambda name: value | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 808 form.add_elements('Subject', | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 809 ['textfield', func, 'textfield' ], | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 810 [ (), (), ()], # this is horrible! | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 811 [ dict(value=subject[0]), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 812 {}, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 813 dict(value=subject[1]) ], | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 814 help='how to display the subject line of your blog post' | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 815 ) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 816 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 817 # CSS files | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 818 css_files = [ i['name'] for i in prefs['CSS'] ] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 819 form.add_element('menu', 'Stylesheet', css_files, | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 820 help='which CSS file should be the default') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 821 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 822 # or upload a CSS file | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 823 form.add_element('file_upload', 'CSS file', | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 824 help='upload a CSS file to theme your webpage') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 825 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 826 # Friends -- can see secret posts | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 827 users = [ i for i in list(self.users.users()) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 828 if i != user ] | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 829 if users: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 830 users.sort(key=str.lower) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 831 form.add_element('checkboxes', 'Friends', | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 832 users, prefs.get('Friends', set()), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 833 help='friends can see your secret posts') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 834 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 835 return form | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 836 | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 837 def preferences(self, request, user, errors=None, message=None): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 838 """user preferences form""" | 
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 839 body = self.preferences_form(request, user)(errors) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 840 if message: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 841 body = '%s\n%s' % ( markup.p(markup.strong(message)), body ) | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 842 return self.render(request, body, title='preferences') | 
| 9 | 843 | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 844 def privacy_settings(self, default='public'): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 845 """HTML snippet for privacy settings""" | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 846 settings = (('public', 'viewable to everyone'), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 847 ('secret', 'viewable only to your friends'), | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 848 ('private', 'viewable only to you')) | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 849 form = Form() | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 850 return form.radiobuttons('privacy', settings, checked=default, joiner=' ') | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 851 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 852 class BitsierBlog(BitsyBlog): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 853 """single user version of bitsyblog""" | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 854 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 855 def get(self, request): | 
| 9 | 856 | 
| 857 # GENSHI: global data dictionary | |
| 12 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 858 request.environ['data'] = { 'site_name': self.site_name, | 
| 
dd8c1c8ae0da
more removing of self.request and general cleanup
 k0s <k0scist@gmail.com> parents: 
9diff
changeset | 859 'request': request, | 
| 16 | 860 'link': self.link, | 
| 20 
1554cb56aa2f
got index working, just doesnt do anything
 k0s <k0scist@gmail.com> parents: 
19diff
changeset | 861 'logo': self.logo(request) } | 
| 9 | 862 | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 863 ### user space | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 864 user, path = self.userpath(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 865 if user not in self.users: | 
| 9 | 866 return exc.HTTPNotFound("Blog entry not found") | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 867 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 868 return self.get_user_space(user, path, request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 869 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 870 def userpath(self, request): | 
| 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 871 path = request.path_info.strip('/').split('/') | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 872 if path == ['']: | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 873 path = [] | 
| 14 
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
 k0s <k0scist@gmail.com> parents: 
12diff
changeset | 874 request.user = self.users[self.user] | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 875 return self.user, path | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 876 | 
| 9 | 877 def user_url(self, request, user, *args, **kw): | 
| 15 | 878 permalink = kw.get('permalink', False) | 
| 879 return self.link(request, args, permalink) | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 880 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 881 def passwords(self): | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 882 return { self.user: self.users.password(self.user) } | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 883 | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 884 def site_nav(self, request): | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 885 """returns HTML for site navigation""" | 
| 15 | 886 links = [(self.user_url(request, self.user), self.user), ] | 
| 7 
57a45adf33d4
separate out request from self.  ultimately a new object should be
 k0s <k0scist@gmail.com> parents: 
6diff
changeset | 887 user = self.authenticated(request) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 888 if user: | 
| 15 | 889 links.extend([(self.user_url(request, user, 'post'), 'post'), | 
| 890 (self.user_url(request, user, 'preferences'), 'preferences'), | |
| 891 (self.link(request, 'logout'), 'logout')]) | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 892 else: | 
| 15 | 893 links.append((self.link(request, 'login'), 'login')) | 
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 894 | 
| 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 895 if hasattr(self, 'help'): | 
| 15 | 896 links.append((self.link(request, 'help'), 'about')) | 
| 897 | |
| 0 
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
 k0s <k0scist@gmail.com> parents: diff
changeset | 898 | 
| 15 | 899 request.environ['data']['links'] = links | 
| 900 | 
