MCPcopy
hub / github.com/encode/django-rest-framework / encode_cursor

Method encode_cursor

rest_framework/pagination.py:806–820  ·  view source on GitHub ↗

Given a Cursor instance, return an url with encoded cursor.

(self, cursor)

Source from the content-addressed store, hash-verified

804 return Cursor(offset=offset, reverse=reverse, position=position)
805
806 def encode_cursor(self, cursor):
807 """
808 Given a Cursor instance, return an url with encoded cursor.
809 """
810 tokens = {}
811 if cursor.offset != 0:
812 tokens['o'] = str(cursor.offset)
813 if cursor.reverse:
814 tokens['r'] = '1'
815 if cursor.position is not None:
816 tokens['p'] = cursor.position
817
818 querystring = parse.urlencode(tokens, doseq=True)
819 encoded = b64encode(querystring.encode('ascii')).decode('ascii')
820 return replace_query_param(self.base_url, self.cursor_query_param, encoded)
821
822 def _get_position_from_instance(self, instance, ordering):
823 field_name = ordering[0].lstrip('-')

Calls 1

replace_query_paramFunction · 0.90