|
a/ForgeWiki/forgewiki/wiki_main.py |
|
b/ForgeWiki/forgewiki/wiki_main.py |
|
... |
|
... |
3 |
from pprint import pformat
|
3 |
from pprint import pformat
|
4 |
from urllib import urlencode, unquote
|
4 |
from urllib import urlencode, unquote
|
5 |
from datetime import datetime
|
5 |
from datetime import datetime
|
6 |
|
6 |
|
7 |
# Non-stdlib imports
|
7 |
# Non-stdlib imports
|
8 |
import pkg_resources
|
|
|
9 |
from tg import expose, validate, redirect, response, flash
|
8 |
from tg import expose, validate, redirect, response, flash
|
10 |
from tg.decorators import with_trailing_slash, without_trailing_slash
|
9 |
from tg.decorators import with_trailing_slash, without_trailing_slash
|
11 |
from tg.controllers import RestController
|
10 |
from tg.controllers import RestController
|
12 |
from pylons import g, c, request
|
11 |
from pylons import g, c, request
|
13 |
from formencode import validators
|
12 |
from formencode import validators
|
14 |
from webob import exc
|
13 |
from webob import exc
|
|
|
14 |
from ming.orm import session
|
15 |
|
15 |
|
16 |
# Pyforge-specific imports
|
16 |
# Pyforge-specific imports
|
17 |
from allura import model as M
|
17 |
from allura import model as M
|
18 |
from allura.lib import helpers as h
|
18 |
from allura.lib import helpers as h
|
19 |
from allura.app import Application, SitemapEntry, DefaultAdminController
|
19 |
from allura.app import Application, SitemapEntry, DefaultAdminController
|
20 |
from allura.lib.search import search
|
20 |
from allura.lib.search import search
|
21 |
from allura.lib.decorators import require_post
|
21 |
from allura.lib.decorators import require_post, Property
|
22 |
from allura.lib.security import require_access, has_access
|
22 |
from allura.lib.security import require_access, has_access
|
23 |
from allura.controllers import AppDiscussionController, BaseController
|
23 |
from allura.controllers import AppDiscussionController, BaseController
|
24 |
from allura.controllers import attachments as ac
|
24 |
from allura.controllers import attachments as ac
|
25 |
from allura.lib import widgets as w
|
25 |
from allura.lib import widgets as w
|
26 |
from allura.lib.widgets import form_fields as ffw
|
26 |
from allura.lib.widgets import form_fields as ffw
|
|
... |
|
... |
84 |
page = WM.Page.upsert(topic)
|
84 |
page = WM.Page.upsert(topic)
|
85 |
except:
|
85 |
except:
|
86 |
log.exception('Error getting artifact %s', topic)
|
86 |
log.exception('Error getting artifact %s', topic)
|
87 |
self.handle_artifact_message(page, message)
|
87 |
self.handle_artifact_message(page, message)
|
88 |
|
88 |
|
89 |
@property
|
89 |
@Property
|
90 |
def root_page_name(self):
|
90 |
def root_page_name():
|
|
|
91 |
def fget(self):
|
91 |
globals = WM.Globals.query.get(app_config_id=self.config._id)
|
92 |
globals = WM.Globals.query.get(app_config_id=self.config._id)
|
92 |
if globals is not None:
|
93 |
if globals is not None:
|
93 |
page_name = globals.root
|
94 |
page_name = globals.root
|
94 |
else:
|
95 |
else:
|
95 |
page_name = self.default_root_page_name
|
96 |
page_name = self.default_root_page_name
|
96 |
return page_name
|
97 |
return page_name
|
|
|
98 |
def fset(self, new_root_page_name):
|
|
|
99 |
globals = WM.Globals.query.get(app_config_id=self.config._id)
|
|
|
100 |
if globals is not None:
|
|
|
101 |
globals.root = new_root_page_name
|
|
|
102 |
elif new_root_page_name != self.default_root_page_name:
|
|
|
103 |
globals = WM.Globals(app_config_id=self.config._id, root=new_root_page_name)
|
|
|
104 |
if globals is not None:
|
|
|
105 |
session(globals).flush()
|
97 |
|
106 |
|
98 |
@property
|
107 |
@Property
|
99 |
def show_discussion(self):
|
108 |
def show_discussion():
|
100 |
if 'show_discussion' in self.config.options:
|
109 |
def fget(self):
|
101 |
return self.config.options['show_discussion']
|
110 |
return self.config.options.get('show_discussion', True)
|
102 |
else:
|
111 |
def fset(self, show):
|
103 |
return True
|
112 |
self.config.options['show_discussion'] = bool(show)
|
104 |
|
113 |
|
105 |
@property
|
114 |
@Property
|
106 |
def show_left_bar(self):
|
115 |
def show_left_bar():
|
107 |
if 'show_left_bar' in self.config.options:
|
116 |
def fget(self):
|
108 |
return self.config.options['show_left_bar']
|
117 |
return self.config.options.get('show_left_bar', True)
|
109 |
else:
|
118 |
def fset(self, show):
|
110 |
return True
|
119 |
self.config.options['show_left_bar'] = bool(show)
|
111 |
|
120 |
|
112 |
@property
|
121 |
@Property
|
113 |
def show_right_bar(self):
|
122 |
def show_right_bar():
|
114 |
if 'show_right_bar' in self.config.options:
|
123 |
def fget(self):
|
115 |
return self.config.options['show_right_bar']
|
124 |
return self.config.options.get('show_right_bar', True)
|
116 |
else:
|
125 |
def fset(self, show):
|
117 |
return True
|
126 |
self.config.options['show_right_bar'] = bool(show)
|
118 |
|
127 |
|
119 |
def main_menu(self):
|
128 |
def main_menu(self):
|
120 |
'''Apps should provide their entries to be added to the main nav
|
129 |
'''Apps should provide their entries to be added to the main nav
|
121 |
:return: a list of :class:`SitemapEntries <allura.app.SitemapEntry>`
|
130 |
:return: a list of :class:`SitemapEntries <allura.app.SitemapEntry>`
|
122 |
'''
|
131 |
'''
|
|
... |
|
... |
157 |
links = links + [
|
166 |
links = links + [
|
158 |
SitemapEntry('Wiki Home',c.app.url),
|
167 |
SitemapEntry('Wiki Home',c.app.url),
|
159 |
SitemapEntry('Browse Pages',c.app.url+'browse_pages/'),
|
168 |
SitemapEntry('Browse Pages',c.app.url+'browse_pages/'),
|
160 |
SitemapEntry('Browse Labels',c.app.url+'browse_tags/')]
|
169 |
SitemapEntry('Browse Labels',c.app.url+'browse_tags/')]
|
161 |
discussion = c.app.config.discussion
|
170 |
discussion = c.app.config.discussion
|
162 |
pending_mod_count = M.Post.query.find({'discussion_id':discussion._id, 'status':'pending'}).count()
|
171 |
pending_mod_count = M.Post.query.find({'discussion_id':discussion._id, 'status':'pending'}).count() if discussion else 0
|
163 |
if pending_mod_count and h.has_access(discussion, 'moderate')():
|
172 |
if pending_mod_count and h.has_access(discussion, 'moderate')():
|
164 |
links.append(SitemapEntry('Moderate', discussion.url() + 'moderate', ui_icon=g.icons['pencil'],
|
173 |
links.append(SitemapEntry('Moderate', discussion.url() + 'moderate', ui_icon=g.icons['pencil'],
|
165 |
small = pending_mod_count))
|
174 |
small = pending_mod_count))
|
166 |
links = links + [SitemapEntry(''),
|
175 |
links = links + [SitemapEntry(''),
|
167 |
SitemapEntry('Markdown Syntax',c.app.url+'markdown_syntax/', className='nav_child')
|
176 |
SitemapEntry('Markdown Syntax',c.app.url+'markdown_syntax/', className='nav_child')
|
|
... |
|
... |
695 |
|
704 |
|
696 |
@without_trailing_slash
|
705 |
@without_trailing_slash
|
697 |
@expose()
|
706 |
@expose()
|
698 |
@require_post()
|
707 |
@require_post()
|
699 |
def set_home(self, new_home):
|
708 |
def set_home(self, new_home):
|
700 |
globals = WM.Globals.query.get(app_config_id=self.app.config._id)
|
709 |
self.app.root_page_name = new_home
|
701 |
if globals is not None:
|
|
|
702 |
globals.root = new_home
|
|
|
703 |
else:
|
|
|
704 |
globals = WM.Globals(app_config_id=self.app.config._id, root=new_home)
|
|
|
705 |
self.app.upsert_root(new_home)
|
710 |
self.app.upsert_root(new_home)
|
706 |
flash('Home updated')
|
711 |
flash('Home updated')
|
707 |
redirect(c.project.url()+self.app.config.options.mount_point+'/'+new_home+'/')
|
712 |
redirect(c.project.url()+self.app.config.options.mount_point+'/'+new_home+'/')
|
708 |
|
713 |
|
709 |
@without_trailing_slash
|
714 |
@without_trailing_slash
|
710 |
@expose()
|
715 |
@expose()
|
711 |
@require_post()
|
716 |
@require_post()
|
712 |
def set_options(self, show_discussion=False, show_left_bar=False, show_right_bar=False):
|
717 |
def set_options(self, show_discussion=False, show_left_bar=False, show_right_bar=False):
|
713 |
if show_discussion:
|
|
|
714 |
show_discussion = True
|
|
|
715 |
if show_left_bar:
|
|
|
716 |
show_left_bar = True
|
|
|
717 |
if show_right_bar:
|
|
|
718 |
show_right_bar = True
|
|
|
719 |
self.app.config.options['show_discussion'] = show_discussion
|
718 |
self.app.show_discussion = show_discussion
|
720 |
self.app.config.options['show_left_bar'] = show_left_bar
|
719 |
self.app.show_left_bar = show_left_bar
|
721 |
self.app.config.options['show_right_bar'] = show_right_bar
|
720 |
self.app.show_right_bar = show_right_bar
|
722 |
flash('Wiki options updated')
|
721 |
flash('Wiki options updated')
|
723 |
redirect(c.project.url()+'admin/tools')
|
722 |
redirect(c.project.url()+'admin/tools')
|