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