You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fields.py 873B

12345678910111213141516171819
  1. from django.forms import fields
  2. from django.core.validators import URL_VALIDATOR_USER_AGENT
  3. from oscar.core import validators
  4. class ExtendedURLField(fields.URLField):
  5. """
  6. Custom field similar to URLField type field, however also accepting
  7. and validating local relative URLs, ie. '/product/'
  8. """
  9. def __init__(self, max_length=None, min_length=None, verify_exists=False,
  10. validator_user_agent=URL_VALIDATOR_USER_AGENT, *args, **kwargs):
  11. # intentionally skip one step when calling super()
  12. super(fields.URLField, self).__init__(max_length, min_length, *args,
  13. **kwargs)
  14. validator = validators.ExtendedURLValidator(verify_exists=verify_exists,
  15. validator_user_agent=validator_user_agent)
  16. self.validators.append(validator)