app/soc/views/helper/lists.py
changeset 274 56e1c1721299
parent 268 af1d7f48b361
child 277 85f7d537e4d7
equal deleted inserted replaced
273:b97d08ebac0e 274:56e1c1721299
    21   '"Chen Lunpeng" <forever.clp@gmail.com>',
    21   '"Chen Lunpeng" <forever.clp@gmail.com>',
    22   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    22   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    23   ]
    23   ]
    24 
    24 
    25 
    25 
    26 from soc.views.helpers import forms_helpers
    26 from soc.views import helper
       
    27 import soc.views.helper.forms
    27 
    28 
    28 
    29 
    29 DEF_PAGINATION = 10
    30 DEF_PAGINATION = 10
    30 MAX_PAGINATION = 100
    31 MAX_PAGINATION = 100
    31 
    32 
   151   return context
   152   return context
   152 
   153 
   153 
   154 
   154 def makePaginationForm(
   155 def makePaginationForm(
   155   request, limit, arg_name='limit', choices=DEF_PAGINATION_CHOICES,
   156   request, limit, arg_name='limit', choices=DEF_PAGINATION_CHOICES,
   156   field_name_fmt=forms_helpers.DEF_SELECT_QUERY_ARG_FIELD_NAME_FMT):
   157   field_name_fmt=helper.forms.DEF_SELECT_QUERY_ARG_FIELD_NAME_FMT):
   157   """Returns a customized pagination limit selection form.
   158   """Returns a customized pagination limit selection form.
   158   
   159   
   159   Args:
   160   Args:
   160     request: the standard Django HTTP request object
   161     request: the standard Django HTTP request object
   161     limit: the initial value of the selection control
   162     limit: the initial value of the selection control
   162     arg_name: see forms_helpers.makeSelectQueryArgForm(); default is 'limit'
   163     arg_name: see helper.forms.makeSelectQueryArgForm(); default is 'limit'
   163     choices: see forms_helpers.makeSelectQueryArgForm(); default is
   164     choices: see helper.forms.makeSelectQueryArgForm(); default is
   164       DEF_PAGINATION_CHOICES
   165       DEF_PAGINATION_CHOICES
   165     field_name_fmt: see forms_helpers.makeSelectQueryArgForm()
   166     field_name_fmt: see helper.forms.makeSelectQueryArgForm()
   166   """
   167   """
   167   choices = makeNewPaginationChoices(limit=limit, choices=choices)
   168   choices = makeNewPaginationChoices(limit=limit, choices=choices)
   168   
   169   
   169   return forms_helpers.makeSelectQueryArgForm(
   170   return helper.forms.makeSelectQueryArgForm(
   170       request, arg_name, limit, choices)
   171       request, arg_name, limit, choices)
   171 
   172 
   172 
   173 
   173 def makeNewPaginationChoices(limit=DEF_PAGINATION,
   174 def makeNewPaginationChoices(limit=DEF_PAGINATION,
   174                              choices=DEF_PAGINATION_CHOICES):
   175                              choices=DEF_PAGINATION_CHOICES):
   175   """Updates the pagination limit selection form.
   176   """Updates the pagination limit selection form.
   176 
   177 
   177   Args:
   178   Args:
   178     limit: the initial value of the selection control;
   179     limit: the initial value of the selection control;
   179       default is DEF_PAGINATION
   180       default is DEF_PAGINATION
   180     choices: see forms_helpers.makeSelectQueryArgForm();
   181     choices: see helper.forms.makeSelectQueryArgForm();
   181       default is DEF_PAGINATION_CHOICES
   182       default is DEF_PAGINATION_CHOICES
   182 
   183 
   183   Returns:
   184   Returns:
   184     a new pagination choices list if limit is not in
   185     a new pagination choices list if limit is not in
   185     DEF_PAGINATION_CHOICES, or DEF_PAGINATION_CHOICES otherwise
   186     DEF_PAGINATION_CHOICES, or DEF_PAGINATION_CHOICES otherwise