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 824B

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