Re-enable the custom Radio IRI model form/field.

This commit is contained in:
RecursiveGreen 2019-06-06 15:45:56 -04:00
parent f3ec6a1ae3
commit d866ce7cda
4 changed files with 13 additions and 35 deletions

View file

@ -2,11 +2,12 @@
Custom model fields for the Save Point Radio project. Custom model fields for the Save Point Radio project.
''' '''
from django.core import validators
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import gettext_lazy as _
from .forms import ALLOWED_SCHEMES, RadioIRIFormField from core.validators import RadioIRIValidator
from .forms import RadioIRIFormField
class RadioIRIField(models.TextField): class RadioIRIField(models.TextField):
@ -19,13 +20,7 @@ class RadioIRIField(models.TextField):
https://stackoverflow.com/questions/41756572/ https://stackoverflow.com/questions/41756572/
''' '''
# TODO: Because of a shortcoming of Django's URLValidator code, the default_validators = [RadioIRIValidator()]
# 'file://' scheme does not validate properly on most cases due to
# incompatibilities with optional hostnames. Disabling the custom field
# for now until I can figure out a non-lethal way of handling this.
# https://code.djangoproject.com/ticket/25595
default_validators = [validators.URLValidator(schemes=ALLOWED_SCHEMES)]
description = _("Long IRI") description = _("Long IRI")
def __init__(self, verbose_name=None, name=None, **kwargs): def __init__(self, verbose_name=None, name=None, **kwargs):

View file

@ -2,11 +2,9 @@
Custom forms/formfields for the Save Point Radio project. Custom forms/formfields for the Save Point Radio project.
''' '''
from django.core import validators
from django.forms.fields import URLField from django.forms.fields import URLField
from core.validators import RadioIRIValidator
ALLOWED_SCHEMES = ['http', 'https', 'file', 'ftp', 'ftps', 's3']
class RadioIRIFormField(URLField): class RadioIRIFormField(URLField):
@ -19,10 +17,4 @@ class RadioIRIFormField(URLField):
https://stackoverflow.com/questions/41756572/ https://stackoverflow.com/questions/41756572/
''' '''
# TODO: Because of a shortcoming of Django's URLValidator code, the default_validators = [RadioIRIValidator()]
# 'file://' scheme does not validate properly on most cases due to
# incompatibilities with optional hostnames. Disabling the custom field
# for now until I can figure out a non-lethal way of handling this.
# https://code.djangoproject.com/ticket/25595
default_validators = [validators.URLValidator(schemes=ALLOWED_SCHEMES)]

View file

@ -1,8 +1,9 @@
# Generated by Django 2.2.1 on 2019-06-03 18:39 # Generated by Django 2.2.1 on 2019-06-06 19:06
import django.core.validators import django.core.validators
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
import radio.fields
class Migration(migrations.Migration): class Migration(migrations.Migration):
@ -18,7 +19,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_date', models.DateTimeField(auto_now_add=True, verbose_name='added on')), ('created_date', models.DateTimeField(auto_now_add=True, verbose_name='added on')),
('modified_date', models.DateTimeField(auto_now=True, verbose_name='last modified')), ('modified_date', models.DateTimeField(auto_now=True, verbose_name='last modified')),
('iri', models.TextField(verbose_name='IRI path to song file')), ('iri', radio.fields.RadioIRIField(verbose_name='IRI path to song file')),
('mime_type', models.CharField(blank=True, max_length=64, verbose_name='file MIME type')), ('mime_type', models.CharField(blank=True, max_length=64, verbose_name='file MIME type')),
('file_size', models.BigIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='file size')), ('file_size', models.BigIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='file size')),
('length', models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True, verbose_name='song length (in seconds)')), ('length', models.DecimalField(blank=True, decimal_places=2, max_digits=8, null=True, verbose_name='song length (in seconds)')),

View file

@ -9,11 +9,11 @@ from django.apps import apps
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import gettext_lazy as _
from core.behaviors import Disableable, Publishable, Timestampable from core.behaviors import Disableable, Publishable, Timestampable
from core.utils import get_setting from core.utils import get_setting
# from .fields import RadioIRIField from .fields import RadioIRIField
from .managers import RadioManager, SongManager from .managers import RadioManager, SongManager
@ -104,17 +104,7 @@ class Store(Timestampable, models.Model):
''' '''
A model to represent various data locations (stores) for the song. A model to represent various data locations (stores) for the song.
''' '''
# TODO: Because of a shortcoming of Django's URLValidator code, the iri = RadioIRIField(_('IRI path to song file'))
# 'file://' scheme does not validate properly on most cases due to
# incompatibilities with optional hostnames. Disabling the custom field
# for now until I can figure out a non-lethal way of handling this.
# https://code.djangoproject.com/ticket/25594
# https://code.djangoproject.com/ticket/25595
# https://stackoverflow.com/questions/41756572/
# iri = RadioIRIField()
iri = models.TextField(_('IRI path to song file'))
mime_type = models.CharField(_('file MIME type'), mime_type = models.CharField(_('file MIME type'),
max_length=64, max_length=64,
blank=True) blank=True)