def show_more_info(context, label=None, loading=settings.LOADING, class_name=None): data = utils.get_data_from_context(context) page = data['page'] if page.has_next(): request = context['request'] page_number = page.next_page_number() querystring_key = data['querystring_key'] querystring = utils.get_querystring_for_page( request, page_number, querystring_key, default_number=data['default_number']) return { 'label': label, 'loading': loading, 'class_name': class_name, 'path': iri_to_uri(data['override_path'] or request.path), 'querystring': querystring, 'querystring_key': querystring_key, 'request': request, } return {}
def render(self, context): # This template tag could raise a PaginationError: you have to call # *paginate* or *lazy_paginate* before including the getpages template. data = utils.get_data_from_context(context) # Return the string representation of the sequence of pages. pages = models.PageList(context['request'], data['page'], data['querystring_key'], default_number=data['default_number'], override_path=data['override_path'], context=context) return pages.get_rendered()
def render(self, context): # This template tag could raise a PaginationError: you have to call # *paginate* or *lazy_paginate* before including the getpages template. data = utils.get_data_from_context(context) # Return the string representation of the sequence of pages. pages = models.PageList( context['request'], data['page'], data['querystring_key'], default_number=data['default_number'], override_path=data['override_path'], ) return utils.text(pages)
def render(self, context): # This template tag could raise a PaginationError: you have to call # *paginate* or *lazy_paginate* before including the getpages template. data = utils.get_data_from_context(context) # Add the PageList instance to the context. context[self.var_name] = models.PageList( context['request'], data['page'], data['querystring_key'], default_number=data['default_number'], override_path=data['override_path'], ) return ''
def custom_show_more(context, label=None, loading=settings.LOADING, class_name=None): """Show the link to get the next page in a Twitter-like pagination. Usage:: {% show_more %} Alternatively you can override the label passed to the default template:: {% show_more "even more" %} You can override the loading text too:: {% show_more "even more" "working" %} You could pass in the extra CSS style class name as a third argument {% show_more "even more" "working" "class_name" %} Must be called after ``{% paginate objects %}``. """ # This template tag could raise a PaginationError: you have to call # *paginate* or *lazy_paginate* before including the showmore template. data = utils.get_data_from_context(context) page = data['page'] # show the template only if there is a next page if page.has_next(): request = context['request'] page_number = page.next_page_number() # Generate the querystring. querystring_key = data['querystring_key'] querystring = utils.get_querystring_for_page( request, page_number, querystring_key, default_number=data['default_number']) return { 'label': label, 'loading': loading, 'class_name': class_name, 'path': iri_to_uri(data['override_path'] or request.path), 'querystring': querystring, 'querystring_key': querystring_key, 'request': request, } # No next page, nothing to see. return {}
def show_more(context, label=None, loading=settings.LOADING, class_name=None): """Show the link to get the next page in a Twitter-like pagination. Usage:: {% show_more %} Alternatively you can override the label passed to the default template:: {% show_more "even more" %} You can override the loading text too:: {% show_more "even more" "working" %} You could pass in the extra CSS style class name as a third argument {% show_more "even more" "working" "class_name" %} Must be called after ``{% paginate objects %}``. """ # This template tag could raise a PaginationError: you have to call # *paginate* or *lazy_paginate* before including the showmore template. data = utils.get_data_from_context(context) page = data['page'] # show the template only if there is a next page if page.has_next(): request = context['request'] page_number = page.next_page_number() # Generate the querystring. querystring_key = data['querystring_key'] querystring = utils.get_querystring_for_page( request, page_number, querystring_key, default_number=data['default_number']) return { 'label': label, 'loading': loading, 'class_name': class_name, 'path': iri_to_uri(data['override_path'] or request.path), 'querystring': querystring, 'querystring_key': querystring_key, 'request': request, } # No next page, nothing to see. return {}
def show_more_custom(context, label=None, items_ids=None, length=None, items_count=None, loading=settings.LOADING): data = utils.get_data_from_context(context) page = data['page'] query = None if page.has_next(): request = context['request'] page_number = page.next_page_number() items_shown = 10 * (page_number - 1) if not page_number: items_shown = items_count # pagination = context['pagination'] if not items_ids: if context.get('search_query'): query = context.get('search_query') querystring_key = data['querystring_key'] context['override_path'] = "/catalog-sort-item/" context['override_path'] = "/catalog-sort-item/" querystring = utils.get_querystring_for_page( request, page_number, querystring_key, default_number=data['default_number']) return { 'label': label, 'loading': loading, 'path': iri_to_uri(context.get('instance_path') or request.path), 'ajax_path': iri_to_uri( context.get("override_path") or context.get('instance_path') or request.path), 'querystring': querystring + context.get("extra_querystring", ""), 'querystring_key': querystring_key, 'request': request, 'page_number': page_number, 'length': length, 'items_ids': items_ids, 'items_count': items_count, 'items_shown': items_shown, 'query': query, # 'pagination': pagination , } return { 'length': length, 'items_count': items_count, 'items_shown': items_count, 'items_ids': items_ids, 'page': page, }
def test_valid_context(self): # Ensure the endless data is correctly retrieved from context. context = {'endless': 'test-data'} self.assertEqual('test-data', utils.get_data_from_context(context))