Mercurial > hg > bitsyblog
annotate bitsyblog/factory.py @ 59:0af1f4ae328d
fix a couple of basic things
author | egj@socialplanning.org |
---|---|
date | Mon, 04 Jan 2010 03:12:04 +0000 |
parents | b97d11e2cf41 |
children | f6a6a4b072e7 |
rev | line source |
---|---|
45 | 1 from bitsyauth import BitsyAuth |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
2 from bitsyblog import BitsyBlog, BitsierBlog |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
3 from getpass import getpass |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
4 from paste.httpexceptions import HTTPExceptionHandler |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
5 |
52
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
50
diff
changeset
|
6 # accepted configuration keys, e.g. 'bitsyblog.file_dir' |
58 | 7 config = set(['file_dir', |
8 'date_format', | |
9 'subject', | |
10 'n_links', | |
11 'help_file', | |
12 'header', | |
13 'template_directories', | |
14 'feed_items']) | |
52
3ddb2ca12178
allow for multiple template directories
k0s <k0scist@gmail.com>
parents:
50
diff
changeset
|
15 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
16 def factory(global_conf, **app_conf): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
17 """make bitsyauth app and wrap it in middleware""" |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 key_str = 'bitsyblog.%s' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 args = dict([ (key, app_conf[ key_str % key]) for key in config |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
20 if app_conf.has_key(key_str % key) ]) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
21 app = BitsyBlog(**args) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
22 secret = app_conf.get('secret', 'secret') |
59 | 23 return BitsyAuth(HTTPExceptionHandler(app), |
24 global_conf, | |
25 app.passwords, | |
26 app.newuser, | |
27 'bitsyblog', | |
28 secret) | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
29 |
40 | 30 |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
31 def bitsierfactory(global_conf, **app_conf): |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
32 """make single-user bitsyblog""" |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
33 key_str = 'bitsyblog.%s' |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
34 args = dict([ (key, app_conf[ key_str % key]) for key in config |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
35 if app_conf.has_key(key_str % key) ]) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
36 user = app_conf['bitsyblog.user'] |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
37 app = BitsierBlog(**args) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
38 app.user = user |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
39 secret = app_conf.get('secret', 'secret') |
59 | 40 auth = BitsyAuth(HTTPExceptionHandler(app), |
41 global_conf, | |
42 app.passwords, | |
43 newuser=None, | |
44 site=app_conf.get('site', 'bitsyblog'), | |
45 secret=secret) | |
0
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
46 if not user in app.users: |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
47 pw = getpass('Enter password for %s: ' % user) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
48 app.newuser(user, auth.hash(app.user, pw)) |
e3823be6a423
initial commit of bitsyblog, from https://svn.openplans.org/svn/standalone/bitsyblog/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
49 return auth |