diff --git a/web-app/django/VIM/apps/instruments/migrations/0012_alter_instrumentname_source_name.py b/web-app/django/VIM/apps/instruments/migrations/0012_alter_instrumentname_source_name.py new file mode 100644 index 00000000..5c5e3f31 --- /dev/null +++ b/web-app/django/VIM/apps/instruments/migrations/0012_alter_instrumentname_source_name.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.5 on 2025-12-17 16:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("instruments", "0011_language_html_direction"), + ] + + operations = [ + 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_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/update_umil_db.py b/web-app/django/VIM/apps/instruments/views/update_umil_db.py index 74a52731..5d717397 100644 --- a/web-app/django/VIM/apps/instruments/views/update_umil_db.py +++ b/web-app/django/VIM/apps/instruments/views/update_umil_db.py @@ -45,6 +45,7 @@ def add_name(request: HttpRequest) -> JsonResponse: }, status=400, ) + # Fetch the instrument from the database, if it does not exist return does not exist error instrument = get_object_or_404(Instrument, wikidata_id=wikidata_id) diff --git a/web-app/django/VIM/templates/instruments/detail.html b/web-app/django/VIM/templates/instruments/detail.html index a605595a..ff11c666 100644 --- a/web-app/django/VIM/templates/instruments/detail.html +++ b/web-app/django/VIM/templates/instruments/detail.html @@ -115,7 +115,7 @@

{{ active_instrument_label.name|title }}

- {{ names.label.source_name }} + {{ names.label.source_name|truncatechars:40 }}
{% if user.is_authenticated %} @@ -182,7 +182,7 @@

{{ active_instrument_label.name|title }}

Source
- {{ names.label.source_name }} + {{ names.label.source_name|truncatechars:50 }}
{% if user.is_authenticated %} diff --git a/web-app/frontend/src/instruments/helpers/AddNameManager.ts b/web-app/frontend/src/instruments/helpers/AddNameManager.ts index 6d153f6f..6781d502 100644 --- a/web-app/frontend/src/instruments/helpers/AddNameManager.ts +++ b/web-app/frontend/src/instruments/helpers/AddNameManager.ts @@ -29,7 +29,7 @@ export class AddNameManager { .join(''); row.innerHTML = ` -
+
@@ -44,7 +44,7 @@ export class AddNameManager {
-
+
diff --git a/web-app/frontend/src/instruments/helpers/NameValidator.ts b/web-app/frontend/src/instruments/helpers/NameValidator.ts index c3a7d880..860af263 100644 --- a/web-app/frontend/src/instruments/helpers/NameValidator.ts +++ b/web-app/frontend/src/instruments/helpers/NameValidator.ts @@ -55,8 +55,14 @@ export class NameValidator { /** * Validates that the name field is not empty */ - validateNameField(nameInput: string): ValidationResult { - if (nameInput.trim() === '') { + validateNameField( + nameInput: string, + minLength = 2, + maxLength = 50, + ): ValidationResult { + const trimmed = nameInput.trim(); + + if (trimmed === '') { return { isValid: false, message: @@ -65,6 +71,22 @@ export class NameValidator { }; } + if (trimmed.length < minLength) { + return { + isValid: false, + message: `Name must be at least ${minLength} characters long.`, + type: 'error', + }; + } + + if (trimmed.length > maxLength) { + return { + isValid: false, + message: `Name cannot exceed ${maxLength} characters.`, + type: 'error', + }; + } + return { isValid: true, message: '', @@ -75,8 +97,14 @@ export class NameValidator { /** * Validates that the source field is not empty */ - validateSource(sourceInput: string): ValidationResult { - if (sourceInput.trim() === '') { + validateSource( + sourceInput: string, + minLength = 2, + maxLength = 255, + ): ValidationResult { + const trimmed = sourceInput.trim(); + + if (trimmed === '') { return { isValid: false, message: 'Please enter the source of this name.', @@ -84,6 +112,22 @@ export class NameValidator { }; } + if (trimmed.length < minLength) { + return { + isValid: false, + message: `Source must be at least ${minLength} characters long.`, + type: 'error', + }; + } + + if (trimmed.length > maxLength) { + return { + isValid: false, + message: `Source cannot exceed ${maxLength} characters.`, + type: 'error', + }; + } + return { isValid: true, message: '',