towards njp.ma
This commit is contained in:
parent
a7c48d557d
commit
b24ba91bfc
23 changed files with 167 additions and 524 deletions
|
|
@ -3,6 +3,13 @@ from django.conf import settings
|
|||
import ox
|
||||
from ... import models
|
||||
|
||||
|
||||
def escape(key):
|
||||
return key.replace('%', '%25').replace('&', '%26').replace('_', '%09').replace(' ', '_').replace('<', '%0E').replace('>', '%0F')
|
||||
|
||||
def escape_slug(key):
|
||||
return key.replace('%', '').replace('&', '-').replace('_', '-').replace(' ', '-').replace('<', '').replace('>', '').lower()
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'import titles from pan.do/ra'
|
||||
|
||||
|
|
@ -12,38 +19,42 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **options):
|
||||
api = ox.api.signin(options['api'])
|
||||
|
||||
query = {
|
||||
'query': {
|
||||
'conditions': [{'key': 'groups', 'value': options['group'], 'operator': '=='}]
|
||||
},
|
||||
'keys': [
|
||||
'id', 'title', 'director', 'summary', 'source', 'sourcedescription', 'date', 'location',
|
||||
'duration', 'featuring', 'cinematographer',
|
||||
'hue', 'saturation', 'lightness',
|
||||
'folder', 'folderdescription'
|
||||
],
|
||||
'range': [0, 1000]
|
||||
}
|
||||
folders = {}
|
||||
for item in api.find(**query)['data']['items']:
|
||||
print(item)
|
||||
f, c = models.Film.objects.get_or_create(padma_id=item['id'])
|
||||
if item['folder'] not in folders:
|
||||
folders[item['folder']] = {
|
||||
'title': item['folder'],
|
||||
'description': item['folderdescription'],
|
||||
'url': api.url.replace('/api/', '/grid/folder==' + escape(item['folder'])),
|
||||
'items': [],
|
||||
}
|
||||
del item['folderdescription']
|
||||
if item['summary'] == folders[item['folder']]['description']:
|
||||
item['summary'] = ''
|
||||
folders[item['folder']]['items'].append(item)
|
||||
|
||||
for item in folders.values():
|
||||
if not item['description'] and len(item['items']) == 1:
|
||||
item['description'] = item['items'][0]['summary']
|
||||
item['items'][0]['summary'] = ''
|
||||
f, c = models.Film.objects.get_or_create(pandora_url=item['url'])
|
||||
for key, value in item.items():
|
||||
if key == 'title':
|
||||
if ' / ' in value:
|
||||
f.data['title'], f.data['title_zh'] = value.split(' / ', 1)
|
||||
else:
|
||||
f.data['title'] = value
|
||||
f.data['title_zh'] = ''
|
||||
elif key == 'summary':
|
||||
f.data['summary'], f.data['summary_zh'] = value.split('<br><br>', 1)
|
||||
elif key == 'sourcedescription':
|
||||
if '<br><br>' in value:
|
||||
f.data['bio'], f.data['bio_zh'] = value.split('<br><br>', 1)
|
||||
else:
|
||||
f.data['bio'] = f.data['bio_zh'] = value
|
||||
elif key != 'id':
|
||||
if key != 'url':
|
||||
f.data[{
|
||||
}.get(key, key)] = value
|
||||
if c:
|
||||
f.public = True
|
||||
f.slug = item['id']
|
||||
f.slug = escape_slug(item['title'])
|
||||
f.save()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.2.7 on 2021-09-28 12:09
|
||||
# Generated by Django 3.2.9 on 2021-11-12 09:35
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
@ -11,20 +11,6 @@ class Migration(migrations.Migration):
|
|||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Edit',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('modified', models.DateTimeField(auto_now=True)),
|
||||
('slug', models.SlugField()),
|
||||
('public', models.BooleanField(default=False)),
|
||||
('padma_id', models.CharField(max_length=1024)),
|
||||
('annotation_user', models.CharField(max_length=1024)),
|
||||
('vimeo_id', models.CharField(default=None, max_length=255, null=True)),
|
||||
('data', models.JSONField(default=dict)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Film',
|
||||
fields=[
|
||||
|
|
@ -33,9 +19,9 @@ class Migration(migrations.Migration):
|
|||
('modified', models.DateTimeField(auto_now=True)),
|
||||
('slug', models.SlugField()),
|
||||
('public', models.BooleanField(default=False)),
|
||||
('padma_id', models.CharField(max_length=255)),
|
||||
('vimeo_id', models.CharField(default=None, max_length=255, null=True)),
|
||||
('data', models.JSONField(default=dict)),
|
||||
('position', models.IntegerField(default=0)),
|
||||
('pandora_url', models.CharField(max_length=1024)),
|
||||
('data', models.JSONField(blank=True, default=dict)),
|
||||
],
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
# Generated by Django 3.2.7 on 2021-09-30 15:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('video', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='edit',
|
||||
name='data',
|
||||
field=models.JSONField(blank=True, default=dict),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='film',
|
||||
name='data',
|
||||
field=models.JSONField(blank=True, default=dict),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 3.2.7 on 2021-10-11 12:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('video', '0002_auto_20210930_1527'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='film',
|
||||
name='position',
|
||||
field=models.IntegerField(default=0),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 3.2.7 on 2021-10-23 09:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('video', '0003_film_position'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='film',
|
||||
name='vimeo_id',
|
||||
field=models.CharField(blank=True, null=True, default=None, max_length=255),
|
||||
),
|
||||
]
|
||||
|
|
@ -20,8 +20,7 @@ class Film(models.Model):
|
|||
public = models.BooleanField(default=False)
|
||||
position = models.IntegerField(default=0)
|
||||
|
||||
padma_id = models.CharField(max_length=255)
|
||||
vimeo_id = models.CharField(max_length=255, default=None, blank=True, null=True)
|
||||
pandora_url = models.CharField(max_length=1024)
|
||||
|
||||
data = models.JSONField(default=dict, blank=True)
|
||||
|
||||
|
|
@ -33,7 +32,9 @@ class Film(models.Model):
|
|||
|
||||
def related_texts(self):
|
||||
from ..text.models import Text
|
||||
return Text.objects.filter(Q(data__item=self.padma_id) | Q(data__related=self.padma_id))
|
||||
folder = self.data.get('title')
|
||||
if folder:
|
||||
return Text.objects.filter(Q(data__folder=folder) | Q(data__related=folder))
|
||||
|
||||
def duration(self):
|
||||
return ox.format_duration(self.data['duration'] * 1000, verbosity=1, milliseconds=False)
|
||||
|
|
@ -68,23 +69,8 @@ class Film(models.Model):
|
|||
|
||||
def json(self):
|
||||
data = {}
|
||||
data['id'] = self.padma_id
|
||||
data['url'] = self.pandora_url
|
||||
#data.update(self.data)
|
||||
return json.dumps(data)
|
||||
|
||||
|
||||
class Edit(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
slug = models.SlugField()
|
||||
public = models.BooleanField(default=False)
|
||||
|
||||
padma_id = models.CharField(max_length=1024)
|
||||
annotation_user = models.CharField(max_length=1024)
|
||||
vimeo_id = models.CharField(max_length=255, default=None, null=True)
|
||||
|
||||
data = models.JSONField(default=dict, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.data.get('title', self.slug)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue