From f591f66634e82b9443f788df4e8bb97d86bd0e58 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 4 Aug 2018 16:51:43 +0100 Subject: [PATCH 1/4] try date formats --- pandora/item/models.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index fe7ad08a..7ee4efa8 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1032,9 +1032,16 @@ class Item(models.Model): elif sort_type == 'date': value = self.get(source) if isinstance(value, string_types): - value = datetime_safe.datetime.strptime(value, '%Y-%m-%d') - set_value(s, name, value) - + value_ = None + for fmt in ('%Y-%m-%d', '%Y-%m', '%Y'): + try: + value_ = datetime_safe.datetime.strptime(value, fmt) + except ValueError: + pass + else: + continue + if value_ is not None: + set_value(s, name, value_) s.save() def update_facet(self, key): From 72358a7bceb71180b77f508feaffb0f2b28468d2 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 4 Aug 2018 15:56:30 +0000 Subject: [PATCH 2/4] add stream.flags --- .../migrations/0005_auto_20180804_1554.py | 22 +++++++++++++++++++ pandora/archive/models.py | 5 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 pandora/archive/migrations/0005_auto_20180804_1554.py diff --git a/pandora/archive/migrations/0005_auto_20180804_1554.py b/pandora/archive/migrations/0005_auto_20180804_1554.py new file mode 100644 index 00000000..43291125 --- /dev/null +++ b/pandora/archive/migrations/0005_auto_20180804_1554.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.13 on 2018-08-04 15:54 +from __future__ import unicode_literals + +import django.core.serializers.json +from django.db import migrations, models +import oxdjango.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('archive', '0004_jsonfield'), + ] + + operations = [ + migrations.AddField( + model_name='stream', + name='flags', + field=oxdjango.fields.JSONField(default=dict, editable=False, encoder=django.core.serializers.json.DjangoJSONEncoder), + ), + ] diff --git a/pandora/archive/models.py b/pandora/archive/models.py index 0e0d5c84..ec0986e9 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -521,7 +521,7 @@ class File(models.Model): n += 1 profile = '%sp.%s' % (resolution, config['formats'][0]) target = os.path.join(tmp, language + '_' + profile) - ok, error = extract.stream(media, target, profile, info, audio_track=i+1) + ok, error = extract.stream(media, target, profile, info, audio_track=i+1, flags=self.flags) if ok: tinfo = ox.avinfo(target) del tinfo['path'] @@ -691,6 +691,7 @@ class Stream(models.Model): available = models.BooleanField(default=False) oshash = models.CharField(max_length=16, null=True, db_index=True) info = JSONField(default=dict, editable=False) + flags = JSONField(default=dict, editable=False) duration = models.FloatField(default=0) aspect_ratio = models.FloatField(default=0) @@ -750,7 +751,7 @@ class Stream(models.Model): self.media.name = self.path(self.name()) target = self.media.path info = ox.avinfo(media) - ok, error = extract.stream(media, target, self.name(), info) + ok, error = extract.stream(media, target, self.name(), info, flags=self.flags) # file could have been moved while encoding # get current version from db and update _self = Stream.objects.get(id=self.id) From 4e4d64febc02fbf199f759999f0362e7abcc6d51 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 5 Aug 2018 19:07:31 +0100 Subject: [PATCH 3/4] unify date parsing and fall back to raw value if it failed --- static/js/documentInfoView.js | 7 ++----- static/js/infoView.padma.js | 14 +------------- static/js/utils.js | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/static/js/documentInfoView.js b/static/js/documentInfoView.js index 99da3df5..9d6c1010 100644 --- a/static/js/documentInfoView.js +++ b/static/js/documentInfoView.js @@ -412,11 +412,8 @@ pandora.ui.documentInfoView = function(data) { function formatValue(key, value) { var ret; - if (key == 'date') { - ret = value ? Ox.formatDate(value, - ['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length], - true - ) : ''; + if (key == 'date' && (!value || value.split('-').length < 4)) { + ret = pandora.formatDate(value); } else if (nameKeys.indexOf(key) > -1) { ret = formatLink(value.split(', '), key); } else if (listKeys.indexOf(key) > -1) { diff --git a/static/js/infoView.padma.js b/static/js/infoView.padma.js index 7a88f66b..3bc49b35 100644 --- a/static/js/infoView.padma.js +++ b/static/js/infoView.padma.js @@ -594,19 +594,7 @@ pandora.ui.infoView = function(data) { function formatValue(key, value) { var ret; if (key == 'date' && (!value || value.split('-').length < 4)) { - if (!value) { - ret = '' - } else if (Ox.contains(value, ':') && value.split('-').length == 3) { - ret = Ox.formatDate(value, - ['', '', '%B %e, %Y %H:%M', '%B %e, %Y %H:%M:%S'][value.split(':').length], - false - ); - } else { - ret = Ox.formatDate(value, - ['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length], - true - ); - } + ret = pandora.formatDate(value); } else if (listKeys.indexOf(key) > -1) { ret = value.split(', '); } else { diff --git a/static/js/utils.js b/static/js/utils.js index 22612883..097d7e4f 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1115,6 +1115,27 @@ pandora.formatDocumentKey = function(key, data, size) { return value; } +pandora.formatDate = function(value) { + var ret; + if (!value) { + ret = '' + } else if (Ox.contains(value, ':') && value.split('-').length == 3) { + ret = Ox.formatDate(value, + ['', '', '%B %e, %Y %H:%M', '%B %e, %Y %H:%M:%S'][value.split(':').length], + false + ); + } else { + ret = Ox.formatDate(value, + ['', '%Y', '%B %Y', '%B %e, %Y'][value.split('-').length], + true + ); + } + if (ret.trim() == 'NaN') { + ret = value; + } + return ret; +} + pandora.getAllItemsTitle = function(section) { section = section || pandora.user.ui.section; return { From e7fce4cf26d228a1aa53ff93c3a4bcbe172d7314 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 7 Aug 2018 17:13:35 +0100 Subject: [PATCH 4/4] limit highlight to current search --- static/js/editor.js | 1 + 1 file changed, 1 insertion(+) diff --git a/static/js/editor.js b/static/js/editor.js index 9e9cb826..da85b5b1 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -26,6 +26,7 @@ pandora.ui.editor = function(data) { enableSetPosterFrame: !pandora.site.media.importFrames && data.editable, enableSubtitles: ui.videoSubtitles, find: ui.itemFind, + findLayer: pandora.user.ui._findState.key, getFrameURL: function(position) { return pandora.getMediaURL('/' + ui.item + '/' + ui.videoResolution + 'p' + position + '.jpg?' + data.modified); },