From a57eb8a8cbbe51443133aea314a0e9b78ddaba17 Mon Sep 17 00:00:00 2001 From: PouyaMohseni Date: Sun, 5 Apr 2026 14:57:54 -0400 Subject: [PATCH] fix: prevent the source from overflow - increase the lenght of the source to 255 (max in CharField) - truncate source when displayed - add charecter count ref #455 --- .../0014_alter_instrument_source_and_more.py | 29 ++++++++++++++++++ .../VIM/apps/instruments/models/instrument.py | 2 +- .../instruments/models/instrument_name.py | 2 +- .../instruments/views/create_instrument.py | 6 ++-- .../VIM/templates/instruments/create.html | 8 +++-- .../VIM/templates/instruments/detail.html | 4 +-- .../helpers/CreateInstrumentManager.ts | 30 +++++++++++++++++-- .../helpers/CreateInstrumentValidator.ts | 18 +++++++++-- .../src/instruments/helpers/NameRowManager.ts | 28 +++++++++++++++-- .../src/instruments/helpers/NameValidator.ts | 12 ++++++-- 10 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 web-app/django/VIM/apps/instruments/migrations/0014_alter_instrument_source_and_more.py diff --git a/web-app/django/VIM/apps/instruments/migrations/0014_alter_instrument_source_and_more.py b/web-app/django/VIM/apps/instruments/migrations/0014_alter_instrument_source_and_more.py new file mode 100644 index 00000000..78d5781e --- /dev/null +++ b/web-app/django/VIM/apps/instruments/migrations/0014_alter_instrument_source_and_more.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.5 on 2026-04-05 18:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("instruments", "0013_alter_avresource_format_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="instrument", + name="source", + field=models.CharField( + blank=True, + help_text="Source/reference for this instrument entry", + max_length=255, + ), + ), + migrations.AlterField( + model_name="instrumentname", + name="source_name", + field=models.CharField( + help_text="Who or what called the instrument this?", max_length=255 + ), + ), + ] diff --git a/web-app/django/VIM/apps/instruments/models/instrument.py b/web-app/django/VIM/apps/instruments/models/instrument.py index 7c8e432f..377895df 100644 --- a/web-app/django/VIM/apps/instruments/models/instrument.py +++ b/web-app/django/VIM/apps/instruments/models/instrument.py @@ -45,7 +45,7 @@ class Instrument(models.Model): help_text="User who created this instrument (null for Wikidata imports)", ) source = models.CharField( - max_length=200, + max_length=255, blank=True, help_text="Source/reference for this instrument entry", ) diff --git a/web-app/django/VIM/apps/instruments/models/instrument_name.py b/web-app/django/VIM/apps/instruments/models/instrument_name.py index b31af750..cef40451 100644 --- a/web-app/django/VIM/apps/instruments/models/instrument_name.py +++ b/web-app/django/VIM/apps/instruments/models/instrument_name.py @@ -6,7 +6,7 @@ class InstrumentName(models.Model): language = models.ForeignKey("Language", on_delete=models.PROTECT) name = models.CharField(max_length=100, blank=False) source_name = models.CharField( - max_length=50, blank=False, help_text="Who or what called the instrument this?" + max_length=255, blank=False, help_text="Who or what called the instrument this?" ) # Stand-in for source data; format TBD verification_status = models.CharField( max_length=50, diff --git a/web-app/django/VIM/apps/instruments/views/create_instrument.py b/web-app/django/VIM/apps/instruments/views/create_instrument.py index d53be56a..f1813501 100644 --- a/web-app/django/VIM/apps/instruments/views/create_instrument.py +++ b/web-app/django/VIM/apps/instruments/views/create_instrument.py @@ -110,11 +110,11 @@ def create_instrument(request: HttpRequest) -> JsonResponse: ) # Validate instrument source length - if len(instrument_source) > 200: + if len(instrument_source) > 255: raise ValidationException( ErrorCode.FIELD_TOO_LONG, - "Instrument source must be 200 characters or less", - details={"field": "instrument_source", "max_length": 200}, + "Instrument source must be 255 characters or less", + details={"field": "instrument_source", "max_length": 255}, ) if not validate_hbs_classification(hbs_class): diff --git a/web-app/django/VIM/templates/instruments/create.html b/web-app/django/VIM/templates/instruments/create.html index e070ae3b..a90fa8fc 100644 --- a/web-app/django/VIM/templates/instruments/create.html +++ b/web-app/django/VIM/templates/instruments/create.html @@ -38,12 +38,16 @@
Instrument Information
id="instrumentSource" name="instrument_source" placeholder="Enter instrument source" + maxlength="255" required />
The primary source or reference for this instrument's existence.
-
-
+
+
+
+ 0 / 255 +