add folder/filename columns to media view
This commit is contained in:
parent
10c78fc862
commit
38618e2ed2
3 changed files with 63 additions and 2 deletions
32
pandora/archive/migrations/0008_file_filename_file_folder.py
Normal file
32
pandora/archive/migrations/0008_file_filename_file_folder.py
Normal 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),
|
||||||
|
]
|
|
@ -53,6 +53,9 @@ class File(models.Model):
|
||||||
path = models.CharField(max_length=2048, default="") # canoncial path/file
|
path = models.CharField(max_length=2048, default="") # canoncial path/file
|
||||||
sort_path = models.CharField(max_length=2048, default="") # sort name
|
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)
|
type = models.CharField(default="", max_length=255)
|
||||||
|
|
||||||
# editable
|
# editable
|
||||||
|
@ -194,6 +197,13 @@ class File(models.Model):
|
||||||
data['part'] = str(data['part'])
|
data['part'] = str(data['part'])
|
||||||
return data
|
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):
|
def normalize_path(self):
|
||||||
# FIXME: always use format_path
|
# FIXME: always use format_path
|
||||||
if settings.CONFIG['site']['folderdepth'] == 4:
|
if settings.CONFIG['site']['folderdepth'] == 4:
|
||||||
|
@ -257,7 +267,7 @@ class File(models.Model):
|
||||||
update_path = False
|
update_path = False
|
||||||
if self.info:
|
if self.info:
|
||||||
if self.id:
|
if self.id:
|
||||||
self.path = self.normalize_path()
|
self.path = self.update_path()
|
||||||
else:
|
else:
|
||||||
update_path = True
|
update_path = True
|
||||||
if self.item:
|
if self.item:
|
||||||
|
@ -290,7 +300,7 @@ class File(models.Model):
|
||||||
self.streams.filter(source=None, available=True).count()
|
self.streams.filter(source=None, available=True).count()
|
||||||
super(File, self).save(*args, **kwargs)
|
super(File, self).save(*args, **kwargs)
|
||||||
if update_path:
|
if update_path:
|
||||||
self.path = self.normalize_path()
|
self.path = self.update_path()
|
||||||
super(File, self).save(*args, **kwargs)
|
super(File, self).save(*args, **kwargs)
|
||||||
|
|
||||||
def get_path(self, name):
|
def get_path(self, name):
|
||||||
|
@ -474,6 +484,9 @@ class File(models.Model):
|
||||||
'videoCodec': self.video_codec,
|
'videoCodec': self.video_codec,
|
||||||
'wanted': self.wanted,
|
'wanted': self.wanted,
|
||||||
}
|
}
|
||||||
|
for key in ('folder', 'filename'):
|
||||||
|
if key in keys:
|
||||||
|
data[key] = getattr(self, key)
|
||||||
if error:
|
if error:
|
||||||
data['error'] = error
|
data['error'] = error
|
||||||
for key in self.PATH_INFO:
|
for key in self.PATH_INFO:
|
||||||
|
|
|
@ -142,6 +142,22 @@ pandora.ui.mediaView = function(options) {
|
||||||
visible: true,
|
visible: true,
|
||||||
width: 360
|
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,
|
editable: true,
|
||||||
id: 'version',
|
id: 'version',
|
||||||
|
|
Loading…
Reference in a new issue