# HG changeset patch # User Sverre Rabbelier # Date 1227362374 0 # Node ID c0cc20b4afc91ef9e05cbaeeb0c16bbd08c131a8 # Parent cb23b3897e0cec32bb887feeeb7bfd45e6f91127 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 diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/logic/lists.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) diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/templates/soc/document/list/docs_row.html --- 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 @@ +onclick="document.location.href='{{ list.redirect }}'" name="name">
{{ list.item.scope_path}}/{{ list.item.link_id }} + href="{{ list.redirect }}">{{ list.item.scope_path}}/{{ list.item.link_id }}
{{ list.item.title }}
diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/templates/soc/group/list/group_row.html --- 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 @@ +onclick="document.location.href='{{ list.redirect }}'" name="name">
{{ list.item.name }} + href="{{ list.redirect }}">{{ list.item.name }}
diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/templates/soc/presence/list/home_row.html --- 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 @@ +onclick="document.location.href='{{ list.redirect }}'" name="name">
{{ list.item.scope_path}}/{{ list.item.link_id }} + href="{{ list.redirect }}">{{ list.item.scope_path}}/{{ list.item.link_id }}
diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/templates/soc/request/list/request_row.html --- 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 @@ +onclick="document.location.href='{{ list.redirect }}'" name="name">
{{ list.item.role }}
diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/templates/soc/user/list/user_row.html --- 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 @@ +onclick="document.location.href='{{ list.redirect }}'" name="name">
{{ list.item.account }} + href="{{ list.redirect }}">{{ list.item.account }}
{{ list.item.account.email }}
diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/views/helper/lists.py --- 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 diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/views/models/base.py --- 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'] diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/views/models/document.py --- 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' diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/views/models/host.py --- 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' diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/views/models/presence.py --- 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' diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/views/models/request.py --- 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(). diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/views/models/sponsor.py --- 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) diff -r cb23b3897e0c -r c0cc20b4afc9 app/soc/views/models/user.py --- 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'