From 55b86bdac8a9871848eb54cf50b285979eaaae8c Mon Sep 17 00:00:00 2001 From: j Date: Tue, 20 Nov 2018 16:15:08 +0100 Subject: [PATCH 1/3] use get_or_create(defaults...) --- pandora/annotation/models.py | 5 +---- pandora/app/views.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 333aaf0f..470af358 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -270,10 +270,7 @@ class Annotation(models.Model): from translation.models import Translation layer = self.get_layer() if layer.get('translate'): - t, created = Translation.objects.get_or_create(lang=lang, key=self.value) - if created: - t.type = Translation.CONTENT - t.save() + Translation.objects.get_or_create(lang=lang, key=self.value, defaults={'type': Translation.CONTENT}) def delete(self, *args, **kwargs): with transaction.atomic(): diff --git a/pandora/app/views.py b/pandora/app/views.py index c0da9ede..8bd0fbfa 100644 --- a/pandora/app/views.py +++ b/pandora/app/views.py @@ -118,10 +118,7 @@ def getPage(request, data): name = data else: name = data['name'] - page, created = models.Page.objects.get_or_create(name=name) - if created: - page.text = '' - page.save() + page, created = models.Page.objects.get_or_create(name=name, defaults={'text': ''}) response = json_response({'name': page.name, 'text': page.text}) return render_to_json_response(response) actions.register(getPage) From 708a5b1b33e6f229dd16999dcd22fc39b7d528fc Mon Sep 17 00:00:00 2001 From: j Date: Tue, 4 Dec 2018 19:14:24 +0100 Subject: [PATCH 2/3] don't fail for int --- pandora/document/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandora/document/models.py b/pandora/document/models.py index 1a824734..268302b5 100644 --- a/pandora/document/models.py +++ b/pandora/document/models.py @@ -235,6 +235,8 @@ class Document(models.Model): value = self.get_value(source, u'') if isinstance(value, list): value = u','.join(value) + if not isinstance(value, str): + value = str(value) value = utils.sort_string(value)[:955] set_value(s, name, value) elif sort_type == 'words': From 9730b046ceeddcf9de99de57fbc6e159fcd20041 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 5 Dec 2018 10:10:14 +0100 Subject: [PATCH 3/3] document preview --- static/js/collection.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/static/js/collection.js b/static/js/collection.js index 60185906..d8296de4 100644 --- a/static/js/collection.js +++ b/static/js/collection.js @@ -137,8 +137,10 @@ pandora.ui.collection = function() { that.bindEvent({ closepreview: function(data) { - pandora.$ui.previewDialog.close(); - delete pandora.$ui.previewDialog; + if (pandora.$ui.documentDialog) { + pandora.$ui.documentDialog.close(); + delete pandora.$ui.documentDialog; + } }, copy: function(data) { pandora.clipboard.copy(data.ids, 'document'); @@ -227,20 +229,25 @@ pandora.ui.collection = function() { pandora.UI.set(set); }, openpreview: function(data) { - /* - if (!pandora.$ui.previewDialog) { - pandora.$ui.previewDialog = pandora.ui.previewDialog() - .open() - .bindEvent({ - close: function() { - that.closePreview(); - delete pandora.$ui.previewDialog; - } - }); + if (!pandora.$ui.documentDialog) { + pandora.$ui.documentDialog = pandora.openDocumentDialog({ + documents: that.options('selected').map(function(id) { + return that.value(id); + }) + }).bindEvent({ + close: function() { + that.closePreview(); + delete pandora.$ui.documentDialog; + } + }); } else { - pandora.$ui.previewDialog.update(); + pandora.$ui.documentDialog.update({ + index: 0, + items: that.options('selected').map(function(id) { + return that.value(id); + }) + }); } - */ }, paste: function(data) { var items = pandora.clipboard.paste();