mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-01 11:19:32 -05:00
Make 16 char string
This commit is contained in:
parent
1afff1fec8
commit
a47c1b98c4
@ -198,7 +198,7 @@ class CustomFieldsFilter(Filter):
|
|||||||
class SelectField(serializers.CharField):
|
class SelectField(serializers.CharField):
|
||||||
def __init__(self, custom_field: CustomField):
|
def __init__(self, custom_field: CustomField):
|
||||||
self._options = custom_field.extra_data["select_options"]
|
self._options = custom_field.extra_data["select_options"]
|
||||||
super().__init__(max_length=128)
|
super().__init__(max_length=16)
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
# Test if the supplied value is not an id
|
# Test if the supplied value is not an id
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
# Generated by Django 5.1.1 on 2024-11-13 05:14
|
# Generated by Django 5.1.1 on 2024-11-13 05:14
|
||||||
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
from django.utils.crypto import get_random_string
|
||||||
|
|
||||||
|
|
||||||
def migrate_customfield_selects(apps, schema_editor):
|
def migrate_customfield_selects(apps, schema_editor):
|
||||||
@ -20,7 +19,7 @@ def migrate_customfield_selects(apps, schema_editor):
|
|||||||
if custom_field.data_type == "select": # CustomField.FieldDataType.SELECT
|
if custom_field.data_type == "select": # CustomField.FieldDataType.SELECT
|
||||||
old_select_options = custom_field.extra_data["select_options"]
|
old_select_options = custom_field.extra_data["select_options"]
|
||||||
custom_field.extra_data["select_options"] = [
|
custom_field.extra_data["select_options"] = [
|
||||||
{"id": str(uuid.uuid4()), "label": value}
|
{"id": get_random_string(16), "label": value}
|
||||||
for value in old_select_options
|
for value in old_select_options
|
||||||
]
|
]
|
||||||
custom_field.save()
|
custom_field.save()
|
||||||
@ -70,7 +69,7 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name="customfieldinstance",
|
model_name="customfieldinstance",
|
||||||
name="value_select",
|
name="value_select",
|
||||||
field=models.CharField(max_length=128, null=True),
|
field=models.CharField(max_length=16, null=True),
|
||||||
),
|
),
|
||||||
migrations.RunPython(
|
migrations.RunPython(
|
||||||
migrate_customfield_selects,
|
migrate_customfield_selects,
|
||||||
|
@ -947,7 +947,7 @@ class CustomFieldInstance(SoftDeleteModel):
|
|||||||
|
|
||||||
value_document_ids = models.JSONField(null=True)
|
value_document_ids = models.JSONField(null=True)
|
||||||
|
|
||||||
value_select = models.CharField(null=True, max_length=128)
|
value_select = models.CharField(null=True, max_length=16)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ("created",)
|
ordering = ("created",)
|
||||||
|
@ -533,7 +533,8 @@ class CustomFieldSerializer(serializers.ModelSerializer):
|
|||||||
if (
|
if (
|
||||||
"data_type" in attrs
|
"data_type" in attrs
|
||||||
and attrs["data_type"] == CustomField.FieldDataType.SELECT
|
and attrs["data_type"] == CustomField.FieldDataType.SELECT
|
||||||
and (
|
):
|
||||||
|
if (
|
||||||
"extra_data" not in attrs
|
"extra_data" not in attrs
|
||||||
or "select_options" not in attrs["extra_data"]
|
or "select_options" not in attrs["extra_data"]
|
||||||
or not isinstance(attrs["extra_data"]["select_options"], list)
|
or not isinstance(attrs["extra_data"]["select_options"], list)
|
||||||
@ -542,11 +543,14 @@ class CustomFieldSerializer(serializers.ModelSerializer):
|
|||||||
len(option.get("label", "")) > 0
|
len(option.get("label", "")) > 0
|
||||||
for option in attrs["extra_data"]["select_options"]
|
for option in attrs["extra_data"]["select_options"]
|
||||||
)
|
)
|
||||||
)
|
):
|
||||||
):
|
raise serializers.ValidationError(
|
||||||
raise serializers.ValidationError(
|
{"error": "extra_data.select_options must be a valid list"},
|
||||||
{"error": "extra_data.select_options must be a valid list"},
|
)
|
||||||
)
|
# labels are valid, generate ids if not present
|
||||||
|
for option in attrs["extra_data"]["select_options"]:
|
||||||
|
if "id" not in option or option["id"] is None:
|
||||||
|
option["id"] = get_random_string(length=16)
|
||||||
elif (
|
elif (
|
||||||
"data_type" in attrs
|
"data_type" in attrs
|
||||||
and attrs["data_type"] == CustomField.FieldDataType.MONETARY
|
and attrs["data_type"] == CustomField.FieldDataType.MONETARY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user