77 |
77 |
78 def view(func): |
78 def view(func): |
79 """Decorator that insists that exceptions are handled by view. |
79 """Decorator that insists that exceptions are handled by view. |
80 """ |
80 """ |
81 |
81 |
82 from soc.logic.helper import timeline |
|
83 from soc.logic.models.site import logic as site_logic |
|
84 from soc.logic.models.user import logic as user_logic |
|
85 from soc.views import out_of_band |
82 from soc.views import out_of_band |
86 from soc.views.helper import responses |
|
87 |
83 |
88 @wraps(func) |
84 @wraps(func) |
89 def view_wrapper(request, *args, **kwds): |
85 def view_wrapper(request, *args, **kwds): |
90 """View decorator wrapper method. |
86 """View decorator wrapper method. |
91 """ |
87 """ |
92 |
88 |
|
89 context = responses.getUniversalContext(request) |
|
90 |
93 try: |
91 try: |
94 site = site_logic.getSingleton() |
92 if not context['is_admin'] and context['in_maintenance']: |
95 |
|
96 # don't redirect admins |
|
97 redirect = not user_logic.isDeveloper() |
|
98 |
|
99 if redirect and timeline.isActivePeriod(site, 'maintenance'): |
|
100 return maintenance(request) |
93 return maintenance(request) |
101 |
94 |
102 return func(request, *args, **kwds) |
95 return func(request, *args, **kwds) |
103 except DeadlineExceededError, exception: |
|
104 logging.exception(exception) |
|
105 return http.HttpResponseRedirect('/soc/content/deadline_exceeded.html') |
|
106 except CapabilityDisabledError, exception: |
96 except CapabilityDisabledError, exception: |
107 logging.exception(exception) |
97 logging.exception(exception) |
108 # assume the site is in maintenance if we get CDE |
98 # assume the site is in maintenance if we get CDE |
109 return http.HttpResponseRedirect('/maintenance') |
99 return maintenance(request) |
|
100 except DeadlineExceededError, exception: |
|
101 template = 'soc/deadline_exceeded.html' |
110 except MemoryError, exception: |
102 except MemoryError, exception: |
111 logging.exception(exception) |
103 template = 'soc/memory_error.html' |
112 return http.HttpResponseRedirect('/soc/content/memory_error.html') |
|
113 except AssertionError, exception: |
104 except AssertionError, exception: |
114 logging.exception(exception) |
105 template = 'soc/assertion_error.html' |
115 return http.HttpResponseRedirect('/soc/content/assertion_error.html') |
|
116 except out_of_band.Error, error: |
106 except out_of_band.Error, error: |
117 return responses.errorResponse(error, request) |
107 return responses.errorResponse(error, request) |
|
108 |
|
109 logging.exception(exception) |
|
110 return responses.respond(request, template, context=context) |
118 |
111 |
119 return view_wrapper |
112 return view_wrapper |
120 |
113 |
121 |
114 |
122 def merge_params(func): |
115 def merge_params(func): |