Mercurial > hg > bitsyblog
annotate bitsyblog/bitsyblog.py @ 74:2c219b788648
dont let handlers kill the blog
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 15 Sep 2010 10:34:14 -0700 |
parents | c9bab68d00ac |
children | c690198a2625 |
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 ### imports |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
10 |
28 | 11 import dateutil.parser |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
12 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
13 import cgi |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
14 import datetime |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
15 import docutils |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
16 import docutils.core |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
17 import inspect |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 import os |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 import PyRSS2Gen |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
20 import re |
4 | 21 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
22 import utils |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
23 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
24 from blog import FileBlog |
4 | 25 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
|
26 from docutils.utils import SystemMessage |
15 | 27 from genshi.builder import Markup |
9 | 28 from genshi.template import TemplateLoader |
58 | 29 from paste.fileapp import FileApp |
71 | 30 from pkg_resources import iter_entry_points |
6 | 31 from pkg_resources import resource_filename |
58 | 32 from StringIO import StringIO |
15 | 33 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
|
34 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
|
35 |
59 | 36 from roles import roles |
37 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
38 ### exceptions |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
39 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
40 class BlogPathException(Exception): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
41 """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
|
42 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
43 ### the main course |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
44 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
45 class BitsyBlog(object): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
46 """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
|
47 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
48 ### class level variables |
58 | 49 defaults = { 'date_format': '%H:%M %F', # default date format |
50 'file_dir': os.path.dirname(__file__), # where the blog is kept | |
51 'subject': '[ %(date)s ]:', # default subject | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
52 'n_links': 5, # number of links for navigation |
58 | 53 'site_name': 'bitsyblog', # name of the site (needed?) |
54 'header': None, # text to insert as first child of body' | |
55 'template_directories': '', # space separated template_directories | |
56 'auto_reload': 'True', # reload the genshi templates | |
57 'help_file': None, # help to display | |
58 'feed_items': 10, # number of RSS/atom items to display | |
72
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
59 'post_handlers': '' # post handlers |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
60 } |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
61 |
15 | 62 |
63 cooked_bodies = {} | |
64 | |
70
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
65 def __init__(self, kw, handler_args): |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 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
|
70 'POST': self.post, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
71 'PUT': self.put |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
72 } |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
73 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
74 # abstract attributes |
59 | 75 from user import FilespaceUsers |
76 | |
0
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) |
71 | 78 self.blog = FileBlog(self.file_dir) |
0
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 |
58 | 80 self.feed_items = int(self.feed_items) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
81 |
9 | 82 # template renderer |
52
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
83 self.auto_reload = self.auto_reload.lower()=='true' |
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
84 self.template_directories = self.template_directories.split() # no spaces in directory names, for now |
63 | 85 |
86 for directory in self.template_directories: | |
87 assert os.path.isdir(directory), "Bitsyblog template directory %s does not exist!" % directory | |
88 | |
52
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
89 self.template_directories.append(resource_filename(__name__, 'templates')) |
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
90 self.loader = TemplateLoader(self.template_directories, |
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
91 auto_reload=self.auto_reload) |
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
92 |
9 | 93 |
94 # helpfile | |
3 | 95 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
|
96 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
|
97 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
|
98 writer_name='html', |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
99 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
|
100 |
50 | 101 # header |
102 if self.header: | |
51 | 103 if os.path.exists(self.header): |
104 self.header = file(self.header).read() | |
50 | 105 self.header = Markup(self.header) |
106 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
107 # for BitsyAuth |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
108 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
|
109 |
70
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
110 # post handlers |
72
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
111 self.post_handlers = [ i for i in self.post_handlers.split() if i ] |
70
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
112 self.handlers = [] # handlers for blog post event |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
113 for entry_point in iter_entry_points('bitsyblog.listeners'): |
72
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
114 if entry_point.name in self.post_handlers: |
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
115 try: |
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
116 handler = entry_point.load()(self, **handler_args.get(entry_point.name, {})) |
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
117 self.handlers.append(handler) |
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
118 except: |
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
119 print 'Cant load entry point %s' % entry_point.name |
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
120 raise |
70
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
121 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
122 ### 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
|
123 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
124 def __call__(self, environ, start_response): |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
125 request = Request(environ) |
27 | 126 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
127 # genshi data dictionary |
27 | 128 request.environ['data'] = { 'site_name': self.site_name, |
129 'request': request, | |
130 'link': self.link, | |
31
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
131 'logo': self.logo(request), |
50 | 132 'header': self.header, |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
133 'user_url': self.user_url, |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
134 'permalink': self.permalink } |
27 | 135 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
136 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
|
137 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
|
138 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
139 def get_response(self, text, content_type='text/html'): |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
140 # 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
|
141 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
|
142 return res |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
143 |
20
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
144 def logo(self, request): |
34 | 145 """link to the logo""" |
20
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
146 _logo = 'bitsyblog.png' # TODO: should go to self.logo |
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
147 logo = os.path.join(self.file_dir, _logo) |
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
148 if os.path.exists(logo): |
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
149 return self.link(request, _logo) |
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
150 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
151 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
|
152 """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
|
153 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
154 path = request.path_info.strip('/') |
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
155 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
|
156 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
157 ### the front page |
19
8931c5b7e632
* fixing up index to display [in progress]
k0s <k0scist@gmail.com>
parents:
17
diff
changeset
|
158 if not path: |
58 | 159 return Response(content_type='text/html', body=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
|
160 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
161 ### feeds |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
162 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
163 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
|
164 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
165 # site rss |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
166 if path == 'rss': |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
167 if n_posts is None: |
58 | 168 n_posts = self.feed_items |
169 return Response(content_type='text/xml', body=self.site_rss(request, n_posts)) | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
170 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
171 # site atom |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
172 if path == 'atom': |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
173 if n_posts is None: |
58 | 174 n_posts = self.feed_items |
175 return Response(content_type='text/xml', body=self.atom(request, self.blog.latest(self.users.users(), n_posts))) | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
176 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
177 ### help |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
178 if path == 'help' and hasattr(self, 'help'): |
58 | 179 return Response(content_type='text/html', body=self.help) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
180 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
181 ### static files |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
182 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
183 # site.css |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
184 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
|
185 css_file = os.path.join(self.file_dir, 'site.css') |
58 | 186 return FileApp(css_file) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
187 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
188 # logo |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
189 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
|
190 logo = os.path.join(self.file_dir, 'bitsyblog.png') |
20
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
191 if not self.logo(request): |
19
8931c5b7e632
* fixing up index to display [in progress]
k0s <k0scist@gmail.com>
parents:
17
diff
changeset
|
192 raise exc.HTTPNotFound |
58 | 193 return FileApp(logo) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
194 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
195 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:
6
diff
changeset
|
196 """returns a part of the user space""" |
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
197 |
14
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
198 # 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:
6
diff
changeset
|
199 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
|
200 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
201 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:
6
diff
changeset
|
202 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
|
203 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
204 # special paths |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
205 if path == [ 'post' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
206 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
|
207 return check |
58 | 208 return Response(content_type='text/html', body=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
|
209 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
210 if path == [ 'preferences' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
211 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
|
212 return check |
58 | 213 return Response(content_type='text/html', body=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
|
214 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
215 if path == [ 'rss' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
216 feed = 'rss' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
217 path = [] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
218 if n_posts is None: |
58 | 219 n_posts = self.feed_items # TODO: allow to be configurable |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
220 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
221 if path == [ 'atom' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
222 feed = 'atom' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
223 path = [] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
224 if n_posts is None: |
58 | 225 n_posts = self.feed_items # TODO: allow to be configurable |
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 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
|
228 if path[0] == 'css': |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
229 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
|
230 # 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
|
231 if i['filename'] == path[1]: |
58 | 232 return Response(content_type='text/css', body=i['css']) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
233 else: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
234 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
|
235 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
236 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
|
237 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
238 # get the blog |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
239 try: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
240 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
|
241 except BlogPathException, e: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
246 if feed == 'rss': |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
247 content = self.rss(request, user, blog) # XXX different signatures |
58 | 248 return Response(content_type='text/xml', body=content) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
249 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
250 if feed == 'atom': |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
251 content = self.atom(request, blog, user) # XXX different signatures |
58 | 252 return Response(content_type='text/xml', body=content) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
253 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
254 # reverse the blog if necessary |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
255 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
|
256 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
|
257 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
258 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
|
259 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
260 # write the blog |
58 | 261 if request.GET.get('format') == 'text': |
262 content = self.text_blog(blog) | |
263 content_type = 'text/plain' | |
264 else: | |
265 content = self.write_blog(user, blog, request.path_info, n_links, request) | |
266 content_type = 'text/html' | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
267 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
268 # return the content |
58 | 269 return Response(content_type=content_type, body=content) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
270 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
271 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
|
272 """ |
58 | 273 respond to a get request |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
274 """ |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
275 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
276 # front matter of the site |
19
8931c5b7e632
* fixing up index to display [in progress]
k0s <k0scist@gmail.com>
parents:
17
diff
changeset
|
277 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
|
278 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
|
279 return index |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
280 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
281 ### user space |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
282 user, path = self.userpath(request) |
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
283 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
|
284 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
285 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
|
286 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
287 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
|
288 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
289 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
290 # find user + path |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
291 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
|
292 |
23 | 293 # check to make sure the user is authenticated |
25
62c961bb91e6
* allow changing of privacy on blog entries
k0s <k0scist@gmail.com>
parents:
23
diff
changeset
|
294 # and is the resource owner |
23 | 295 check = self.check_user(user, request) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
296 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
|
297 return check |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
298 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
299 if len(path): |
25
62c961bb91e6
* allow changing of privacy on blog entries
k0s <k0scist@gmail.com>
parents:
23
diff
changeset
|
300 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
301 if path == [ 'preferences' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
302 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
303 # 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
|
304 settings = {} |
9 | 305 settings['Date format'] = request.POST.get('Date format') |
306 settings['Subject'] = '%(date)s'.join((request.POST['Subject-0'], request.POST['Subject-2'])) | |
307 settings['Stylesheet'] = request.POST['Stylesheet'] | |
308 settings['CSS file'] = request.POST.get('CSS file') | |
309 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
|
310 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
311 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
|
312 if errors: # re-display form with errors |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
313 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
|
314 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 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
|
319 return exc.HTTPNotFound("Blog entry %s not found %s" % path[0]) |
9 | 320 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
|
321 datestamp = entry.datestamp() |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
322 if privacy: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
323 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
|
324 self.blog.post(user, datestamp, entry.body, privacy) |
23 | 325 return exc.HTTPSeeOther("Settings updated", location=self.user_url(request, user, datestamp)) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
326 else: |
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 # get the body of the post |
9 | 330 body = request.body |
331 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
|
332 body = body.strip() |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
333 if not body: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
334 return exc.HTTPSeeOther("Your post has no content! No blog for you", |
23 | 335 location=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
|
336 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
337 # determine if the post is secret or private |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
338 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
|
339 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
340 # write the file |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
341 now = utils.datestamp(datetime.datetime.now()) |
72
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
342 location = self.user_url(request, user, now, permalink=True) |
70
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
343 blog_entry = self.blog.post(user, now, body, privacy) |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
344 |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
345 # fire event handlers |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
346 # XXX could be done asynchronously |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
347 for handler in self.handlers: |
74
2c219b788648
dont let handlers kill the blog
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
348 try: |
72
c9bab68d00ac
* add handlers argument class default
Jeff Hammel <jhammel@mozilla.com>
parents:
71
diff
changeset
|
349 handler(blog_entry, location) |
74
2c219b788648
dont let handlers kill the blog
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
350 except: |
2c219b788648
dont let handlers kill the blog
Jeff Hammel <jhammel@mozilla.com>
parents:
72
diff
changeset
|
351 pass |
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 # 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
|
354 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
|
355 |
9 | 356 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
|
357 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
358 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
|
359 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
360 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
361 # find user + path |
9 | 362 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
|
363 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
364 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
|
365 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
|
366 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
367 if len(path): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
368 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
|
369 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
370 # 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
|
371 regex = '\[.*\]:' |
9 | 372 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
|
373 dates = [ date.strip().strip(':').strip('[]').strip() |
9 | 374 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
|
375 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
|
376 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
377 # 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
|
378 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
|
379 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
|
380 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
|
381 |
6 | 382 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
|
383 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
384 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
385 def error(self): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
386 """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
|
387 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
|
388 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
|
389 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
|
390 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
391 ### 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
|
392 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
393 def passwords(self): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
394 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
|
395 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
396 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
|
397 """return authenticated user""" |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
398 # XXX needed? |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
399 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
|
400 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
401 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
|
402 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
403 determine authenticated user |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
404 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
|
405 """ |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
406 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
|
407 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
|
408 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
|
409 elif user != authenticated: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
410 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
|
411 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
412 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
|
413 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
414 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
|
415 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
|
416 """ |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
417 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
|
418 if not auth: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
419 return 'public' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
420 if auth == user: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
421 return 'author' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
422 else: |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
423 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
|
424 return 'friend' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
425 else: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
426 return 'public' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
427 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
428 ### user methods |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
429 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
430 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
|
431 """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:
6
diff
changeset
|
432 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
|
433 name = path[0] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
434 path = path[1:] |
14
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
435 if name: |
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
436 if name not in self.users: |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
437 exc.HTTPNotFound("No blog found for %s" % name) |
14
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
438 request.user = self.users[name] |
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
439 else: |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
440 name = None |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
441 return name, path |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
442 |
34 | 443 ### methods for linking and URLs |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
444 |
29
6a1c85adc671
fixing def link for cases of empty path
k0s <k0scist@gmail.com>
parents:
28
diff
changeset
|
445 def link(self, request, path='', permanant=False): |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
446 if isinstance(path, basestring): |
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
447 path = [ path ] |
48
3fe54d84b9be
fix error with single user blog mounted at /
k0s <k0scist@gmail.com>
parents:
36
diff
changeset
|
448 if not path: |
3fe54d84b9be
fix error with single user blog mounted at /
k0s <k0scist@gmail.com>
parents:
36
diff
changeset
|
449 path = [''] |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
450 path = [ i.strip('/') for i in path ] |
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
451 if permanant: |
15 | 452 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
|
453 else: |
15 | 454 application_url = urlparse(request.application_url)[2] |
455 path = [ application_url ] + list(path) | |
456 return '/'.join(path) | |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
457 |
15 | 458 def user_url(self, request, user, *args, **kw): |
459 """link to a user resource""" | |
460 permalink = kw.get('permalink', False) | |
461 path = [ user ] | |
462 path.extend(args) | |
463 return self.link(request, path, permalink) | |
464 | |
465 def permalink(self, request, blogentry): | |
466 """permalink for a blog entry""" | |
467 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
|
468 |
9 | 469 def mangledurl(self, request, blogentry): |
15 | 470 """return a mangled url for obfuscated sharing""" |
9 | 471 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
|
472 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
473 def unmangleurl(self, url, user): |
15 | 474 """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
|
475 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
|
476 try: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
477 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
|
478 except ValueError: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
479 return None |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
480 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
481 # 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
|
482 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
|
483 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
484 entry = str(value) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
485 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
|
486 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
|
487 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
488 ### blog retrival methods |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
489 |
15 | 490 def isentry(self, string): # TODO -> blog.py |
491 """returns whether the string is a blog entry""" | |
492 return (len(string) == len(''.join(utils.timeformat))) and string.isdigit() | |
493 | |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
494 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
|
495 """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
|
496 # 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:
6
diff
changeset
|
497 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
|
498 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
|
499 try: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
500 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
|
501 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
|
502 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
|
503 except (TypeError, ValueError): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
504 n_posts = None |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
505 return n_posts |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
506 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
507 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
|
508 """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:
6
diff
changeset
|
509 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
|
510 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
|
511 return -1 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
512 try: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
513 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
|
514 except (TypeError, ValueError): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
515 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
|
516 return n_links |
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 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
|
519 """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
|
520 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
521 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
|
522 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
523 # get permissions |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
524 allowed = roles[role] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
525 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
526 # entire blog |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
527 if not path: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
528 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
|
529 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
530 # mangled urls |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
531 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
|
532 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
|
533 if entry: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
534 return [ entry ] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
535 else: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
536 raise BlogPathException(notfound) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
537 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
538 # individual blog entry |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
539 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
|
540 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
|
541 if not blog: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
542 raise BlogPathException(notfound) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
543 return [ blog ] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
544 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
545 # 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
|
546 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
|
547 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
|
548 raise BlogPathException(notfound) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
549 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
550 # 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
|
551 try: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
552 [ 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
|
553 except ValueError: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
554 raise BlogPathException(notfound) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
555 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
556 # get the blog |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
557 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
|
558 |
34 | 559 ### methods for markup |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
560 |
17 | 561 def stylesheets(self, request): |
562 user = getattr(request, 'user', None) | |
563 if user: | |
564 stylesheets = request.user['CSS'] | |
565 stylesheets = [ (self.user_url(request, user.name, 'css', css['filename']), | |
566 css['name']) for css in stylesheets ] | |
567 else: | |
568 stylesheets = [(self.link(request, "css/site.css"), "Default")] | |
569 return stylesheets | |
570 | |
571 | |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
572 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
|
573 """returns HTML for site navigation""" |
15 | 574 |
29
6a1c85adc671
fixing def link for cases of empty path
k0s <k0scist@gmail.com>
parents:
28
diff
changeset
|
575 links = [(self.link(request), '/')] |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
576 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
|
577 if user: |
15 | 578 links.extend([(self.user_url(request, user), user), |
20
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
579 (self.user_url(request, user, 'post'), 'post'), |
15 | 580 (self.user_url(request, user, 'preferences'), 'preferences'), |
581 (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
|
582 else: |
15 | 583 links.extend([(self.link(request, 'login'), 'login'), |
584 (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
|
585 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
586 if hasattr(self, 'help'): |
15 | 587 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
|
588 |
15 | 589 request.environ['data']['links'] = links |
590 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
591 |
19
8931c5b7e632
* fixing up index to display [in progress]
k0s <k0scist@gmail.com>
parents:
17
diff
changeset
|
592 def index(self, request, n_links): |
20
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
593 data = request.environ['data'] |
31
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
594 data['n_links'] = n_links |
20
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
595 self.site_nav(request) |
31
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
596 |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
597 # get the blogs |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
598 blogs = {} |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
599 for user in self.users: |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
600 blog = self.blog(user, ('public',), n_links) |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
601 if blog: |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
602 blogs[user] = blog |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
603 users = blogs.keys() |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
604 |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
605 # display latest active user first |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
606 users.sort(key=lambda user: blogs[user][0].date, reverse=True) |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
607 |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
608 data['blogs'] = blogs |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
609 data['users'] = users |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
610 data['date_formats'] = dict([(user, self.users[user].settings.get('Date format', self.date_format)) for user in users]) |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
611 |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
612 # render the template |
20
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
613 template = self.loader.load('index.html') |
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
614 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
|
615 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
616 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
617 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
|
618 """return the user's blog in HTML""" |
15 | 619 |
620 # 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
|
621 for entry in blog: |
15 | 622 if (user, entry.datestamp()) not in self.cooked_bodies: |
623 self.cooked_bodies[(user, entry.datestamp())] = self.cooker(entry.body) | |
624 entry.cooked_body = Markup(self.cooked_bodies[(user, entry.datestamp())]) | |
625 | |
626 # site nav | |
627 # XXX def site_nav() puts directly in request.environ['data'] | |
628 # should return instead | |
629 self.site_nav(request) | |
630 | |
631 # user data -> should be moved up the chain | |
632 data = request.environ['data'] | |
633 data['user'] = user | |
634 data['role'] = self.role(user, request) | |
17 | 635 data['stylesheets'] = self.stylesheets(request) |
15 | 636 data['subject'] = request.user.settings.get('Subject', self.subject) |
637 data['date_format'] = request.user.settings.get('Date format', self.date_format) | |
638 data['mangledurl'] = self.mangledurl | |
639 | |
640 # blog data | |
641 data['blog'] = blog | |
642 data['n_links'] = n_links | |
643 | |
644 # render the template | |
645 template = self.loader.load('blog.html') | |
646 return template.generate(**data).render() | |
58 | 647 |
648 def text_blog(self, blog): | |
649 | |
650 if len(blog) == 1: | |
651 return blog[0].body.strip() + '\n' | |
652 | |
653 buffer = StringIO() | |
654 for entry in blog: | |
655 print >> buffer, '[ %s ]\n' % entry.date.strftime(self.date_format) | |
656 print >> buffer, entry.body.strip() + '\n' | |
657 return buffer.getvalue() | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
658 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
659 def restructuredText(self, string): |
17 | 660 """renders a string with restructured text""" |
661 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
662 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
|
663 string = string.strip() |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
664 try: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
665 |
60 | 666 parts = docutils.core.publish_parts(string, |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
667 writer_name='html', |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
668 settings_overrides=settings) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
669 body = parts['body'] |
66 | 670 except (SystemMessage, UnicodeError), e: |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
671 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
|
672 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
|
673 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
674 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
675 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
|
676 return retval |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
677 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
678 # # XXX this should be reenabled if 'system-message's again appear in the markup |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
679 # try: |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
680 # foo = etree.fromstring(retval) |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
681 # except etree.XMLSyntaxError: |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
682 # return retval |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
683 # # should cleanup the <div class="system-message"> |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
684 # for i in foo.getiterator(): |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
685 # if dict(i.items()).get('class') == 'system-message': |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
686 # i.clear() |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
687 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
688 # return etree.tostring(foo) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
689 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
690 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
691 ### feeds |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
692 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
693 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
|
694 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
|
695 title = self.site_name + ' - rss' |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
696 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
|
697 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
|
698 lastBuildDate = datetime.datetime.now() |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
699 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
|
700 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
|
701 link=link, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
702 description=description, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
703 lastBuildDate=lastBuildDate, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
704 items=items) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
705 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
|
706 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
707 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
|
708 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
709 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
|
710 done with PyRSS2Gen: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
711 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
|
712 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
713 title = "%s's blog" % user |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
714 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
|
715 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
|
716 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
|
717 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
718 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
|
719 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
|
720 link=link, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
721 description=description, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
722 lastBuildDate=lastBuildDate, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
723 items=items) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
724 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
|
725 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
726 def rss_item(self, request, user, entry): |
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
727 if hasattr(request, 'user') and request.user.name == user: |
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
728 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
|
729 else: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
730 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
|
731 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
|
732 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
|
733 title = entry.title() |
31
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
734 link = self.permalink(request, entry) |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
735 return PyRSS2Gen.RSSItem(title=title, |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
736 link=link, |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
737 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
|
738 author=user, |
31
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
739 guid=PyRSS2Gen.Guid(link), |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
740 pubDate=entry.date) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
741 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
742 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
743 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
|
744 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
745 # data for genshi template |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
746 date = blog[0].date.isoformat() |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
747 data = request.environ['data'] |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
748 data['blog'] = blog |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
749 data['author'] = author |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
750 data['date'] = date |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
751 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
752 # render the template |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
753 template = self.loader.load('atom.xml') |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
754 return template.generate(**data).render() |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
755 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
756 |
34 | 757 ### forms |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
758 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
759 def form_post(self, request, user): |
21 | 760 |
761 # genshi data | |
762 self.site_nav(request) | |
763 data = request.environ['data'] | |
764 data['user'] = user | |
765 data['stylesheets'] = self.stylesheets(request) | |
766 | |
767 # render the template | |
768 template = self.loader.load('post.html') | |
769 return template.generate(**data).render() | |
770 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
771 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
772 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
|
773 """user preferences form""" |
26 | 774 |
775 # genshi data | |
776 self.site_nav(request) | |
777 data = request.environ['data'] | |
778 data['user'] = user | |
779 data['stylesheets'] = self.stylesheets(request) | |
780 | |
781 # form data | |
782 prefs = request.user.settings | |
783 data['date_format'] = prefs.get('Date format', self.date_format) | |
784 data['now'] = datetime.datetime.now().strftime(data['date_format']) | |
785 subject = prefs.get('Subject', self.subject) | |
786 data['subject'] = subject.split('%(date)s', 1) | |
787 data['css_files'] = [ i['name'] for i in prefs['CSS' ] ] | |
788 data['users'] = [ i for i in list(self.users.users()) | |
789 if i != user ] | |
790 data['message'] = message | |
28 | 791 data['errors'] = errors or {} |
26 | 792 |
793 # render the template | |
794 template = self.loader.load('preferences.html') | |
795 return template.generate(**data).render() | |
796 | |
0
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 class BitsierBlog(BitsyBlog): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
799 """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
|
800 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
801 def get(self, request): |
9 | 802 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
803 ### user space |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
804 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
|
805 if user not in self.users: |
9 | 806 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
|
807 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
808 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
|
809 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
810 def userpath(self, request): |
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
811 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
|
812 if path == ['']: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
813 path = [] |
14
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
814 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
|
815 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
|
816 |
9 | 817 def user_url(self, request, user, *args, **kw): |
15 | 818 permalink = kw.get('permalink', False) |
819 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
|
820 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
821 def passwords(self): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
822 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
|
823 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
824 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
|
825 """returns HTML for site navigation""" |
15 | 826 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:
6
diff
changeset
|
827 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
|
828 if user: |
15 | 829 links.extend([(self.user_url(request, user, 'post'), 'post'), |
830 (self.user_url(request, user, 'preferences'), 'preferences'), | |
831 (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
|
832 else: |
15 | 833 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
|
834 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
835 if hasattr(self, 'help'): |
15 | 836 links.append((self.link(request, 'help'), 'about')) |
837 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
838 |
15 | 839 request.environ['data']['links'] = links |
840 |