ajax.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. DEFAULT_PAGE_SIZE = 10
  2. class AjaxModelLoader(object):
  3. """
  4. Ajax related model loader. Override this to implement custom loading behavior.
  5. """
  6. def __init__(self, name, options):
  7. """
  8. Constructor.
  9. :param name:
  10. Field name
  11. """
  12. self.name = name
  13. self.options = options
  14. def format(self, model):
  15. """
  16. Return (id, name) tuple from the model.
  17. """
  18. raise NotImplementedError()
  19. def get_one(self, pk):
  20. """
  21. Find model by its primary key.
  22. :param pk:
  23. Primary key value
  24. """
  25. raise NotImplementedError()
  26. def get_list(self, query, offset=0, limit=DEFAULT_PAGE_SIZE):
  27. """
  28. Return models that match `query`.
  29. :param view:
  30. Administrative view.
  31. :param query:
  32. Query string
  33. :param offset:
  34. Offset
  35. :param limit:
  36. Limit
  37. """
  38. raise NotImplementedError()