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