allura
Revisión | e1c74dfb8a9a750a752ddf4796eb2dadbbc71848 (tree) |
---|---|
Tiempo | 2012-05-17 07:18:18 |
Autor | bolkimen <bolkimen@yaho...> |
Commiter | Cory Johns |
ticket:48 finish site path for feed list edit
@@ -12,12 +12,14 @@ from pylons import g, c, request, response | ||
12 | 12 | from formencode import validators |
13 | 13 | from webob import exc |
14 | 14 | |
15 | +from ming.orm import session | |
16 | + | |
15 | 17 | # Pyforge-specific imports |
16 | 18 | from allura.app import Application, ConfigOption, SitemapEntry |
17 | 19 | from allura.app import DefaultAdminController |
18 | 20 | from allura.lib import helpers as h |
19 | 21 | from allura.lib.search import search |
20 | -from allura.lib.decorators import require_post | |
22 | +from allura.lib.decorators import require_post, Property | |
21 | 23 | from allura.lib.security import has_access, require_access |
22 | 24 | from allura.lib import widgets as w |
23 | 25 | from allura.lib.widgets.subscriptions import SubscribeForm |
@@ -56,6 +58,7 @@ class ForgeBlogApp(Application): | ||
56 | 58 | ordinal=14 |
57 | 59 | installable=True |
58 | 60 | config_options = Application.config_options |
61 | + default_external_feeds = [] | |
59 | 62 | icons={ |
60 | 63 | 24:'images/blog_24.png', |
61 | 64 | 32:'images/blog_32.png', |
@@ -67,6 +70,24 @@ class ForgeBlogApp(Application): | ||
67 | 70 | self.root = RootController() |
68 | 71 | self.admin = BlogAdminController(self) |
69 | 72 | |
73 | + @Property | |
74 | + def external_feeds_list(): | |
75 | + def fget(self): | |
76 | + globals = BM.Globals.query.get(app_config_id=self.config._id) | |
77 | + if globals is not None: | |
78 | + external_feeds = globals.external_feeds | |
79 | + else: | |
80 | + external_feeds = self.default_external_feeds | |
81 | + return external_feeds | |
82 | + def fset(self, new_external_feeds): | |
83 | + globals = BM.Globals.query.get(app_config_id=self.config._id) | |
84 | + if globals is not None: | |
85 | + globals.external_feeds = new_external_feeds | |
86 | + elif len(new_external_feeds) > 0: | |
87 | + globals = BM.Globals(app_config_id=self.config._id, root=new_external_feeds) | |
88 | + if globals is not None: | |
89 | + session(globals).flush() | |
90 | + | |
70 | 91 | @property |
71 | 92 | @h.exceptionless([], log) |
72 | 93 | def sitemap(self): |
@@ -94,7 +115,11 @@ class ForgeBlogApp(Application): | ||
94 | 115 | return links |
95 | 116 | |
96 | 117 | def admin_menu(self): |
97 | - return super(ForgeBlogApp, self).admin_menu(force_options=True) | |
118 | + admin_url = c.project.url() + 'admin/' + self.config.options.mount_point + '/' | |
119 | + links = [SitemapEntry('External feeds', admin_url + 'exfeed', className='admin_modal')] | |
120 | + links += super(ForgeBlogApp, self).admin_menu(force_options=True) | |
121 | + return links | |
122 | + #return super(ForgeBlogApp, self).admin_menu(force_options=True) | |
98 | 123 | |
99 | 124 | def install(self, project): |
100 | 125 | 'Set up any default permissions and roles here' |
@@ -359,3 +384,34 @@ class BlogAdminController(DefaultAdminController): | ||
359 | 384 | self.app.config.options['show_discussion'] = show_discussion and True or False |
360 | 385 | flash('Blog options updated') |
361 | 386 | redirect(h.really_unicode(c.project.url()+'admin/tools').encode('utf-8')) |
387 | + | |
388 | + @without_trailing_slash | |
389 | + @expose('jinja:forgeblog:templates/blog/admin_exfeed.html') | |
390 | + def exfeed(self): | |
391 | + #self.app.external_feeds_list = ['feed1', 'feed2'] | |
392 | + #log.info("EXFEED: %s" % self.app.external_feeds_list) | |
393 | + feeds_list = [] | |
394 | + for feed in self.app.external_feeds_list: | |
395 | + feeds_list.append(feed) | |
396 | + return dict(app=self.app, | |
397 | + feeds_list=feeds_list, | |
398 | + allow_config=has_access(self.app, 'configure')()) | |
399 | + | |
400 | + @without_trailing_slash | |
401 | + @expose() | |
402 | + @require_post() | |
403 | + def set_exfeed(self, **kw): | |
404 | + new_exfeed = kw.get('new_exfeed', None) | |
405 | + exfeed_val = kw.get('exfeed', []) | |
406 | + if type(exfeed_val) == unicode: | |
407 | + exfeed_list = [] | |
408 | + exfeed_list.append(exfeed_val) | |
409 | + else: | |
410 | + exfeed_list = exfeed_val | |
411 | + | |
412 | + if new_exfeed is not None and new_exfeed != '': | |
413 | + exfeed_list.append(new_exfeed) | |
414 | + | |
415 | + self.app.external_feeds_list = exfeed_list | |
416 | + flash('External feeds updated') | |
417 | + redirect(c.project.url()+'admin/tools') |
@@ -1 +1 @@ | ||
1 | -from blog import BlogPost, Attachment, BlogPostSnapshot | |
1 | +from blog import Globals, BlogPost, Attachment, BlogPostSnapshot |
@@ -9,6 +9,8 @@ from pymongo.errors import DuplicateKeyError | ||
9 | 9 | |
10 | 10 | from ming import schema |
11 | 11 | from ming.orm import FieldProperty, ForeignIdProperty, Mapper, session, state |
12 | +from ming.orm.declarative import MappedClass | |
13 | + | |
12 | 14 | from allura import model as M |
13 | 15 | from allura.lib import helpers as h |
14 | 16 | from allura.lib import utils, patience |
@@ -16,6 +18,19 @@ from allura.lib import utils, patience | ||
16 | 18 | config = utils.ConfigProxy( |
17 | 19 | common_suffix='forgemail.domain') |
18 | 20 | |
21 | +class Globals(MappedClass): | |
22 | + | |
23 | + class __mongometa__: | |
24 | + name = 'blog-globals' | |
25 | + session = M.project_orm_session | |
26 | + indexes = [ 'app_config_id' ] | |
27 | + | |
28 | + type_s = 'BlogGlobals' | |
29 | + _id = FieldProperty(schema.ObjectId) | |
30 | + app_config_id = ForeignIdProperty('AppConfig', if_missing=lambda:context.app.config._id) | |
31 | + external_feeds=FieldProperty([str]) | |
32 | + | |
33 | + | |
19 | 34 | class BlogPostSnapshot(M.Snapshot): |
20 | 35 | class __mongometa__: |
21 | 36 | name='blog_post_snapshot' |
@@ -0,0 +1,27 @@ | ||
1 | +<form method="POST" action="{{c.project.url()}}admin/{{app.config.options.mount_point}}/set_exfeed"> | |
2 | + <label class="grid-13">Existing external feeds:</label> | |
3 | + <div class="grid-13"> | |
4 | + <ul> | |
5 | + {% if allow_config %} | |
6 | + {% for feed in feeds_list %} | |
7 | + <li><input type="checkbox" name="exfeed" value="{{ feed }}" checked="checked"><span>{{ feed }}</span></li> | |
8 | + {% endfor %} | |
9 | + {% else %} | |
10 | + {% for feed in feeds_list %} | |
11 | + <li><span>{{ feed.value }}</span></li> | |
12 | + {% endfor %} | |
13 | + {% endif %} | |
14 | + </div> | |
15 | + {% if allow_config %} | |
16 | + <div class="grid-13"> </div> | |
17 | + <div class="grid-13"> | |
18 | + <input type="text" name="new_exfeed" id="new_exfeed" value=""/> | |
19 | + </div> | |
20 | + <div class="grid-13"> </div> | |
21 | + <hr> | |
22 | + <div class="grid-13"> </div> | |
23 | + <div class="grid-13"> | |
24 | + <input type="submit" value="Save"/> | |
25 | + </div> | |
26 | + {% endif %} | |
27 | +</form> |