add folder/filename columns to media view

This commit is contained in:
j 2025-01-23 16:26:25 +05:30
parent 10c78fc862
commit 38618e2ed2
3 changed files with 63 additions and 2 deletions

View file

@ -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),
]

View file

@ -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:

View file

@ -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',