Skip to content
This repository
Browse code

wiki: Handle wiki create errors with set_error.

  • Loading branch information...
commit 23fdb0e225f9dc596acae7da9a79fbc13cbadf39 1 parent 9341181
Andre d authored October 23, 2012 spladug committed December 06, 2012
5  r2/r2/controllers/validator/wiki.py
@@ -305,7 +305,10 @@ def run(self, page, previous=None):
305 305
                 return self.set_error('PAGE_NOT_FOUND', code=404)
306 306
             return self.set_error('MAY_NOT_REVISE', code=403)
307 307
         if not wp:
308  
-            c.error = self.may_not_create(page)
  308
+            # No abort code on purpose, controller will handle
  309
+            error = self.may_not_create(page)
  310
+            if error:
  311
+                self.set_error('WIKI_CREATE_ERROR', msg_params=error)
309 312
             return (None, None)
310 313
         if previous:
311 314
             try:
30  r2/r2/controllers/wiki.py
@@ -135,22 +135,25 @@ def GET_wiki_revisions(self, num, after, reverse, count, page):
135 135
     def GET_wiki_create(self, wp, page):
136 136
         page = page[0]
137 137
         api = c.render_style in extensions.API_TYPES
  138
+        error = c.errors.get(('WIKI_CREATE_ERROR', 'page'))
  139
+        if error:
  140
+            error = error.msg_params
138 141
         if wp[0]:
139 142
             return self.redirect(join_urls(c.wiki_base_url, wp[0].name))
140 143
         elif api:
141  
-            if c.error:
142  
-                self.handle_error(403, **c.error)
  144
+            if error:
  145
+                self.handle_error(403, **error)
143 146
             else:
144 147
                 self.handle_error(404, 'PAGE_NOT_CREATED')
145  
-        elif c.error:
146  
-            error = ''
147  
-            if c.error['reason'] == 'PAGE_NAME_LENGTH':
148  
-                error = _("this wiki cannot handle page names of that magnitude!  please select a page name shorter than %d characters") % c.error['max_length']
149  
-            elif c.error['reason'] == 'PAGE_CREATED_ELSEWHERE':
150  
-                error = _("this page is a special page, please go into the subreddit settings and save the field once to create this special page")
151  
-            elif c.error['reason'] == 'PAGE_NAME_MAX_SEPARATORS':
152  
-                error = _('a max of %d separators "/" are allowed in a wiki page name.') % c.error['max_separators']
153  
-            return BoringPage(_("Wiki error"), infotext=error).render()
  148
+        elif error:
  149
+            error_msg = ''
  150
+            if error['reason'] == 'PAGE_NAME_LENGTH':
  151
+                error_msg = _("this wiki cannot handle page names of that magnitude!  please select a page name shorter than %d characters") % error['max_length']
  152
+            elif error['reason'] == 'PAGE_CREATED_ELSEWHERE':
  153
+                error_msg = _("this page is a special page, please go into the subreddit settings and save the field once to create this special page")
  154
+            elif error['reason'] == 'PAGE_NAME_MAX_SEPARATORS':
  155
+                error_msg = _('a max of %d separators "/" are allowed in a wiki page name.') % error['max_separators']
  156
+            return BoringPage(_("Wiki error"), infotext=error_msg).render()
154 157
         else:
155 158
             return WikiCreate(page=page, may_revise=True).render()
156 159
     
@@ -254,8 +257,9 @@ def POST_wiki_edit(self, pageandprevious, content, page_name, reason):
254 257
         page, previous = pageandprevious
255 258
         
256 259
         if not page:
257  
-            if c.error:
258  
-                self.handle_error(403, **c.error)
  260
+            error = c.errors.get(('WIKI_CREATE_ERROR', 'page'))
  261
+            if error:
  262
+                self.handle_error(403, **(error.msg_params or {}))
259 263
             page = WikiPage.create(c.site, page_name[0])
260 264
         
261 265
         # Use the raw POST value as we need to tell the difference between

0 notes on commit 23fdb0e

Please sign in to comment.
Something went wrong with that request. Please try again.