changeset 6073:1fdff0d0516c

defaults: replace automatic 'routes' 'resource' routing by explicit 'connect' and use POST
author Mads Kiilerich <madski@unity3d.com>
date Thu, 04 Aug 2016 14:23:36 +0200
parents 8805d3e688eb
children 2dfbd29ae8f7
files kallithea/config/routing.py kallithea/controllers/admin/defaults.py kallithea/templates/admin/defaults/defaults.html kallithea/tests/functional/test_admin_defaults.py
diffstat 4 files changed, 10 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/config/routing.py	Thu Aug 04 14:23:36 2016 +0200
+++ b/kallithea/config/routing.py	Thu Aug 04 14:23:36 2016 +0200
@@ -269,9 +269,13 @@
                   action="permission_perms", conditions=dict(method=["GET"]))
 
 
-    #ADMIN DEFAULTS REST ROUTES
-    rmap.resource('default', 'defaults',
-                  controller='admin/defaults', path_prefix=ADMIN_PREFIX)
+    #ADMIN DEFAULTS ROUTES
+    with rmap.submapper(path_prefix=ADMIN_PREFIX,
+                        controller='admin/defaults') as m:
+        m.connect('defaults', 'defaults',
+                  action="index")
+        m.connect('defaults_update', 'defaults/{id}/update',
+                  action="update", conditions=dict(method=["POST"]))
 
     #ADMIN AUTH SETTINGS
     rmap.connect('auth_settings', '%s/auth' % ADMIN_PREFIX,
--- a/kallithea/controllers/admin/defaults.py	Thu Aug 04 14:23:36 2016 +0200
+++ b/kallithea/controllers/admin/defaults.py	Thu Aug 04 14:23:36 2016 +0200
@@ -46,10 +46,6 @@
 
 
 class DefaultsController(BaseController):
-    """REST Controller styled on the Atom Publishing Protocol"""
-    # To properly map this controller, ensure your config/routing.py
-    # file has a resource setup:
-    #     map.resource('default', 'defaults')
 
     @LoginRequired()
     @HasPermissionAnyDecorator('hg.admin')
@@ -57,8 +53,6 @@
         super(DefaultsController, self).__before__()
 
     def index(self, format='html'):
-        """GET /defaults: All items in the collection"""
-        # url('defaults')
         c.backends = BACKENDS.keys()
         defaults = Setting.get_default_repo_settings()
 
@@ -70,14 +64,6 @@
         )
 
     def update(self, id):
-        """PUT /defaults/id: Update an existing item"""
-        # Forms posted to this method should contain a hidden field:
-        #    <input type="hidden" name="_method" value="PUT" />
-        # Or using helpers:
-        #    h.form(url('default', id=ID),
-        #           method='put')
-        # url('default', id=ID)
-
         _form = DefaultsForm()()
 
         try:
--- a/kallithea/templates/admin/defaults/defaults.html	Thu Aug 04 14:23:36 2016 +0200
+++ b/kallithea/templates/admin/defaults/defaults.html	Thu Aug 04 14:23:36 2016 +0200
@@ -22,7 +22,7 @@
         ${self.breadcrumbs()}
     </div>
 
-    ${h.form(url('default', id='defaults'),method='put')}
+    ${h.form(url('defaults_update', id='defaults'))}
     <div class="form">
         <!-- fields -->
 
--- a/kallithea/tests/functional/test_admin_defaults.py	Thu Aug 04 14:23:36 2016 +0200
+++ b/kallithea/tests/functional/test_admin_defaults.py	Thu Aug 04 14:23:36 2016 +0200
@@ -22,7 +22,7 @@
             'default_repo_type': 'hg',
             '_authentication_token': self.authentication_token(),
         }
-        response = self.app.put(url('default', id='default'), params=params)
+        response = self.app.post(url('defaults_update', id='default'), params=params)
         self.checkSessionFlash(response, 'Default settings updated successfully')
 
         params.pop('_authentication_token')
@@ -39,7 +39,7 @@
             'default_repo_type': 'git',
             '_authentication_token': self.authentication_token(),
         }
-        response = self.app.put(url('default', id='default'), params=params)
+        response = self.app.post(url('defaults_update', id='default'), params=params)
         self.checkSessionFlash(response, 'Default settings updated successfully')
 
         params.pop('_authentication_token')