# HG changeset patch # User Todd Larsen # Date 1223054501 0 # Node ID 3c2994f3b85f9d6dd283081e28ca35827c348d62 # Parent 97b60788cb9a0fd1d80f4f6dfec0ecb04de3deab List views should have a selectable pagination "page" length: http://code.google.com/p/soc/issues/detail?id=59 Patch by: Chen Lunpeng and Todd Larsen Review by: Augie Fackler Review URL: http://codereviews.googleopensourceprograms.com/1201 diff -r 97b60788cb9a -r 3c2994f3b85f app/soc/templates/soc/list/list_pagination.html --- a/app/soc/templates/soc/list/list_pagination.html Fri Oct 03 07:03:11 2008 +0000 +++ b/app/soc/templates/soc/list/list_pagination.html Fri Oct 03 17:21:41 2008 +0000 @@ -1,4 +1,7 @@ \ No newline at end of file + diff -r 97b60788cb9a -r 3c2994f3b85f app/soc/views/helpers/forms_helpers.py --- a/app/soc/views/helpers/forms_helpers.py Fri Oct 03 07:03:11 2008 +0000 +++ b/app/soc/views/helpers/forms_helpers.py Fri Oct 03 17:21:41 2008 +0000 @@ -18,12 +18,16 @@ """ __authors__ = [ + '"Chen Lunpeng" ', '"Todd Larsen" ', ] from google.appengine.ext.db import djangoforms +from django import newforms as forms +from django.utils import safestring + class DbModelForm(djangoforms.ModelForm): """Subclass of Django ModelForm that fixes some label and help_text issues. @@ -68,3 +72,101 @@ # to the corresponding field help_text. if hasattr(model_prop, 'help_text'): self.fields[field_name].help_text = model_prop.help_text + + +class SelectQueryArgForm(forms.Form): + """URL query argument change control implemented as a Django form. + """ + + ONCHANGE_JAVASCRIPT_FMT = ''' + +''' + + def __init__(self, page_path, arg_name, choices, field_name, + *form_args, **form_kwargs): + """ + Args: + page_path: (usually request.path) + arg_name: the URL query parameter that determines which choice is + selected in the selection control + choices: list (or tuple) of value/label string two-tuples, for example: + (('10', '10 items per page'), ('25', '25 items per page')) + field_name: name of the selection field in the form + *form_args: positional arguments passed on to the Form base + class __init__() + *form_kwargs: keyword arguments passed on to the Form base + class __init__() + """ + super(SelectQueryArgForm, self).__init__(*form_args, **form_kwargs) + + self._script = safestring.mark_safe(self.ONCHANGE_JAVASCRIPT_FMT % { + 'arg_name': arg_name, 'page_path': page_path,}) + + onchange_js_call = 'changeArg_%s(this)' % arg_name + + self.fields[field_name] = forms.ChoiceField( + label='', choices=choices, + widget=forms.widgets.Select(attrs={'onchange': onchange_js_call})) + + def as_table(self): + """Returns form rendered as HTML rows -- with no
. + + Prepends