| 414 | self.validator = validator_class() |
| 415 | |
| 416 | def get_context(self, name, value, attrs): |
| 417 | try: |
| 418 | self.validator(value if value else "") |
| 419 | url_valid = True |
| 420 | except ValidationError: |
| 421 | url_valid = False |
| 422 | context = super().get_context(name, value, attrs) |
| 423 | context["current_label"] = _("Currently:") |
| 424 | context["change_label"] = _("Change:") |
| 425 | context["widget"]["href"] = ( |
| 426 | smart_urlquote(context["widget"]["value"]) if url_valid else "" |
| 427 | ) |
| 428 | context["url_valid"] = url_valid |
| 429 | return context |
| 430 | |
| 431 | |
| 432 | class AdminIntegerFieldWidget(forms.NumberInput): |