validators.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ==========
  2. Validators
  3. ==========
  4. Misago apps implement plenty of validators, some of which are considered public API. Those validators are per convention contained within ``validators`` module of their respective apps.
  5. misago.core.validators
  6. ======================
  7. validate_sluggable
  8. ------------------
  9. :py:class:`misago.core.validators.validate_sluggable`
  10. Callable class that validates if string can be converted to non-empty slug thats no longer than 255 characters.
  11. To you use it, first instantiate it. If you want to define custom error messages, you can pass them using ``error_short`` and ``error_long`` arguments on initializer. After that you can simply call the class like other validator functions to see if it raises ``ValidationError``::
  12. from misago.core.validators import validate_sluggable
  13. validator = validate_sluggable()
  14. validator(some_value)
  15. misago.users.validators
  16. =======================
  17. validate_email
  18. --------------
  19. :py:class:`misago.users.validators.validate_email`
  20. Function that takes email address and runs content, availability and ban check validation in this order via calling dedicated validators.
  21. validate_email_banned
  22. ---------------------
  23. :py:function:`misago.users.validators.validate_email_banned`
  24. Function that accepts email string as its only argument and raises Validation error if it's banned.
  25. validate_email_content
  26. ----------------------
  27. :py:class:`misago.users.validators.validate_email_content`
  28. Callable instance of :py:class:`django.core.validators.EmailValidator` that checks if email address has valid structure and contents.
  29. validate_password
  30. -----------------
  31. :py:function:`misago.users.validators.validate_password`
  32. Function that takes plaintext password and runs length and complexity validation in this order via calling dedicated validators.
  33. validate_password_complexity
  34. ----------------------------
  35. :py:function:`misago.users.validators.validate_password_complexity`
  36. Validates password complexity against tests specified in ``password_complexity`` setting.
  37. validate_password_length
  38. ------------------------
  39. :py:function:`misago.users.validators.validate_password_length`
  40. Validates password length and raises ValidationError if specified plaintext password is shorter than ``password_length_min``.
  41. validate_username
  42. -----------------
  43. :py:function:`misago.users.validators.validate_username`
  44. Function that takes username and runs content, length, availability and ban check validation in this order via calling dedicated validators.
  45. validate_username_available
  46. ---------------------------
  47. :py:function:`misago.users.validators.validate_username_available`
  48. Function that accepts username string as its only argument and raises ValidationError if it's already taken.
  49. validate_username_banned
  50. ------------------------
  51. :py:function:`misago.users.validators.validate_username_banned`
  52. Function that accepts username string as its only argument and raises Validation error if it's banned.
  53. validate_username_content
  54. -------------------------
  55. :py:function:`misago.users.validators.validate_username_content`
  56. Function that accepts username string as its only argument and raises Validation error if username contains disallowed characters (eg. those that are not matched by ``[0-9a-z]+`` regex).
  57. validate_username_length
  58. ------------------------
  59. :py:function:`misago.users.validators.validate_username_length`
  60. Function that accepts username string as its only argument and raises Validation error if it's shorter than ``username_length_min`` setting or longer than ``username_length_max`` setting.