Skip to content

Commit

Permalink
Fixed problems with renaming of files.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmanovic committed Feb 5, 2019
1 parent 711eb2f commit 88d4b0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,25 @@ def get_task_dirname(self):
def __str__(self):
return self.name

# Redefined a couple of operation for FileSystemStorage to avoid renaming
# or other side effects.
class MyFileSystemStorage(FileSystemStorage):
def get_valid_name(self, name):
return name

def get_available_name(self, name, max_length=None):
if self.exists(name) or (max_length and len(name) > max_length):
raise IOError('`{}` file already exists or its name is too long'.format(name))
return name

def upload_path_handler(instance, filename):
return os.path.join(instance.task.get_upload_dirname(), filename)

# For client files which the user is uploaded
class ClientFile(models.Model):
task = models.ForeignKey(Task, on_delete=models.CASCADE)
file = models.FileField(upload_to=upload_path_handler,
storage=FileSystemStorage())
storage=MyFileSystemStorage())

class Meta:
default_permissions = ()
Expand Down
7 changes: 7 additions & 0 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class Meta:
model = ClientFile
fields = ('file', )

def to_internal_value(self, data):
return {'file': data}

def to_representation(self, instance):
upload_dir = instance.task.get_upload_dirname()
return instance.file.path[len(upload_dir) + 1:]

class ServerFileSerializer(serializers.ModelSerializer):
class Meta:
model = ServerFile
Expand Down

0 comments on commit 88d4b0b

Please sign in to comment.