app/soc/views/helper/lists.py
changeset 1810 ec0bae3632bb
parent 1807 1f8cde169f32
child 1811 75d3c1384736
equal deleted inserted replaced
1809:66aec0241d61 1810:ec0bae3632bb
    29 from soc.logic.models.user import logic as user_logic
    29 from soc.logic.models.user import logic as user_logic
    30 
    30 
    31 import soc.views.helper.forms
    31 import soc.views.helper.forms
    32 
    32 
    33 
    33 
    34 DEF_PAGINATION = 50
    34 DEF_DEFAULT_PAGINATION = 50
    35 MAX_PAGINATION = 100
    35 DEF_MAX_PAGINATION = 100
    36 MAX_DEV_PAGINATION = 1000
    36 DEF_MAX_DEV_PAGINATION = 1000
    37 
    37 
    38 DEF_PAGINATION_CHOICES = (
    38 DEF_PAGINATION_CHOICES = (
    39   ('10', '10 items per page'),
    39   ('10', '10 items per page'),
    40   ('25', '25 items per page'),
    40   ('25', '25 items per page'),
    41   ('50', '50 items per page'),
    41   ('50', '50 items per page'),
    50     user: User entity containing the list pagination preference;
    50     user: User entity containing the list pagination preference;
    51       default is None, to use the current logged-in User
    51       default is None, to use the current logged-in User
    52   """
    52   """
    53   # TODO: eventually this limit should be a User profile preference
    53   # TODO: eventually this limit should be a User profile preference
    54   #   (stored in the site-wide User Model) preference 
    54   #   (stored in the site-wide User Model) preference 
    55   return DEF_PAGINATION
    55   return DEF_DEFAULT_PAGINATION
    56 
    56 
    57 
    57 
    58 def getLimitAndOffset(request, offset_key, limit_key):
    58 def getLimitAndOffset(request, offset_key, limit_key):
    59   """Retrieves, converts and validates offset and limit values
    59   """Retrieves, converts and validates offset and limit values
    60 
    60 
    86     limit = getPreferredListPagination()
    86     limit = getPreferredListPagination()
    87 
    87 
    88   offset = max(0, offset)
    88   offset = max(0, offset)
    89   limit = max(1, limit)
    89   limit = max(1, limit)
    90 
    90 
    91   maximum = MAX_DEV_PAGINATION if user_logic.isDeveloper() else MAX_PAGINATION
    91   if user_logic.isDeveloper():
    92   limit = min(maximum, limit)
    92     limit = min(DEF_MAX_DEV_PAGINATION, limit)
       
    93   else:
       
    94     limit = min(DEF_MAX_PAGINATION, limit)
    93 
    95 
    94   return limit, offset
    96   return limit, offset
    95 
    97 
    96 
    98 
    97 def generateLinkFromGetArgs(request, offset_and_limits):
    99 def generateLinkFromGetArgs(request, offset_and_limits):
   219   
   221   
   220   return soc.views.helper.forms.makeSelectQueryArgForm(
   222   return soc.views.helper.forms.makeSelectQueryArgForm(
   221       request, arg_name, limit, choices)
   223       request, arg_name, limit, choices)
   222 
   224 
   223 
   225 
   224 def makeNewPaginationChoices(limit=DEF_PAGINATION,
   226 def makeNewPaginationChoices(limit=DEF_DEFAULT_PAGINATION,
   225                              choices=DEF_PAGINATION_CHOICES):
   227                              choices=DEF_PAGINATION_CHOICES):
   226   """Updates the pagination limit selection form.
   228   """Updates the pagination limit selection form.
   227 
   229 
   228   Args:
   230   Args:
   229     limit: the initial value of the selection control;
   231     limit: the initial value of the selection control;
   230       default is DEF_PAGINATION
   232       default is DEF_DEFAULT_PAGINATION
   231     choices: see soc.views.helper.forms.makeSelectQueryArgForm();
   233     choices: see soc.views.helper.forms.makeSelectQueryArgForm();
   232       default is DEF_PAGINATION_CHOICES
   234       default is DEF_PAGINATION_CHOICES
   233 
   235 
   234   Returns:
   236   Returns:
   235     a new pagination choices list if limit is not in
   237     a new pagination choices list if limit is not in