Exemplo n.º 1
0
    def get_next_link(self):
        if self.offset + self.limit >= self.count:
            return None

        url = self.request.build_absolute_uri()
        url = replace_query_param(url, self.limit_query_param, self.limit)

        offset = self.offset + self.limit
        return replace_query_param(url, self.offset_query_param, offset)
Exemplo n.º 2
0
    def get_previous_link(self):
        if self.offset <= 0:
            return None

        url = self.request.build_absolute_uri()
        url = replace_query_param(url, self.limit_query_param, self.limit)

        if self.offset - self.limit <= 0:
            return remove_query_param(url, self.offset_query_param)

        offset = self.offset - self.limit
        return replace_query_param(url, self.offset_query_param, offset)
Exemplo n.º 3
0
def add_query_param(request, key, val):
    """
    Add a query parameter to the current request url, and return the new url.
    """
    iri = request.get_full_path()
    uri = iri_to_uri(iri)
    return escape(replace_query_param(uri, key, val))
Exemplo n.º 4
0
 def get_previous_link(self):
     if not self.page.has_previous():
         return None
     url = self.request.build_absolute_uri()
     page_number = self.page.previous_page_number()
     if page_number == 1:
         return remove_query_param(url, self.page_query_param)
     return replace_query_param(url, self.page_query_param, page_number)
Exemplo n.º 5
0
    def encode_cursor(self, cursor):
        """
        Given a Cursor instance, return an url with encoded cursor.
        """
        tokens = {}
        if cursor.offset != 0:
            tokens['o'] = str(cursor.offset)
        if cursor.reverse:
            tokens['r'] = '1'
        if cursor.position is not None:
            tokens['p'] = cursor.position

        querystring = urlparse.urlencode(tokens, doseq=True)
        encoded = b64encode(querystring.encode('ascii')).decode('ascii')
        return replace_query_param(self.base_url, self.cursor_query_param, encoded)
Exemplo n.º 6
0
def preserve_builtin_query_params(url, request=None):
    """
    Given an incoming request, and an outgoing URL representation,
    append the value of any built-in query parameters.
    """
    if request is None:
        return url

    overrides = [
        api_settings.URL_FORMAT_OVERRIDE,
    ]

    for param in overrides:
        if param and (param in request.GET):
            value = request.GET[param]
            url = replace_query_param(url, param, value)

    return url
Exemplo n.º 7
0
 def page_number_to_url(page_number):
     if page_number == 1:
         return remove_query_param(base_url, self.offset_query_param)
     else:
         offset = self.offset + ((page_number - current) * self.limit)
         return replace_query_param(base_url, self.offset_query_param, offset)
Exemplo n.º 8
0
 def page_number_to_url(page_number):
     if page_number == 1:
         return remove_query_param(base_url, self.page_query_param)
     else:
         return replace_query_param(base_url, self.page_query_param, page_number)
Exemplo n.º 9
0
 def get_next_link(self):
     if not self.page.has_next():
         return None
     url = self.request.build_absolute_uri()
     page_number = self.page.next_page_number()
     return replace_query_param(url, self.page_query_param, page_number)