changeset 3866:1fdec7e3aeb2 beta

refactored url.resource to full definition of routes - id -> gist_id
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 18 May 2013 23:41:37 +0200
parents 100be6988bb0
children 73f7149f2cc0
files rhodecode/config/routing.py rhodecode/controllers/admin/gists.py rhodecode/model/db.py rhodecode/templates/admin/gists/index.html rhodecode/templates/admin/gists/show.html rhodecode/tests/functional/test_admin_gists.py
diffstat 6 files changed, 53 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/routing.py	Fri May 17 21:33:24 2013 +0200
+++ b/rhodecode/config/routing.py	Sat May 18 23:41:37 2013 +0200
@@ -384,16 +384,39 @@
         m.connect("formatted_notification", "/notifications/{notification_id}.{format}",
                   action="show", conditions=dict(method=["GET"]))
 
+    #ADMIN GIST
+    with rmap.submapper(path_prefix=ADMIN_PREFIX,
+                        controller='admin/gists') as m:
+        m.connect("gists", "/gists",
+                  action="create", conditions=dict(method=["POST"]))
+        m.connect("gists", "/gists",
+                  action="index", conditions=dict(method=["GET"]))
+        m.connect("formatted_gists", "/gists.{format}",
+                  action="index", conditions=dict(method=["GET"]))
+        m.connect("new_gist", "/gists/new",
+                  action="new", conditions=dict(method=["GET"]))
+        m.connect("formatted_new_gist", "/gists/new.{format}",
+                  action="new", conditions=dict(method=["GET"]))
+        m.connect("/gist/{gist_id}",
+                  action="update", conditions=dict(method=["PUT"]))
+        m.connect("/gist/{gist_id}",
+                  action="delete", conditions=dict(method=["DELETE"]))
+        m.connect("edit_gist", "/gist/{gist_id}/edit",
+                  action="edit", conditions=dict(method=["GET"]))
+        m.connect("formatted_edit_gist",
+                  "/gist/{gist_id}.{format}/edit",
+                  action="edit", conditions=dict(method=["GET"]))
+        m.connect("gist", "/gist/{gist_id}",
+                  action="show", conditions=dict(method=["GET"]))
+        m.connect("formatted_gist", "/gists/{gist_id}.{format}",
+                  action="show", conditions=dict(method=["GET"]))
+
     #ADMIN MAIN PAGES
     with rmap.submapper(path_prefix=ADMIN_PREFIX,
                         controller='admin/admin') as m:
         m.connect('admin_home', '', action='index')
         m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
                   action='add_repo')
-
-    #ADMIN GIST
-    rmap.resource('gist', 'gists', controller='admin/gists',
-        path_prefix=ADMIN_PREFIX)
     #==========================================================================
     # API V2
     #==========================================================================
--- a/rhodecode/controllers/admin/gists.py	Fri May 17 21:33:24 2013 +0200
+++ b/rhodecode/controllers/admin/gists.py	Sat May 18 23:41:37 2013 +0200
@@ -126,7 +126,7 @@
             log.error(traceback.format_exc())
             h.flash(_('Error occurred during gist creation'), category='error')
             return redirect(url('new_gist'))
-        return redirect(url('gist', id=new_gist_id))
+        return redirect(url('gist', gist_id=new_gist_id))
 
     @LoginRequired()
     @NotAnonymous()
@@ -138,26 +138,26 @@
 
     @LoginRequired()
     @NotAnonymous()
-    def update(self, id):
-        """PUT /admin/gists/id: Update an existing item"""
+    def update(self, gist_id):
+        """PUT /admin/gists/gist_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('gist', id=ID),
+        #    h.form(url('gist', gist_id=ID),
         #           method='put')
-        # url('gist', id=ID)
+        # url('gist', gist_id=ID)
 
     @LoginRequired()
     @NotAnonymous()
-    def delete(self, id):
-        """DELETE /admin/gists/id: Delete an existing item"""
+    def delete(self, gist_id):
+        """DELETE /admin/gists/gist_id: Delete an existing item"""
         # Forms posted to this method should contain a hidden field:
         #    <input type="hidden" name="_method" value="DELETE" />
         # Or using helpers:
-        #    h.form(url('gist', id=ID),
+        #    h.form(url('gist', gist_id=ID),
         #           method='delete')
-        # url('gist', id=ID)
-        gist = GistModel().get_gist(id)
+        # url('gist', gist_id=ID)
+        gist = GistModel().get_gist(gist_id)
         owner = gist.gist_owner == c.rhodecode_user.user_id
         if h.HasPermissionAny('hg.admin')() or owner:
             GistModel().delete(gist)
@@ -169,10 +169,9 @@
         return redirect(url('gists'))
 
     @LoginRequired()
-    def show(self, id, format='html'):
-        """GET /admin/gists/id: Show a specific item"""
-        # url('gist', id=ID)
-        gist_id = id
+    def show(self, gist_id, format='html'):
+        """GET /admin/gists/gist_id: Show a specific item"""
+        # url('gist', gist_id=ID)
         c.gist = Gist.get_or_404(gist_id)
 
         #check if this gist is not expired
@@ -191,6 +190,6 @@
 
     @LoginRequired()
     @NotAnonymous()
-    def edit(self, id, format='html'):
-        """GET /admin/gists/id/edit: Form to edit an existing item"""
-        # url('edit_gist', id=ID)
+    def edit(self, gist_id, format='html'):
+        """GET /admin/gists/gist_id/edit: Form to edit an existing item"""
+        # url('edit_gist', gist_id=ID)
--- a/rhodecode/model/db.py	Fri May 17 21:33:24 2013 +0200
+++ b/rhodecode/model/db.py	Sat May 18 23:41:37 2013 +0200
@@ -2161,7 +2161,7 @@
             return alias_url.replace('{gistid}', self.gist_access_id)
 
         from pylons import url
-        return url('gist', id=self.gist_access_id, qualified=True)
+        return url('gist', gist_id=self.gist_access_id, qualified=True)
 
     @classmethod
     def base_path(cls):
--- a/rhodecode/templates/admin/gists/index.html	Fri May 17 21:33:24 2013 +0200
+++ b/rhodecode/templates/admin/gists/index.html	Sat May 18 23:41:37 2013 +0200
@@ -42,7 +42,7 @@
             </div>
             <div title="${gist.owner.full_contact}" class="user" style="font-size: 16px">
                 <b>${h.person(gist.owner.full_contact)}</b> /
-                <b><a href="${h.url('gist',id=gist.gist_access_id)}">gist:${gist.gist_access_id}</a></b>
+                <b><a href="${h.url('gist',gist_id=gist.gist_access_id)}">gist:${gist.gist_access_id}</a></b>
             </div>
             <div style="padding: 4px 0px 0px 0px">
                 ${_('Created')} ${h.age(gist.created_on)} /
--- a/rhodecode/templates/admin/gists/show.html	Fri May 17 21:33:24 2013 +0200
+++ b/rhodecode/templates/admin/gists/show.html	Sat May 18 23:41:37 2013 +0200
@@ -52,7 +52,7 @@
                           ## only owner should see that
                           %if h.HasPermissionAny('hg.admin')() or c.gist.gist_owner == c.rhodecode_user.user_id:
                             ##${h.link_to(_('Edit'),h.url(''),class_="ui-btn")}
-                            ${h.form(url('gist', id=c.gist.gist_id),method='delete')}
+                            ${h.form(url('gist', gist_id=c.gist.gist_id),method='delete')}
                                 ${h.submit('remove_gist', _('Delete'),class_="ui-btn red",onclick="return confirm('"+_('Confirm to delete this gist')+"');")}
                             ${h.end_form()}
                           %endif
--- a/rhodecode/tests/functional/test_admin_gists.py	Fri May 17 21:33:24 2013 +0200
+++ b/rhodecode/tests/functional/test_admin_gists.py	Sat May 18 23:41:37 2013 +0200
@@ -92,7 +92,7 @@
         Session().add(gist)
         Session().commit()
 
-        response = self.app.get(url('gist', id=gist.gist_access_id), status=404)
+        response = self.app.get(url('gist', gist_id=gist.gist_access_id), status=404)
 
     def test_create_private(self):
         self.log_user()
@@ -128,28 +128,28 @@
 
     def test_update(self):
         self.skipTest('not implemented')
-        response = self.app.put(url('gist', id=1))
+        response = self.app.put(url('gist', gist_id=1))
 
     def test_delete(self):
         self.log_user()
         gist = _create_gist('delete-me')
-        response = self.app.delete(url('gist', id=gist.gist_id))
+        response = self.app.delete(url('gist', gist_id=gist.gist_id))
         self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
 
     def test_delete_normal_user_his_gist(self):
         self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
         gist = _create_gist('delete-me', owner=TEST_USER_REGULAR_LOGIN)
-        response = self.app.delete(url('gist', id=gist.gist_id))
+        response = self.app.delete(url('gist', gist_id=gist.gist_id))
         self.checkSessionFlash(response, 'Deleted gist %s' % gist.gist_id)
 
     def test_delete_normal_user_not_his_own_gist(self):
         self.log_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS)
         gist = _create_gist('delete-me')
-        response = self.app.delete(url('gist', id=gist.gist_id), status=403)
+        response = self.app.delete(url('gist', gist_id=gist.gist_id), status=403)
 
     def test_show(self):
         gist = _create_gist('gist-show-me')
-        response = self.app.get(url('gist', id=gist.gist_access_id))
+        response = self.app.get(url('gist', gist_id=gist.gist_access_id))
         response.mustcontain('added file: gist-show-me<')
         response.mustcontain('test_admin (RhodeCode Admin) - created')
         response.mustcontain('gist-desc')
@@ -157,4 +157,4 @@
 
     def test_edit(self):
         self.skipTest('not implemented')
-        response = self.app.get(url('edit_gist', id=1))
+        response = self.app.get(url('edit_gist', gist_id=1))