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