|
|
@@ -22,6 +22,7 @@ import os
|
|
|
import re
|
|
|
import uuid
|
|
|
|
|
|
+from datetime import datetime
|
|
|
from itertools import chain
|
|
|
|
|
|
from django.contrib.auth import models as auth_models
|
|
|
@@ -1029,18 +1030,28 @@ class Document2(models.Model):
|
|
|
if invalid_chars.search(self.name):
|
|
|
raise FilesystemException(_('Document %s contains an invalid character.') % self.name)
|
|
|
|
|
|
- # Validate that directories cannot have same name and parent
|
|
|
- if self.is_directory:
|
|
|
- try:
|
|
|
- dir = Directory.objects.get(name=self.name, owner=self.owner, parent_directory=self.parent_directory)
|
|
|
- if dir.pk != self.pk:
|
|
|
- raise FilesystemException(_('Directory for owner %s at path %s already exists') % (self.owner, self.path))
|
|
|
- except Directory.DoesNotExist:
|
|
|
- pass # no conflicts
|
|
|
- except Directory.MultipleObjectsReturned:
|
|
|
- dir_ids = [doc.id for doc in Directory.objects.filter(name=self.name, owner=self.owner, parent_directory=self.parent_directory)]
|
|
|
- raise FilesystemException(_('Found multiple documents for owner %s at path %s with IDs: [%s]') %
|
|
|
- (self.owner, self.path, ', '.join(dir_ids)))
|
|
|
+ # If different document with same name and same path (parent) exists, rename current document with datetime
|
|
|
+ try:
|
|
|
+ doc = Document2.objects.get(
|
|
|
+ owner=self.owner,
|
|
|
+ name=self.name,
|
|
|
+ type=self.type,
|
|
|
+ parent_directory=self.parent_directory
|
|
|
+ )
|
|
|
+ if doc.pk != self.pk:
|
|
|
+ timestamp = str(datetime.now()).split('.', 1)[0]
|
|
|
+ self.name = '%s %s' % (self.name, timestamp)
|
|
|
+ except Document2.DoesNotExist:
|
|
|
+ pass # no conflicts
|
|
|
+ except Document2.MultipleObjectsReturned:
|
|
|
+ doc_ids = Document2.objects.filter(
|
|
|
+ owner=self.owner,
|
|
|
+ name=self.name,
|
|
|
+ type=self.type,
|
|
|
+ parent_directory=self.parent_directory
|
|
|
+ ).values_list('id', flat=True)
|
|
|
+ raise FilesystemException(_('Found multiple documents with type %s at path %s with IDs: [%s]') %
|
|
|
+ (self.type, self.path, ', '.join(map(str, doc_ids))))
|
|
|
|
|
|
# Validate home and Trash directories are only created once per user and cannot be created or modified after
|
|
|
if self.name in ['', Document2.TRASH_DIR] and \
|