fix:duplicate-folder
This commit is contained in:
parent
81e865bcdb
commit
b8990c8e73
@ -0,0 +1,21 @@
|
||||
# Generated by Django 4.2.11 on 2024-06-17 08:36
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('documents', '1055_folder_checksum'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveConstraint(
|
||||
model_name='folder',
|
||||
name='documents_folder_unique_name_owner',
|
||||
),
|
||||
migrations.RemoveConstraint(
|
||||
model_name='folder',
|
||||
name='documents_folder_name_uniq',
|
||||
),
|
||||
]
|
@ -0,0 +1,21 @@
|
||||
# Generated by Django 4.2.11 on 2024-06-17 08:56
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('documents', '1056_remove_folder_documents_folder_unique_name_owner_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveConstraint(
|
||||
model_name='warehouse',
|
||||
name='documents_warehouse_unique_name_owner',
|
||||
),
|
||||
migrations.RemoveConstraint(
|
||||
model_name='warehouse',
|
||||
name='documents_warehouse_name_uniq',
|
||||
),
|
||||
]
|
@ -149,6 +149,7 @@ class Warehouse(MatchingModel):
|
||||
class Meta(MatchingModel.Meta):
|
||||
verbose_name = _("warehouse")
|
||||
verbose_name_plural = _("warehouses")
|
||||
constraints = []
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@ -166,8 +167,10 @@ class Folder(MatchingModel):
|
||||
)
|
||||
|
||||
class Meta(MatchingModel.Meta):
|
||||
|
||||
verbose_name = _("folder")
|
||||
verbose_name_plural = _("folders")
|
||||
constraints = []
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
@ -1828,11 +1828,19 @@ class WorkflowSerializer(serializers.ModelSerializer):
|
||||
|
||||
class AdjustedNameField(serializers.CharField):
|
||||
def to_internal_value(self, data):
|
||||
model = self.parent.Meta.model
|
||||
|
||||
model = self.parent.Meta.model
|
||||
print(data)
|
||||
if hasattr(model, 'name'):
|
||||
|
||||
existing_names = model.objects.filter(name__startswith=data).values_list('name', flat=True)
|
||||
parent_folder = self.parent.initial_data.get('parent_folder')
|
||||
type = self.parent.initial_data.get('type')
|
||||
|
||||
if type:
|
||||
existing_names = model.objects.filter(type=type).values_list('name', flat=True)
|
||||
elif parent_folder:
|
||||
existing_names = model.objects.filter(parent_folder=parent_folder).values_list('name', flat=True)
|
||||
|
||||
else:
|
||||
existing_names = model.objects.filter(name__startswith=data).values_list('name', flat=True)
|
||||
|
||||
if data in existing_names:
|
||||
data = self.generate_unique_name(data, existing_names)
|
||||
|
@ -1941,10 +1941,6 @@ class WarehouseViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
parent_warehouse = serializer.validated_data.get('parent_warehouse',None)
|
||||
|
||||
existing_warehouse = Warehouse.objects.filter(name=serializer.validated_data['name'], owner=request.user).first()
|
||||
if existing_warehouse:
|
||||
return Response({'error': 'A warehouse with the same name already exists.'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
parent_warehouse = Warehouse.objects.filter(id=parent_warehouse.id if parent_warehouse else 0).first()
|
||||
|
||||
if serializer.validated_data.get("type") == Warehouse.WAREHOUSE and not parent_warehouse:
|
||||
@ -2133,10 +2129,6 @@ class FolderViewSet(ModelViewSet, PermissionsAwareDocumentCountMixin):
|
||||
if serializer.is_valid(raise_exception=True):
|
||||
parent_folder = serializer.validated_data.get('parent_folder',None)
|
||||
|
||||
existing_folder = Folder.objects.filter(name=serializer.validated_data['name'], owner=request.user).first()
|
||||
if existing_folder:
|
||||
return Response({'error': 'A folder with the same name already exists.'}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
parent_folder = Folder.objects.filter(id=parent_folder.id if parent_folder else 0).first()
|
||||
|
||||
if parent_folder == None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user