Skip to content

Commit b2701dc

Browse files
committed
don't change the short name when re-uploading a custom part type
1 parent a140ec1 commit b2701dc

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

editor/forms.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ def validate_custom_part_type_json_file(f):
640640
class UploadCustomPartTypeForm(forms.ModelForm):
641641
file = forms.FileField(required=True, validators=[validate_custom_part_type_json_file])
642642

643+
unique_short_name = True
644+
643645
kwarg_keys = ['name', 'short_name', 'description', 'input_widget', 'input_options', 'can_be_gap', 'can_be_step', 'marking_script', 'marking_notes', 'settings', 'help_url', 'ready_to_use']
644646

645647
class Meta:
@@ -664,11 +666,13 @@ def get_kwargs(self):
664666
for key in self.kwarg_keys:
665667
if key in data:
666668
kwargs[key] = data[key]
667-
n = 0
668-
o_short_name = kwargs['short_name']
669-
while CustomPartType.objects.filter(short_name=kwargs['short_name']).exists():
670-
n += 1
671-
kwargs['short_name'] = o_short_name+'-'+str(n)
669+
670+
if self.unique_short_name:
671+
n = 0
672+
o_short_name = kwargs['short_name']
673+
while CustomPartType.objects.filter(short_name=kwargs['short_name']).exists():
674+
n += 1
675+
kwargs['short_name'] = o_short_name+'-'+str(n)
672676

673677
return (kwargs, extensions)
674678

@@ -681,6 +685,7 @@ def save(self, commit=True):
681685
return cpt
682686

683687
class ReuploadCustomPartTypeForm(UploadCustomPartTypeForm):
688+
unique_short_name = False
684689
class Meta:
685690
model = CustomPartType
686691
fields = []

0 commit comments

Comments
 (0)