From d645ec24313bb726ce2e758707a638396c245142 Mon Sep 17 00:00:00 2001
From: Erwan Rouchet <rouchet@teklia.com>
Date: Tue, 18 Apr 2023 12:28:30 +0000
Subject: [PATCH] Export Transcription.orientation

---
 arkindex/documents/export/structure.sql               | 4 +++-
 arkindex/documents/export/transcription.sql           | 1 +
 arkindex/documents/management/commands/load_export.py | 1 +
 arkindex/documents/tests/tasks/test_export.py         | 3 ++-
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arkindex/documents/export/structure.sql b/arkindex/documents/export/structure.sql
index d233ab243d..b82d67c24a 100644
--- a/arkindex/documents/export/structure.sql
+++ b/arkindex/documents/export/structure.sql
@@ -73,11 +73,13 @@ CREATE TABLE transcription (
     element_id VARCHAR(37) NOT NULL,
     text TEXT NOT NULL,
     confidence REAL,
+    orientation TEXT NOT NULL DEFAULT 'horizontal-lr',
     worker_version_id VARCHAR(37),
     PRIMARY KEY (id),
     FOREIGN KEY (element_id) REFERENCES element (id) ON DELETE CASCADE,
     FOREIGN KEY (worker_version_id) REFERENCES worker_version (id) ON DELETE CASCADE,
-    CHECK (confidence IS NULL OR (confidence >= 0 AND confidence <= 1))
+    CHECK (confidence IS NULL OR (confidence >= 0 AND confidence <= 1)),
+    CHECK (orientation IN ('horizontal-lr', 'horizontal-rl', 'vertical-lr', 'vertical-rl'))
 );
 
 CREATE TABLE classification (
diff --git a/arkindex/documents/export/transcription.sql b/arkindex/documents/export/transcription.sql
index 1dc0f0402a..251497e89d 100644
--- a/arkindex/documents/export/transcription.sql
+++ b/arkindex/documents/export/transcription.sql
@@ -3,6 +3,7 @@ SELECT
     transcription.element_id,
     transcription.text,
     transcription.confidence,
+    transcription.orientation,
     transcription.worker_version_id
 FROM documents_transcription transcription
 INNER JOIN documents_element element ON (element.id = transcription.element_id)
diff --git a/arkindex/documents/management/commands/load_export.py b/arkindex/documents/management/commands/load_export.py
index f3ff303c9a..9b325aaeb6 100644
--- a/arkindex/documents/management/commands/load_export.py
+++ b/arkindex/documents/management/commands/load_export.py
@@ -250,6 +250,7 @@ class Command(BaseCommand):
             element_id=row["element_id"],
             text=row["text"],
             confidence=row["confidence"],
+            orientation=row["orientation"],
             worker_version_id=self.worker_version_map[row["worker_version_id"]] if row["worker_version_id"] else None,
         )]
 
diff --git a/arkindex/documents/tests/tasks/test_export.py b/arkindex/documents/tests/tasks/test_export.py
index 5396b92b5b..3b35f95e56 100644
--- a/arkindex/documents/tests/tasks/test_export.py
+++ b/arkindex/documents/tests/tasks/test_export.py
@@ -286,13 +286,14 @@ class TestExport(FixtureTestCase):
         )
 
         self.assertCountEqual(
-            db.execute("SELECT id, element_id, text, confidence, worker_version_id FROM transcription").fetchall(),
+            db.execute("SELECT id, element_id, text, confidence, orientation, worker_version_id FROM transcription").fetchall(),
             [
                 (
                     str(transcription.id),
                     str(transcription.element_id),
                     transcription.text,
                     transcription.confidence,
+                    transcription.orientation.value,
                     str(transcription.worker_version_id) if transcription.worker_version_id else None
                 )
                 for transcription in Transcription.objects.filter(element__corpus=self.corpus)
-- 
GitLab