|
14 | 14 | encode_string, decode_string |
15 | 15 | from core.concepts.constants import CONCEPT_TYPE, LOCALES_FULLY_SPECIFIED, LOCALES_SHORT, LOCALES_SEARCH_INDEX_TERM, \ |
16 | 16 | CONCEPT_WAS_RETIRED, CONCEPT_IS_ALREADY_RETIRED, CONCEPT_IS_ALREADY_NOT_RETIRED, CONCEPT_WAS_UNRETIRED, \ |
17 | | - PERSIST_CLONE_ERROR, PERSIST_CLONE_SPECIFY_USER_ERROR, ALREADY_EXISTS, CONCEPT_REGEX |
| 17 | + PERSIST_CLONE_ERROR, PERSIST_CLONE_SPECIFY_USER_ERROR, ALREADY_EXISTS, CONCEPT_REGEX, MAX_LOCALES_LIMIT, \ |
| 18 | + MAX_NAMES_LIMIT, MAX_DESCRIPTIONS_LIMIT |
18 | 19 | from core.concepts.mixins import ConceptValidationMixin |
19 | 20 |
|
20 | 21 |
|
@@ -548,6 +549,7 @@ def persist_new(cls, data, user=None, create_initial_version=True, create_parent |
548 | 549 | return concept |
549 | 550 |
|
550 | 551 | try: |
| 552 | + concept.validate_locales_limit(names, descriptions) |
551 | 553 | concept.cloned_names = names |
552 | 554 | concept.cloned_descriptions = descriptions |
553 | 555 | concept.full_clean() |
@@ -615,6 +617,8 @@ def persist_clone( |
615 | 617 | prev_latest_version = versioned_object.versions.exclude(id=obj.id).filter(is_latest_version=True).first() |
616 | 618 | try: |
617 | 619 | with transaction.atomic(): |
| 620 | + cls.validate_locales_limit(obj.cloned_names, obj.cloned_descriptions) |
| 621 | + |
618 | 622 | cls.pause_indexing() |
619 | 623 |
|
620 | 624 | obj.is_latest_version = True |
@@ -666,6 +670,13 @@ def index_all(): |
666 | 670 |
|
667 | 671 | return errors |
668 | 672 |
|
| 673 | + @staticmethod |
| 674 | + def validate_locales_limit(names, descriptions): |
| 675 | + if len(names) > MAX_LOCALES_LIMIT: |
| 676 | + raise ValidationError({'names': [MAX_NAMES_LIMIT]}) |
| 677 | + if len(descriptions) > MAX_LOCALES_LIMIT: |
| 678 | + raise ValidationError({'descriptions': [MAX_DESCRIPTIONS_LIMIT]}) |
| 679 | + |
669 | 680 | def get_unidirectional_mappings_for_collection(self, collection_url, collection_version=HEAD): |
670 | 681 | from core.mappings.models import Mapping |
671 | 682 | return Mapping.objects.filter( |
|
0 commit comments