allura
修訂 | 3bd73827e847f98752873cca3b28c093137a920f (tree) |
---|---|
時間 | 2010-05-22 03:09:10 |
作者 | Rick Copeland <rcopeland@geek...> |
Commiter | Rick Copeland |
[#425] - Fix more 500 errors, fix semantics of contextmanager, trap exceptions in sidebar_menu()
@@ -1,4 +1,5 @@ | ||
1 | 1 | import difflib |
2 | +import logging | |
2 | 3 | from pprint import pformat |
3 | 4 | from collections import defaultdict |
4 | 5 | from mimetypes import guess_type |
@@ -20,6 +21,8 @@ from pyforge import model as M | ||
20 | 21 | from pyforge.lib.security import require, has_project_access |
21 | 22 | from pyforge.lib.widgets import form_fields as ffw |
22 | 23 | |
24 | +log = logging.getLogger(__name__) | |
25 | + | |
23 | 26 | class W: |
24 | 27 | markdown_editor = ffw.MarkdownEdit() |
25 | 28 | label_edit = ffw.LabelEdit() |
@@ -70,6 +73,7 @@ class AdminApp(Application): | ||
70 | 73 | self.templates = pkg_resources.resource_filename('pyforge.ext.admin', 'templates') |
71 | 74 | self.sitemap = [ SitemapEntry('Admin','.')] |
72 | 75 | |
76 | + @h.exceptionless([], log) | |
73 | 77 | def sidebar_menu(self): |
74 | 78 | admin_url = c.project.url()+'admin/' |
75 | 79 | links = [SitemapEntry('Project'), |
@@ -121,7 +125,8 @@ class ProjectAdminController(object): | ||
121 | 125 | def overview(self): |
122 | 126 | c.markdown_editor = W.markdown_editor |
123 | 127 | c.label_edit = W.label_edit |
124 | - return dict(categories=M.ProjectCategory.query.find(dict(parent_id=None)).sort('label').all()) | |
128 | + categories = M.ProjectCategory.query.find(dict(parent_id=None)).sort('label').all() | |
129 | + return dict(categories=categories) | |
125 | 130 | |
126 | 131 | @without_trailing_slash |
127 | 132 | @expose('pyforge.ext.admin.templates.project_tools') |
@@ -44,6 +44,7 @@ class ProjectHomeApp(Application): | ||
44 | 44 | return [ |
45 | 45 | SitemapEntry('Home', '.') ] |
46 | 46 | |
47 | + @h.exceptionless([], log) | |
47 | 48 | def sidebar_menu(self): |
48 | 49 | return [ SitemapEntry('Configure', 'configuration')] |
49 | 50 |
@@ -135,8 +135,10 @@ def fake_pylons_context(request): | ||
135 | 135 | pylons.c._push_object(MagicalC(EmptyClass(), environ)) |
136 | 136 | pylons.g._push_object(Globals()) |
137 | 137 | pylons.request._push_object(request) |
138 | - yield | |
139 | - pylons.c._pop_object() | |
140 | - pylons.g._pop_object() | |
141 | - pylons.request._pop_object() | |
138 | + try: | |
139 | + yield | |
140 | + finally: | |
141 | + pylons.c._pop_object() | |
142 | + pylons.g._pop_object() | |
143 | + pylons.request._pop_object() | |
142 | 144 |
@@ -44,6 +44,7 @@ class UserProfileApp(Application): | ||
44 | 44 | menu_id = 'User' |
45 | 45 | return [] |
46 | 46 | |
47 | + @h.exceptionless([], log) | |
47 | 48 | def sidebar_menu(self): |
48 | 49 | return [ SitemapEntry('Preferences', '/auth/prefs/')] |
49 | 50 |
@@ -172,9 +172,11 @@ def fake_pylons_context(request): | ||
172 | 172 | pylons.c._push_object(MagicalC(EmptyClass(), environ)) |
173 | 173 | pylons.g._push_object(Globals()) |
174 | 174 | pylons.request._push_object(request) |
175 | - yield | |
176 | - pylons.c._pop_object() | |
177 | - pylons.g._pop_object() | |
178 | - pylons.request._pop_object() | |
175 | + try: | |
176 | + yield | |
177 | + finally: | |
178 | + pylons.c._pop_object() | |
179 | + pylons.g._pop_object() | |
180 | + pylons.request._pop_object() | |
179 | 181 | |
180 | 182 | on_import() |
@@ -77,11 +77,14 @@ def push_config(obj, **kw): | ||
77 | 77 | except AttributeError: |
78 | 78 | new_attrs.append(k) |
79 | 79 | setattr(obj, k, v) |
80 | - yield obj | |
81 | - for k,v in saved_attrs.iteritems(): | |
82 | - setattr(obj, k, v) | |
83 | - for k in new_attrs: | |
84 | - delattr(obj, k) | |
80 | + try: | |
81 | + yield obj | |
82 | + finally: | |
83 | + for k,v in saved_attrs.iteritems(): | |
84 | + setattr(obj, k, v) | |
85 | + for k in new_attrs: | |
86 | + delattr(obj, k) | |
87 | + | |
85 | 88 | |
86 | 89 | def mixin_reactors(cls, module, prefix=None): |
87 | 90 | 'attach the reactor-decorated functions in module to the given class' |
@@ -117,15 +120,17 @@ def push_context(project_id, mount_point=None, app_config_id=None): | ||
117 | 120 | project = getattr(c, 'project', ()) |
118 | 121 | app = getattr(c, 'app', ()) |
119 | 122 | set_context(project_id, mount_point, app_config_id) |
120 | - yield | |
121 | - if project == (): | |
122 | - del c.project | |
123 | - else: | |
124 | - c.project = project | |
125 | - if app == (): | |
126 | - del c.app | |
127 | - else: | |
128 | - c.app = app | |
123 | + try: | |
124 | + yield | |
125 | + finally: | |
126 | + if project == (): | |
127 | + del c.project | |
128 | + else: | |
129 | + c.project = project | |
130 | + if app == (): | |
131 | + del c.app | |
132 | + else: | |
133 | + c.app = app | |
129 | 134 | |
130 | 135 | def encode_keys(d): |
131 | 136 | '''Encodes the unicode keys of d, making the result |
@@ -221,6 +221,7 @@ class Project(MappedClass): | ||
221 | 221 | labels = FieldProperty([str]) |
222 | 222 | last_updated = FieldProperty(datetime, if_missing=None) |
223 | 223 | |
224 | + @h.exceptionless([], log) | |
224 | 225 | def sidebar_menu(self): |
225 | 226 | from pyforge.app import SitemapEntry |
226 | 227 | result = [] |
@@ -52,6 +52,7 @@ class {{egg}}App(Application): | ||
52 | 52 | return [ |
53 | 53 | SitemapEntry(menu_id, '.')[self.sidebar_menu()] ] |
54 | 54 | |
55 | + @h.exceptionless([], log) | |
55 | 56 | def sidebar_menu(self): |
56 | 57 | return [ |
57 | 58 | SitemapEntry('Home', '.'), |