From bb2bfd5ee05529dcedbca7355ac87521d0adbd69 Mon Sep 17 00:00:00 2001 From: sarayourfriend Date: Thu, 16 May 2024 05:25:31 +1000 Subject: [PATCH] Remove unnecessary write-time validating URLTextField (#4322) --- .../0061_convert_varchar_to_text.py | 25 +++++++++---------- api/api/models/fields.py | 21 ---------------- api/api/models/mixins.py | 18 ++++++------- 3 files changed, 20 insertions(+), 44 deletions(-) delete mode 100644 api/api/models/fields.py diff --git a/api/api/migrations/0061_convert_varchar_to_text.py b/api/api/migrations/0061_convert_varchar_to_text.py index cd907a4bcb7..4685533c4c1 100644 --- a/api/api/migrations/0061_convert_varchar_to_text.py +++ b/api/api/migrations/0061_convert_varchar_to_text.py @@ -1,6 +1,5 @@ # Generated by Django 4.2.11 on 2024-05-10 22:07 -import api.models.fields from django.db import migrations, models @@ -24,7 +23,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='audio', name='creator_url', - field=api.models.fields.URLTextField(blank=True, help_text='A direct link to the media creator.', max_length=2000, null=True), + field=models.TextField(blank=True, help_text='A direct link to the media creator.', max_length=2000, null=True), ), migrations.AlterField( model_name='audio', @@ -34,12 +33,12 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='audio', name='foreign_landing_url', - field=api.models.fields.URLTextField(blank=True, help_text='The landing page of the work.', null=True), + field=models.TextField(blank=True, help_text='The landing page of the work.', null=True), ), migrations.AlterField( model_name='audio', name='thumbnail', - field=api.models.fields.URLTextField(blank=True, help_text='The thumbnail for the media.', null=True), + field=models.TextField(blank=True, help_text='The thumbnail for the media.', null=True), ), migrations.AlterField( model_name='audio', @@ -49,7 +48,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='audio', name='url', - field=api.models.fields.URLTextField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True), + field=models.TextField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True), ), migrations.AlterField( model_name='audioset', @@ -59,7 +58,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='audioset', name='creator_url', - field=api.models.fields.URLTextField(blank=True, help_text='A direct link to the media creator.', max_length=2000, null=True), + field=models.TextField(blank=True, help_text='A direct link to the media creator.', max_length=2000, null=True), ), migrations.AlterField( model_name='audioset', @@ -69,12 +68,12 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='audioset', name='foreign_landing_url', - field=api.models.fields.URLTextField(blank=True, help_text='The landing page of the work.', null=True), + field=models.TextField(blank=True, help_text='The landing page of the work.', null=True), ), migrations.AlterField( model_name='audioset', name='thumbnail', - field=api.models.fields.URLTextField(blank=True, help_text='The thumbnail for the media.', null=True), + field=models.TextField(blank=True, help_text='The thumbnail for the media.', null=True), ), migrations.AlterField( model_name='audioset', @@ -84,7 +83,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='audioset', name='url', - field=api.models.fields.URLTextField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True), + field=models.TextField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True), ), migrations.AlterField( model_name='image', @@ -94,7 +93,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='image', name='creator_url', - field=api.models.fields.URLTextField(blank=True, help_text='A direct link to the media creator.', max_length=2000, null=True), + field=models.TextField(blank=True, help_text='A direct link to the media creator.', max_length=2000, null=True), ), migrations.AlterField( model_name='image', @@ -104,12 +103,12 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='image', name='foreign_landing_url', - field=api.models.fields.URLTextField(blank=True, help_text='The landing page of the work.', null=True), + field=models.TextField(blank=True, help_text='The landing page of the work.', null=True), ), migrations.AlterField( model_name='image', name='thumbnail', - field=api.models.fields.URLTextField(blank=True, help_text='The thumbnail for the media.', null=True), + field=models.TextField(blank=True, help_text='The thumbnail for the media.', null=True), ), migrations.AlterField( model_name='image', @@ -119,6 +118,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='image', name='url', - field=api.models.fields.URLTextField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True), + field=models.TextField(blank=True, help_text='The actual URL to the media file.', max_length=1000, null=True, unique=True), ), ] diff --git a/api/api/models/fields.py b/api/api/models/fields.py deleted file mode 100644 index 208d262362a..00000000000 --- a/api/api/models/fields.py +++ /dev/null @@ -1,21 +0,0 @@ -from django import forms -from django.core import validators -from django.db import models -from django.utils.translation import gettext_lazy as _ - - -class URLTextField(models.TextField): - """URL field which uses the underlying Postgres TEXT column type.""" - - default_validators = [validators.URLValidator()] - description = _("URL") - - def formfield(self, **kwargs): - # As with CharField, this will cause URL validation to be performed - # twice. - return super().formfield( - **{ - "form_class": forms.URLField, - **kwargs, - } - ) diff --git a/api/api/models/mixins.py b/api/api/models/mixins.py index 4594cd24f10..e1f77a46516 100644 --- a/api/api/models/mixins.py +++ b/api/api/models/mixins.py @@ -2,8 +2,6 @@ from django.db import models -from api.models import fields - class IdentifierMixin(models.Model): """ @@ -57,10 +55,10 @@ class MediaMixin(models.Model): The mixin adds - title: TextField - - foreign_landing_url: URLTextField + - foreign_landing_url: TextField - creator: TextField - - creator_url: URLTextField - - thumbnail: URLTextField + - creator_url: TextField + - thumbnail: TextField - provider: CharField """ @@ -69,7 +67,7 @@ class MediaMixin(models.Model): null=True, help_text="The name of the media.", ) - foreign_landing_url = fields.URLTextField( + foreign_landing_url = models.TextField( blank=True, null=True, help_text="The landing page of the work.", @@ -80,7 +78,7 @@ class MediaMixin(models.Model): null=True, help_text="The name of the media creator.", ) - creator_url = fields.URLTextField( + creator_url = models.TextField( max_length=2000, blank=True, null=True, @@ -90,7 +88,7 @@ class MediaMixin(models.Model): # Because all forms of media have a thumbnail for visual representation # For images, this field is not used as images are generated using Photon. # For audio, this field points to the artwork, or is ``null``. - thumbnail = fields.URLTextField( + thumbnail = models.TextField( blank=True, null=True, help_text="The thumbnail for the media.", @@ -117,12 +115,12 @@ class FileMixin(models.Model): This mixin adds - - url: URLTextField + - url: TextField - filesize: IntegerField - filetype: CharField """ - url = fields.URLTextField( + url = models.TextField( unique=True, max_length=1000, help_text="The actual URL to the media file.",