From 38618e2ed29be69504202fb58b91f22a5c52b914 Mon Sep 17 00:00:00 2001 From: j Date: Thu, 23 Jan 2025 16:26:25 +0530 Subject: [PATCH] add folder/filename columns to media view --- .../0008_file_filename_file_folder.py | 32 +++++++++++++++++++ pandora/archive/models.py | 17 ++++++++-- static/js/mediaView.js | 16 ++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 pandora/archive/migrations/0008_file_filename_file_folder.py diff --git a/pandora/archive/migrations/0008_file_filename_file_folder.py b/pandora/archive/migrations/0008_file_filename_file_folder.py new file mode 100644 index 00000000..5c8b34da --- /dev/null +++ b/pandora/archive/migrations/0008_file_filename_file_folder.py @@ -0,0 +1,32 @@ +# Generated by Django 4.2.7 on 2025-01-23 10:48 + +from django.db import migrations, models + +def update_path(apps, schema_editor): + File = apps.get_model("archive", "File") + for file in File.objects.all(): + if file.path: + parts = file.path.split('/') + file.filename = parts.pop() + file.folder = '/'.join(parts) + file.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('archive', '0007_stream_archive_str_file_id_69a542_idx'), + ] + + operations = [ + migrations.AddField( + model_name='file', + name='filename', + field=models.CharField(default='', max_length=2048), + ), + migrations.AddField( + model_name='file', + name='folder', + field=models.CharField(default='', max_length=2048), + ), + migrations.RunPython(update_path), + ] diff --git a/pandora/archive/models.py b/pandora/archive/models.py index a5800d3d..96e5a477 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -53,6 +53,9 @@ class File(models.Model): path = models.CharField(max_length=2048, default="") # canoncial path/file sort_path = models.CharField(max_length=2048, default="") # sort name + folder = models.CharField(max_length=2048, default="") + filename = models.CharField(max_length=2048, default="") + type = models.CharField(default="", max_length=255) # editable @@ -194,6 +197,13 @@ class File(models.Model): data['part'] = str(data['part']) return data + def update_path(self): + path = self.normalize_path() + parts = path.split('/') + self.filename = parts.pop() + self.folder = '/'.join(parts) + return path + def normalize_path(self): # FIXME: always use format_path if settings.CONFIG['site']['folderdepth'] == 4: @@ -257,7 +267,7 @@ class File(models.Model): update_path = False if self.info: if self.id: - self.path = self.normalize_path() + self.path = self.update_path() else: update_path = True if self.item: @@ -290,7 +300,7 @@ class File(models.Model): self.streams.filter(source=None, available=True).count() super(File, self).save(*args, **kwargs) if update_path: - self.path = self.normalize_path() + self.path = self.update_path() super(File, self).save(*args, **kwargs) def get_path(self, name): @@ -474,6 +484,9 @@ class File(models.Model): 'videoCodec': self.video_codec, 'wanted': self.wanted, } + for key in ('folder', 'filename'): + if key in keys: + data[key] = getattr(self, key) if error: data['error'] = error for key in self.PATH_INFO: diff --git a/static/js/mediaView.js b/static/js/mediaView.js index f7773148..c453c7f7 100644 --- a/static/js/mediaView.js +++ b/static/js/mediaView.js @@ -142,6 +142,22 @@ pandora.ui.mediaView = function(options) { visible: true, width: 360 }, + { + align: 'left', + id: 'folder', + operator: '+', + title: Ox._('Folder'), + visible: false, + width: 360 + }, + { + align: 'left', + id: 'filename', + operator: '+', + title: Ox._('Filename'), + visible: false, + width: 360 + }, { editable: true, id: 'version',