Make redirect generic using the new Lists object
authorSverre Rabbelier <srabbelier@gmail.com>
Sat, 22 Nov 2008 13:59:34 +0000
changeset 553 c0cc20b4afc9
parent 552 cb23b3897e0c
child 554 68c7a1dd3c52
Make redirect generic using the new Lists object This makes it possible (and easier) to have the list view redirect to any page specially tailored to the current item. Patch by: Sverre Rabbelier
app/soc/logic/lists.py
app/soc/templates/soc/document/list/docs_row.html
app/soc/templates/soc/group/list/group_row.html
app/soc/templates/soc/presence/list/home_row.html
app/soc/templates/soc/request/list/request_row.html
app/soc/templates/soc/user/list/user_row.html
app/soc/views/helper/lists.py
app/soc/views/models/base.py
app/soc/views/models/document.py
app/soc/views/models/host.py
app/soc/views/models/presence.py
app/soc/views/models/request.py
app/soc/views/models/sponsor.py
app/soc/views/models/user.py
--- a/app/soc/logic/lists.py	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/logic/lists.py	Sat Nov 22 13:59:34 2008 +0000
@@ -132,3 +132,12 @@
     """
 
     return self.row_data
+
+  def redirect(self):
+    """Returns the redirect for the current row item in the current list.
+    """
+
+    logic = self.get('logic')
+    action = self.get('action')
+    suffix = logic.getKeySuffix(self.row_data)
+    return "%s/%s" % (action, suffix)
--- a/app/soc/templates/soc/document/list/docs_row.html	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/templates/soc/document/list/docs_row.html	Sat Nov 22 13:59:34 2008 +0000
@@ -1,9 +1,9 @@
 <tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'" 
-onclick="document.location.href='/document/edit/{{ list.item.scope_path }}/{{ list.item.link_id }}'" name="name">
+onclick="document.location.href='{{ list.redirect }}'" name="name">
   <td align="right">
    <div class="title">
     <a class="noul"
-     href="/document/edit/{{ list.item.scope_path }}/{{ list.item.link_id }}">{{ list.item.scope_path}}/{{ list.item.link_id }}</a>
+     href="{{ list.redirect }}">{{ list.item.scope_path}}/{{ list.item.link_id }}</a>
    </div>
   </td>
   <td><div class="title">{{ list.item.title }}</div></td>
--- a/app/soc/templates/soc/group/list/group_row.html	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/templates/soc/group/list/group_row.html	Sat Nov 22 13:59:34 2008 +0000
@@ -1,7 +1,7 @@
 <tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'" 
-onclick="document.location.href='/{{ entity_type|lower }}/edit/{{ list.item.link_id }}'" name="name">
+onclick="document.location.href='{{ list.redirect }}'" name="name">
   <td align="right"><div class="name"><a class="noul"
-         href="/{{ entity_type|lower }}/edit/{{ list.item.link_id }}">{{ list.item.name }}</a>
+         href="{{ list.redirect }}">{{ list.item.name }}</a>
      </div>
   </td>
   <td><div class="link_id">{{ list.item.link_id }}</a></div></td>
--- a/app/soc/templates/soc/presence/list/home_row.html	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/templates/soc/presence/list/home_row.html	Sat Nov 22 13:59:34 2008 +0000
@@ -1,9 +1,9 @@
 <tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'" 
-onclick="document.location.href='/home/settings/edit/{{ list.item.scope_path }}/{{ list.item.link_id }}'" name="name">
+onclick="document.location.href='{{ list.redirect }}'" name="name">
   <td align="right">
    <div class="title">
     <a class="noul"
-     href="/home/settings/edit/{{ list.item.scope_path }}/{{ list.item.link_id }}">{{ list.item.scope_path}}/{{ list.item.link_id }}</a>
+     href="{{ list.redirect }}">{{ list.item.scope_path}}/{{ list.item.link_id }}</a>
    </div>
   </td>
   <td><div class="link_id">{{ list.item.home.title }}</div></td>
--- a/app/soc/templates/soc/request/list/request_row.html	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/templates/soc/request/list/request_row.html	Sat Nov 22 13:59:34 2008 +0000
@@ -1,7 +1,7 @@
 <tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'" 
-onclick="document.location.href='/{{ entity_type|lower }}/edit/{{ list.item.role|lower }}/{{ list.item.to.link_id }}/{{ list.item.requester.link_id }}'" name="name">
+onclick="document.location.href='{{ list.redirect }}'" name="name">
   <td align="right"><div class="user_link_id"><a class="noul"
-         href="/{{ entity_type|lower }}/edit/{{ list.item.role|lower }}/{{ list.item.to.link_id }}/{{ list.item.requester.link_id }}">{{ list.item.requester.link_id }}</a>
+         href="{{ list.redirect }}">{{ list.item.requester.link_id }}</a>
      </div>
   </td>
   <td><div class="role">{{ list.item.role }}</div></td>
--- a/app/soc/templates/soc/user/list/user_row.html	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/templates/soc/user/list/user_row.html	Sat Nov 22 13:59:34 2008 +0000
@@ -1,7 +1,7 @@
 <tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'" 
-onclick="document.location.href='{{redirect_action|lower}}/{{ list.item.link_id }}'" name="name">
+onclick="document.location.href='{{ list.redirect }}'" name="name">
   <td align="right"><div class="account"><a class="noul"
-         href="{{redirect_action|lower}}/{{ list.item.link_id }}">{{ list.item.account }}</a>
+         href="{{ list.redirect }}">{{ list.item.account }}</a>
      </div>
   </td>
   <td><div class="email">{{ list.item.account.email }}</a></div></td>
--- a/app/soc/views/helper/lists.py	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/views/helper/lists.py	Sat Nov 22 13:59:34 2008 +0000
@@ -78,15 +78,14 @@
   return max(0, offset), max(1, min(limit, MAX_PAGINATION))
 
 
-def getList(request, list_data, list_templates, description, offset=0, limit=0):
+def getList(request, data, offset, limit):
   """Returns a dict with fields used for rendering lists.
 
   Args:
     request: the Django HTTP request object
-    list_data: array of data to be displayed in the list
+    data: array of data to be displayed in the list
     offset: offset in list which defines first item to return
     limit: max amount of items per page
-    list_templates: templates that are used when rendering list
 
   Returns:
     A a dictionary with the following values set:
@@ -106,12 +105,12 @@
     }
   """
 
-  if not list_data:
-    list_data = []
+  if not data:
+    data = []
 
-  more = bool(list_data[limit:])
+  more = bool(data[limit:])
   if more:
-    del list_data[limit:]
+    del data[limit:]
 
   newest = ''
   next = ''
@@ -127,19 +126,14 @@
     newest = request.path + '?limit=%d' % limit
 
   content = {
-      'data': list_data,
-      'description': description,
-     'main': list_templates['list_main'],
-     'pagination': list_templates['list_pagination'],
-     'row': list_templates['list_row'],
-     'heading': list_templates['list_heading'],
-     'limit': limit,
-     'newest': newest, 
-     'prev': prev, 
-     'next': next,
-     'first': offset+1,
-     'last': len(list_data) > 1 and offset+len(list_data) or None
-     }
+      'data': data,
+      'first': offset+1,
+      'last': len(data) > 1 and offset+len(data) or None,
+      'limit': limit,
+      'newest': newest, 
+      'next': next,
+      'prev': prev, 
+      }
 
   return content
 
--- a/app/soc/views/models/base.py	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/views/models/base.py	Sat Nov 22 13:59:34 2008 +0000
@@ -127,7 +127,22 @@
             'soc.views.models.%s.list', 'List %(name_plural)s'),
         ]
 
-    new_params['list_redirect_action'] = '/' + params['url_name'] + '/edit'
+    new_params['edit_template'] = 'soc/models/edit.html'
+    new_params['list_template'] = 'soc/models/list.html'
+    new_params['invite_template'] = 'soc/models/invite.html'
+
+    new_params['list_main'] = 'soc/list/list_main.html'
+    new_params['list_pagination'] = 'soc/list/list_pagination.html'
+    
+    new_params['list_action'] = '/' + params['url_name'] + '/edit'
+    new_params['list_params'] = {
+        'list_action': 'action',
+        'list_description': 'description',
+        'list_main': 'main',
+        'list_pagination': 'pagination',
+        'list_row': 'row',
+        'list_heading': 'heading',
+        }
 
     description = ugettext_lazy('List of %(name)s in Google Open Source Programs.')
     new_params['list_description'] = description % params
@@ -358,16 +373,16 @@
     
     context['pagination_form'] = helper.lists.makePaginationForm(request, limit)
 
-    templates = params['lists_template']
-    description = params['list_description']
+    updates = dicts.rename(params, params['list_params'])
+    updates['logic'] = self._logic
 
-    content = helper.lists.getList(request, entities, templates,
-        description, offset, limit)
+    content = helper.lists.getList(request, entities, offset, limit)
+    content.update(updates)
+
     context['list'] = soc.logic.lists.Lists([content])
 
     context['entity_type'] = params['name']
     context['entity_type_plural'] = params['name_plural']
-    context['redirect_action'] = params['list_redirect_action']
 
     template = params['list_template']
 
--- a/app/soc/views/models/document.py	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/views/models/document.py	Sat Nov 22 13:59:34 2008 +0000
@@ -104,16 +104,10 @@
     params['create_form'] = CreateForm
 
     # TODO(tlarsen) Add support for Django style template lookup
-    params['edit_template'] = 'soc/models/edit.html'
     params['public_template'] = 'soc/document/public.html'
-    params['list_template'] = 'soc/models/list.html'
 
-    params['lists_template'] = {
-      'list_main': 'soc/list/list_main.html',
-      'list_pagination': 'soc/list/list_pagination.html',
-      'list_row': 'soc/document/list/docs_row.html',
-      'list_heading': 'soc/document/list/docs_heading.html',
-    }
+    params['list_row'] = 'soc/document/list/docs_row.html'
+    params['list_heading'] = 'soc/document/list/docs_heading.html'
 
     params['delete_redirect'] = '/' + params['url_name'] + '/list'
 
--- a/app/soc/views/models/host.py	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/views/models/host.py	Sat Nov 22 13:59:34 2008 +0000
@@ -102,17 +102,10 @@
     params['create_form'] = CreateForm
 
     # TODO(tlarsen) Add support for Django style template lookup
-    params['edit_template'] = 'soc/models/edit.html'
     params['public_template'] = 'soc/host/public.html'
-    params['list_template'] = 'soc/models/list.html'
-    params['invite_template'] = 'soc/models/invite.html'
 
-    params['lists_template'] = {
-      'list_main': 'soc/list/list_main.html',
-      'list_pagination': 'soc/list/list_pagination.html',
-      'list_row': 'soc/host/list/host_row.html',
-      'list_heading': 'soc/host/list/host_heading.html',
-    }
+    params['list_row'] = 'soc/host/list/host_row.html'
+    params['list_heading'] = 'soc/host/list/host_heading.html'
 
     params['delete_redirect'] = '/' + params['url_name'] + '/list'
     params['invite_redirect'] = '/request/list'
--- a/app/soc/views/models/presence.py	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/views/models/presence.py	Sat Nov 22 13:59:34 2008 +0000
@@ -119,16 +119,10 @@
     params['create_form'] = CreateForm
 
     # TODO(tlarsen) Add support for Django style template lookup
-    params['edit_template'] = 'soc/models/edit.html'
     params['public_template'] = 'soc/presence/public.html'
-    params['list_template'] = 'soc/models/list.html'
 
-    params['lists_template'] = {
-      'list_main': 'soc/list/list_main.html',
-      'list_pagination': 'soc/list/list_pagination.html',
-      'list_row': 'soc/presence/list/home_row.html',
-      'list_heading': 'soc/presence/list/home_heading.html',
-    }
+    params['list_row'] = 'soc/presence/list/home_row.html'
+    params['list_heading'] = 'soc/presence/list/home_heading.html'
 
     params['delete_redirect'] = '/' + params['url_name'] + '/list'
 
--- a/app/soc/views/models/request.py	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/views/models/request.py	Sat Nov 22 13:59:34 2008 +0000
@@ -110,16 +110,10 @@
     params['create_form'] = CreateForm
 
     # TODO(tlarsen) Add support for Django style template lookup
-    params['edit_template'] = 'soc/models/edit.html'
     params['public_template'] = 'soc/request/public.html'
-    params['list_template'] = 'soc/models/list.html'
 
-    params['lists_template'] = {
-      'list_main': 'soc/list/list_main.html',
-      'list_pagination': 'soc/list/list_pagination.html',
-      'list_row': 'soc/request/list/request_row.html',
-      'list_heading': 'soc/request/list/request_heading.html',
-    }
+    params['list_row'] = 'soc/request/list/request_row.html'
+    params['list_heading'] = 'soc/request/list/request_heading.html'
 
     params['sidebar_defaults'] = [('/%s/list', 'List %(name_plural)s')]
 
@@ -160,7 +154,7 @@
               'declined' : False}
     
     
-    return list(request, page_name, params, filter)
+    return list(request, page_name=page_name, params=params, filter=filter)
 
   def _editSeed(self, request, seed):
     """See base.View._editGet().
--- a/app/soc/views/models/sponsor.py	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/views/models/sponsor.py	Sat Nov 22 13:59:34 2008 +0000
@@ -121,15 +121,10 @@
     # TODO(tlarsen): Add support for Django style template lookup
     params['edit_template'] = 'soc/sponsor/edit.html'
     params['public_template'] = 'soc/group/public.html'
-    params['list_template'] = 'soc/models/list.html'
 
-    params['lists_template'] = {
-      'list_main': 'soc/list/list_main.html',
-      'list_pagination': 'soc/list/list_pagination.html',
-      'list_row': 'soc/group/list/group_row.html',
-      'list_heading': 'soc/group/list/group_heading.html',
-    }
-    
+    params['list_row'] = 'soc/group/list/group_row.html'
+    params['list_heading'] = 'soc/group/list/group_heading.html'
+
     params['delete_redirect'] = '/' + params['url_name'] + '/list'
 
     params = dicts.merge(original_params, params)
--- a/app/soc/views/models/user.py	Sat Nov 22 11:19:20 2008 +0000
+++ b/app/soc/views/models/user.py	Sat Nov 22 13:59:34 2008 +0000
@@ -177,16 +177,10 @@
     params['create_form'] = CreateForm
 
     # TODO(tlarsen) Add support for Django style template lookup
-    params['edit_template'] = 'soc/models/edit.html'
     params['public_template'] = 'soc/user/public.html'
-    params['list_template'] = 'soc/models/list.html'
 
-    params['lists_template'] = {
-      'list_main': 'soc/list/list_main.html',
-      'list_pagination': 'soc/list/list_pagination.html',
-      'list_row': 'soc/user/list/user_row.html',
-      'list_heading': 'soc/user/list/user_heading.html',
-    }
+    params['list_row'] = 'soc/user/list/user_row.html'
+    params['list_heading'] = 'soc/user/list/user_heading.html'
 
     params['delete_redirect'] = '/' + params['url_name'] + '/list'