Mercurial > hg > bitsyblog
annotate bitsyblog/bitsyblog.py @ 71:0c98d1c2c6df
fix syntax errors
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 08 Jul 2010 10:40:43 -0700 |
parents | f6a6a4b072e7 |
children | c9bab68d00ac |
rev | line source |
---|---|
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
1 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
2 a tiny tiny blog. |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
3 this is the view class and is more bitsyblog than anything |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
4 else can claim to be |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
5 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
6 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
7 ### global variables |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
8 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
9 ### imports |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
10 |
28 | 11 import dateutil.parser |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
12 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
13 import cgi |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
14 import datetime |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
15 import docutils |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
16 import docutils.core |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
17 import inspect |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 import os |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 import PyRSS2Gen |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
20 import re |
4 | 21 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
22 import utils |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
23 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
24 from blog import FileBlog |
4 | 25 from cStringIO import StringIO |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
26 from docutils.utils import SystemMessage |
15 | 27 from genshi.builder import Markup |
9 | 28 from genshi.template import TemplateLoader |
58 | 29 from paste.fileapp import FileApp |
71 | 30 from pkg_resources import iter_entry_points |
6 | 31 from pkg_resources import resource_filename |
58 | 32 from StringIO import StringIO |
15 | 33 from urlparse import urlparse |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
34 from webob import Request, Response, exc |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
35 |
59 | 36 from roles import roles |
37 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
38 ### exceptions |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
39 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
40 class BlogPathException(Exception): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
41 """exception when trying to retrieve the blog""" |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
42 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
43 ### the main course |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
44 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
45 class BitsyBlog(object): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
46 """a very tiny blog""" |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
47 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
48 ### class level variables |
58 | 49 defaults = { 'date_format': '%H:%M %F', # default date format |
50 'file_dir': os.path.dirname(__file__), # where the blog is kept | |
51 'subject': '[ %(date)s ]:', # default subject | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
52 'n_links': 5, # number of links for navigation |
58 | 53 'site_name': 'bitsyblog', # name of the site (needed?) |
54 'header': None, # text to insert as first child of body' | |
55 'template_directories': '', # space separated template_directories | |
56 'auto_reload': 'True', # reload the genshi templates | |
57 'help_file': None, # help to display | |
58 'feed_items': 10, # number of RSS/atom items to display | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
59 } |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
60 |
15 | 61 |
62 cooked_bodies = {} | |
63 | |
70
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 'POST': self.post, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
70 'PUT': self.put |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
71 } |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
72 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
73 # abstract attributes |
59 | 74 from user import FilespaceUsers |
75 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
76 self.users = FilespaceUsers(self.file_dir) |
71 | 77 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
|
78 self.cooker = self.restructuredText |
58 | 79 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
|
80 |
9 | 81 # template renderer |
52
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
82 self.auto_reload = self.auto_reload.lower()=='true' |
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
83 self.template_directories = self.template_directories.split() # no spaces in directory names, for now |
63 | 84 |
85 for directory in self.template_directories: | |
86 assert os.path.isdir(directory), "Bitsyblog template directory %s does not exist!" % directory | |
87 | |
52
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
88 self.template_directories.append(resource_filename(__name__, 'templates')) |
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
89 self.loader = TemplateLoader(self.template_directories, |
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
90 auto_reload=self.auto_reload) |
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
51
diff
changeset
|
91 |
9 | 92 |
93 # helpfile | |
3 | 94 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
|
95 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
|
96 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
|
97 writer_name='html', |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
98 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
|
99 |
50 | 100 # header |
101 if self.header: | |
51 | 102 if os.path.exists(self.header): |
103 self.header = file(self.header).read() | |
50 | 104 self.header = Markup(self.header) |
105 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
106 # for BitsyAuth |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
107 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
|
108 |
70
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
109 # post handlers |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
110 self.handlers = [] # handlers for blog post event |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
111 for entry_point in iter_entry_points('bitsyblog.listeners'): |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
112 try: |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
113 handler = entry_point.load()(self, **handler_args.get(entry_point.name, {})) |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
114 self.handlers.append(handler) |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
115 except: |
71 | 116 print 'Cant load entry point %s' % entry_point.name |
70
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
117 continue |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
118 |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
119 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
120 ### 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
|
121 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
122 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
|
123 request = Request(environ) |
27 | 124 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
125 # genshi data dictionary |
27 | 126 request.environ['data'] = { 'site_name': self.site_name, |
127 'request': request, | |
128 'link': self.link, | |
31
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
129 'logo': self.logo(request), |
50 | 130 'header': self.header, |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
131 'user_url': self.user_url, |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
132 'permalink': self.permalink } |
27 | 133 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
134 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
|
135 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
|
136 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
137 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
|
138 # 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
|
139 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
|
140 return res |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
141 |
20
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
142 def logo(self, request): |
34 | 143 """link to the logo""" |
20
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
144 _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
|
145 logo = os.path.join(self.file_dir, _logo) |
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
146 if os.path.exists(logo): |
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
147 return self.link(request, _logo) |
1554cb56aa2f
got index working, just doesnt do anything
k0s <k0scist@gmail.com>
parents:
19
diff
changeset
|
148 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
149 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
|
150 """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
|
151 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
152 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
|
153 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
|
154 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
155 ### the front page |
19
8931c5b7e632
* fixing up index to display [in progress]
k0s <k0scist@gmail.com>
parents:
17
diff
changeset
|
156 if not path: |
58 | 157 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
|
158 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
159 ### feeds |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
160 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
161 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
|
162 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
163 # site rss |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
164 if path == 'rss': |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
165 if n_posts is None: |
58 | 166 n_posts = self.feed_items |
167 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
|
168 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
169 # site atom |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
170 if path == 'atom': |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
171 if n_posts is None: |
58 | 172 n_posts = self.feed_items |
173 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
|
174 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
175 ### help |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
176 if path == 'help' and hasattr(self, 'help'): |
58 | 177 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
|
178 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
179 ### static files |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
180 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
181 # site.css |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
182 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
|
183 css_file = os.path.join(self.file_dir, 'site.css') |
58 | 184 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
|
185 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
186 # logo |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
187 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
|
188 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
|
189 if not self.logo(request): |
19
8931c5b7e632
* fixing up index to display [in progress]
k0s <k0scist@gmail.com>
parents:
17
diff
changeset
|
190 raise exc.HTTPNotFound |
58 | 191 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
|
192 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
193 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
|
194 """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
|
195 |
14
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
196 # 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
|
197 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
|
198 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
199 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
|
200 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
|
201 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
202 # special paths |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
203 if path == [ 'post' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
204 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
|
205 return check |
58 | 206 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
|
207 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
208 if path == [ 'preferences' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
209 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
|
210 return check |
58 | 211 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
|
212 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
213 if path == [ 'rss' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
214 feed = 'rss' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
215 path = [] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
216 if n_posts is None: |
58 | 217 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
|
218 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
219 if path == [ 'atom' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
220 feed = 'atom' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
221 path = [] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
222 if n_posts is None: |
58 | 223 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
|
224 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 # 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
|
229 if i['filename'] == path[1]: |
58 | 230 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
|
231 else: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
232 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
|
233 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
234 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
|
235 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
236 # get the blog |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
237 try: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
238 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
|
239 except BlogPathException, e: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
240 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
|
241 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
|
242 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
|
243 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
244 if feed == 'rss': |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
245 content = self.rss(request, user, blog) # XXX different signatures |
58 | 246 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
|
247 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
248 if feed == 'atom': |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
249 content = self.atom(request, blog, user) # XXX different signatures |
58 | 250 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
|
251 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
252 # 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
|
253 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
|
254 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
|
255 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
256 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
|
257 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
258 # write the blog |
58 | 259 if request.GET.get('format') == 'text': |
260 content = self.text_blog(blog) | |
261 content_type = 'text/plain' | |
262 else: | |
263 content = self.write_blog(user, blog, request.path_info, n_links, request) | |
264 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
|
265 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
266 # return the content |
58 | 267 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
|
268 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
269 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
|
270 """ |
58 | 271 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
|
272 """ |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
273 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
274 # front matter of the site |
19
8931c5b7e632
* fixing up index to display [in progress]
k0s <k0scist@gmail.com>
parents:
17
diff
changeset
|
275 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
|
276 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
|
277 return index |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
278 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
279 ### user space |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
280 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
|
281 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
|
282 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
283 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
|
284 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
285 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
|
286 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
287 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
288 # find user + path |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
289 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
|
290 |
23 | 291 # 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
|
292 # and is the resource owner |
23 | 293 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
|
294 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
|
295 return check |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
296 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
297 if len(path): |
25
62c961bb91e6
* allow changing of privacy on blog entries
k0s <k0scist@gmail.com>
parents:
23
diff
changeset
|
298 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
299 if path == [ 'preferences' ]: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
300 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
301 # 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
|
302 settings = {} |
9 | 303 settings['Date format'] = request.POST.get('Date format') |
304 settings['Subject'] = '%(date)s'.join((request.POST['Subject-0'], request.POST['Subject-2'])) | |
305 settings['Stylesheet'] = request.POST['Stylesheet'] | |
306 settings['CSS file'] = request.POST.get('CSS file') | |
307 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
|
308 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
309 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
|
310 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
|
311 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
|
312 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
313 return self.get_response(self.preferences(request, user, 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
|
314 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
|
315 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
|
316 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
|
317 return exc.HTTPNotFound("Blog entry %s not found %s" % path[0]) |
9 | 318 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
|
319 datestamp = entry.datestamp() |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
320 if privacy: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
321 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
|
322 self.blog.post(user, datestamp, entry.body, privacy) |
23 | 323 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
|
324 else: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
325 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
|
326 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
327 # get the body of the post |
9 | 328 body = request.body |
329 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
|
330 body = body.strip() |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
331 if not body: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
332 return exc.HTTPSeeOther("Your post has no content! No blog for you", |
23 | 333 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
|
334 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
335 # 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
|
336 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
|
337 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
338 # write the file |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
339 now = utils.datestamp(datetime.datetime.now()) |
23 | 340 location = self.user_url(request, user, now) |
70
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
341 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
|
342 |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
343 # fire event handlers |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
344 # XXX could be done asynchronously |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
345 for handler in self.handlers: |
f6a6a4b072e7
complete overhaul to allow event handlers
Jeff Hammel <jhammel@mozilla.com>
parents:
66
diff
changeset
|
346 handler(blog_entry) |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
347 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
348 # 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
|
349 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
|
350 |
9 | 351 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
|
352 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
353 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
|
354 """ |
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 # find user + path |
9 | 357 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
|
358 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
359 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
|
360 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
|
361 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
362 if len(path): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
363 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
|
364 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
365 # 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
|
366 regex = '\[.*\]:' |
9 | 367 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
|
368 dates = [ date.strip().strip(':').strip('[]').strip() |
9 | 369 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
|
370 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
|
371 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
372 # 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
|
373 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
|
374 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
|
375 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
|
376 |
6 | 377 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
|
378 |
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 def error(self): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
381 """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
|
382 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
|
383 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
|
384 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
|
385 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
386 ### 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
|
387 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
388 def passwords(self): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
389 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
|
390 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
391 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
|
392 """return authenticated user""" |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
393 # XXX needed? |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
394 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
|
395 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
396 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
|
397 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
398 determine authenticated user |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
399 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
|
400 """ |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 elif user != authenticated: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
405 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
|
406 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
407 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
|
408 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
409 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
|
410 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
|
411 """ |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
412 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
|
413 if not auth: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
414 return 'public' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
415 if auth == user: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
416 return 'author' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
417 else: |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
418 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
|
419 return 'friend' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
420 else: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
421 return 'public' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
422 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
423 ### user methods |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
424 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
425 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
|
426 """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
|
427 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
|
428 name = path[0] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
429 path = path[1:] |
14
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
430 if name: |
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
431 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
|
432 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
|
433 request.user = self.users[name] |
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
434 else: |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
435 name = None |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
436 return name, path |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
437 |
34 | 438 ### 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
|
439 |
29
6a1c85adc671
fixing def link for cases of empty path
k0s <k0scist@gmail.com>
parents:
28
diff
changeset
|
440 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
|
441 if isinstance(path, basestring): |
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
442 path = [ path ] |
48
3fe54d84b9be
fix error with single user blog mounted at /
k0s <k0scist@gmail.com>
parents:
36
diff
changeset
|
443 if not path: |
3fe54d84b9be
fix error with single user blog mounted at /
k0s <k0scist@gmail.com>
parents:
36
diff
changeset
|
444 path = [''] |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
445 path = [ i.strip('/') for i in path ] |
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
446 if permanant: |
15 | 447 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
|
448 else: |
15 | 449 |
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') | |
642 return template.generate(**data).render() | |
58 | 643 |
644 def text_blog(self, blog): | |
645 | |
646 if len(blog) == 1: | |
647 return blog[0].body.strip() + '\n' | |
648 | |
649 buffer = StringIO() | |
650 for entry in blog: | |
651 print >> buffer, '[ %s ]\n' % entry.date.strftime(self.date_format) | |
652 print >> buffer, entry.body.strip() + '\n' | |
653 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
|
654 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
655 def restructuredText(self, string): |
17 | 656 """renders a string with restructured text""" |
657 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
658 settings = { 'report_level': 5 } |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
659 string = string.strip() |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
660 try: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
661 |
60 | 662 parts = docutils.core.publish_parts(string, |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
663 writer_name='html', |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
664 settings_overrides=settings) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
665 body = parts['body'] |
66 | 666 except (SystemMessage, UnicodeError), e: |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
667 lines = [ cgi.escape(i.strip()) for i in string.split('\n') ] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
668 body = '<br/>\n'.join(lines) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
669 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
670 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
671 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
|
672 return retval |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
673 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
674 # # 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
|
675 # try: |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
676 # foo = etree.fromstring(retval) |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
677 # except etree.XMLSyntaxError: |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
678 # return retval |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
679 # # 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
|
680 # for i in foo.getiterator(): |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
681 # 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
|
682 # i.clear() |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
683 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
684 # 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
|
685 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
686 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
687 ### feeds |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
688 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
689 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
|
690 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
|
691 title = self.site_name + ' - rss' |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
692 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
|
693 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
|
694 lastBuildDate = datetime.datetime.now() |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
695 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
|
696 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
|
697 link=link, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
698 description=description, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
699 lastBuildDate=lastBuildDate, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
700 items=items) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
701 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
|
702 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
703 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
|
704 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
705 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
|
706 done with PyRSS2Gen: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
707 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
|
708 """ |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
709 title = "%s's blog" % user |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
714 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
|
715 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
|
716 link=link, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
717 description=description, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
718 lastBuildDate=lastBuildDate, |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
719 items=items) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
720 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
|
721 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
722 def rss_item(self, request, user, entry): |
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
723 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
|
724 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
|
725 else: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
726 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
|
727 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
|
728 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
|
729 title = entry.title() |
31
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
730 link = self.permalink(request, entry) |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
731 return PyRSS2Gen.RSSItem(title=title, |
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
732 link=link, |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
733 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
|
734 author=user, |
31
4ac11f7992c6
index page now works and so does rss
k0s <k0scist@gmail.com>
parents:
29
diff
changeset
|
735 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
|
736 pubDate=entry.date) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
737 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
738 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
739 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
|
740 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
741 # data for genshi template |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
742 date = blog[0].date.isoformat() |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
743 data = request.environ['data'] |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
744 data['blog'] = blog |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
745 data['author'] = author |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
746 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
|
747 |
35
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
748 # render the template |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
749 template = self.loader.load('atom.xml') |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
750 return template.generate(**data).render() |
7e7fbdc64cc1
enable atom support, this brings us to 2.0
k0s <k0scist@gmail.com>
parents:
34
diff
changeset
|
751 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
752 |
34 | 753 ### forms |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
754 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
755 def form_post(self, request, user): |
21 | 756 |
757 # genshi data | |
758 self.site_nav(request) | |
759 data = request.environ['data'] | |
760 data['user'] = user | |
761 data['stylesheets'] = self.stylesheets(request) | |
762 | |
763 # render the template | |
764 template = self.loader.load('post.html') | |
765 return template.generate(**data).render() | |
766 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
767 |
12
dd8c1c8ae0da
more removing of self.request and general cleanup
k0s <k0scist@gmail.com>
parents:
9
diff
changeset
|
768 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
|
769 """user preferences form""" |
26 | 770 |
771 # genshi data | |
772 self.site_nav(request) | |
773 data = request.environ['data'] | |
774 data['user'] = user | |
775 data['stylesheets'] = self.stylesheets(request) | |
776 | |
777 # form data | |
778 prefs = request.user.settings | |
779 data['date_format'] = prefs.get('Date format', self.date_format) | |
780 data['now'] = datetime.datetime.now().strftime(data['date_format']) | |
781 subject = prefs.get('Subject', self.subject) | |
782 data['subject'] = subject.split('%(date)s', 1) | |
783 data['css_files'] = [ i['name'] for i in prefs['CSS' ] ] | |
784 data['users'] = [ i for i in list(self.users.users()) | |
785 if i != user ] | |
786 data['message'] = message | |
28 | 787 data['errors'] = errors or {} |
26 | 788 |
789 # render the template | |
790 template = self.loader.load('preferences.html') | |
791 return template.generate(**data).render() | |
792 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
793 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
794 class BitsierBlog(BitsyBlog): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
795 """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
|
796 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
797 def get(self, request): |
9 | 798 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
799 ### user space |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
800 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
|
801 if user not in self.users: |
9 | 802 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
|
803 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
804 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
|
805 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
806 def userpath(self, request): |
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
807 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
|
808 if path == ['']: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
809 path = [] |
14
645aa0f3279f
userland refactoring...still lives on request, sadly, but better
k0s <k0scist@gmail.com>
parents:
12
diff
changeset
|
810 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
|
811 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
|
812 |
9 | 813 def user_url(self, request, user, *args, **kw): |
15 | 814 permalink = kw.get('permalink', False) |
815 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
|
816 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
817 def passwords(self): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
818 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
|
819 |
7
57a45adf33d4
separate out request from self. ultimately a new object should be
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
820 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
|
821 """returns HTML for site navigation""" |
15 | 822 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
|
823 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
|
824 if user: |
15 | 825 links.extend([(self.user_url(request, user, 'post'), 'post'), |
826 (self.user_url(request, user, 'preferences'), 'preferences'), | |
827 (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
|
828 else: |
15 | 829 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
|
830 |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
831 if hasattr(self, 'help'): |
15 | 832 links.append((self.link(request, 'help'), 'about')) |
833 | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
834 |
15 | 835 request.environ['data']['links'] = links |
836 |