comparison bitsyblog/bitsyblog.py @ 100:f2780e1418bb

STUB: bitsyblog/bitsyblog.py
author Jeff Hammel <k0scist@gmail.com>
date Thu, 30 Jan 2014 19:51:19 -0800
parents 9e1e736958a2
children 83ec14fca36c
comparison
equal deleted inserted replaced
99:8d8f639d563f 100:f2780e1418bb
3 this is the view class and is more bitsyblog than anything 3 this is the view class and is more bitsyblog than anything
4 else can claim to be 4 else can claim to be
5 """ 5 """
6 6
7 ### imports 7 ### imports
8
9 import dateutil.parser 8 import dateutil.parser
10 9
11 import datetime 10 import datetime
12 import docutils 11 import docutils
13 import docutils.core 12 import docutils.core
14 import inspect 13 import inspect
15 import os 14 import os
16 import PyRSS2Gen 15 import PyRSS2Gen
17 import re 16 import re
18 17 import .utils
19 import utils 18 from .blog import FileBlog
20 19 from .roles import roles
21 from blog import FileBlog
22 from cStringIO import StringIO 20 from cStringIO import StringIO
23 from docutils.utils import SystemMessage 21 from docutils.utils import SystemMessage
24 from genshi.builder import Markup 22 from genshi.builder import Markup
25 from genshi.template import TemplateLoader 23 from genshi.template import TemplateLoader
26 from paste.fileapp import FileApp 24 from paste.fileapp import FileApp
28 from pkg_resources import resource_filename 26 from pkg_resources import resource_filename
29 from StringIO import StringIO 27 from StringIO import StringIO
30 from urlparse import urlparse 28 from urlparse import urlparse
31 from webob import Request, Response, exc 29 from webob import Request, Response, exc
32 30
33 from roles import roles
34 31
35 ### exceptions 32 ### exceptions
36 33
37 class BlogPathException(Exception): 34 class BlogPathException(Exception):
38 """exception when trying to retrieve the blog""" 35 """exception when trying to retrieve the blog"""
195 return FileApp(logo) 192 return FileApp(logo)
196 193
197 def get_user_space(self, user, path, request): 194 def get_user_space(self, user, path, request):
198 """returns a part of the user space""" 195 """returns a part of the user space"""
199 196
200 # request.user = self.users[user] # user whose blog is viewed
201 check = self.check_user(user, request) # is this the authenticated user? 197 check = self.check_user(user, request) # is this the authenticated user?
202
203 feed = None # not an rss/atom feed by default (flag) 198 feed = None # not an rss/atom feed by default (flag)
204 n_posts = self.number_of_posts(request, user) 199 n_posts = self.number_of_posts(request, user)
205 n_links = self.number_of_links(request, n_posts, user) 200 n_links = self.number_of_links(request, n_posts, user)
206 201
207 # special paths 202 # special paths
213 if path == [ 'preferences' ]: 208 if path == [ 'preferences' ]:
214 if check is not None: 209 if check is not None:
215 return check 210 return check
216 return Response(content_type='text/html', body=self.preferences(request, user)) 211 return Response(content_type='text/html', body=self.preferences(request, user))
217 212
218 if path == [ 'rss' ]: 213 if path in (['atom'], ['rss']):
219 feed = 'rss' 214 # feeds
220 path = [] 215 feed = path.pop()
221 if n_posts is None: 216 n_posts = n_posts or self.feed_items
222 n_posts = self.feed_items # TODO: allow to be configurable
223
224 if path == [ 'atom' ]:
225 feed = 'atom'
226 path = []
227 if n_posts is None:
228 n_posts = self.feed_items # TODO: allow to be configurable
229 217
230 if len(path) == 2: 218 if len(path) == 2:
231 if path[0] == 'css': 219 if path[0] == 'css':
232 for i in request.user.settings['CSS']: 220 for i in request.user.settings['CSS']:
233 # find the right CSS file 221 # find the right CSS file
277 # front matter of the site 265 # front matter of the site
278 index = self.get_index(request) 266 index = self.get_index(request)
279 if index is not None: 267 if index is not None:
280 return index 268 return index
281 269
282 ### user space 270 # user space
283 user, path = self.userpath(request) 271 user, path = self.userpath(request)
284 return self.get_user_space(user, path, request) 272 return self.get_user_space(user, path, request)
273
285 274
286 ## POST 275 ## POST
287 276
288 def post(self, request): 277 def post(self, request):
289 """ 278 """
350 # fire event handlers 339 # fire event handlers
351 # XXX could be done asynchronously 340 # XXX could be done asynchronously
352 for handler in self.handlers: 341 for handler in self.handlers:
353 try: 342 try:
354 handler(blog_entry, location) 343 handler(blog_entry, location)
355 except: 344 except: # XXX bare except!
356 pass 345 pass
357 346
358 # point the user at the post 347 # point the user at the post
359 return exc.HTTPSeeOther("Post blogged by bitsy", location=location) 348 return exc.HTTPSeeOther("Post blogged by bitsy", location=location)
360 349