diff --git a/config/settings/base.py b/config/settings/base.py index b6977c6..f15b604 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -82,6 +82,7 @@ "reference", "xml_manager", "model_ai", + "markup_doc", ] INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS + WAGTAIL @@ -300,5 +301,18 @@ LLAMA_ENABLED = env.bool("LLAMA_ENABLED", default=True) MODEL_LLAMA = "llama-3.2-3b-instruct-q4_k_m.gguf" +# Core API +CORE_API_DOMAIN = env("CORE_API_DOMAIN", default="https://core.scielo.org") +CORE_COLLECTION_API_ENDPOINT = env( + "CORE_COLLECTION_API_ENDPOINT", + default="/api/v2/pid/collection/", +) +CORE_JOURNAL_API_ENDPOINT = env( + "CORE_JOURNAL_API_ENDPOINT", + default="/api/v2/pid/journal/", +) +CORE_COLLECTION_API_URL = f"{CORE_API_DOMAIN}{CORE_COLLECTION_API_ENDPOINT}" +CORE_JOURNAL_API_URL = f"{CORE_API_DOMAIN}{CORE_JOURNAL_API_ENDPOINT}" + #Aumento en el límite de campos DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000 \ No newline at end of file diff --git a/fixtures/Artigo 5.docx b/fixtures/Artigo 5.docx new file mode 100644 index 0000000..5fbf592 Binary files /dev/null and b/fixtures/Artigo 5.docx differ diff --git a/fixtures/e14790.docx b/fixtures/e14790.docx new file mode 100644 index 0000000..36bb9d0 Binary files /dev/null and b/fixtures/e14790.docx differ diff --git a/fixtures/e740.docx b/fixtures/e740.docx new file mode 100644 index 0000000..25240d4 Binary files /dev/null and b/fixtures/e740.docx differ diff --git a/markup_doc/__init__.py b/markup_doc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/markup_doc/admin.py b/markup_doc/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/markup_doc/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/markup_doc/apps.py b/markup_doc/apps.py new file mode 100644 index 0000000..87efcb1 --- /dev/null +++ b/markup_doc/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MarkupDocConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "markup_doc" diff --git a/markup_doc/choices.py b/markup_doc/choices.py new file mode 100644 index 0000000..8ebae82 --- /dev/null +++ b/markup_doc/choices.py @@ -0,0 +1,75 @@ +front_labels = [ + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("", ""), + ("

", "

"), + ("", ""), + ("", ""), + ("", ""), + ("", "
"), + ("", ""), + ("", "<title>"), + ("<trans-abstract>", "<trans-abstract>"), + ("<trans-title>", "<trans-title>"), + ("<translate-front>", "<translate-front>"), + ("<translate-body>", "<translate-body>"), + ("<disp-formula>", "<disp-formula>"), + ("<inline-formula>", "<inline-formula>"), + ("<formula>", "<formula>"), +] + +order_labels = { + "<article-id>": {"pos": 1, "next": "<subject>"}, + "<subject>": {"pos": 2, "next": "<article-title>"}, + "<article-title>": {"pos": 3, "next": "<trans-title>", "lan": True}, + "<trans-title>": {"size": 14, "bold": True, "lan": True, "next": "<contrib>"}, + "<contrib>": {"reset": True, "size": 12, "next": "<aff>"}, + "<aff>": { + "reset": True, + "size": 12, + }, + "<abstract>": {"size": 12, "bold": True, "lan": True, "next": "<p>"}, + "<p>": {"size": 12, "next": "<p>", "repeat": True}, + "<trans-abstract>": {"size": 12, "bold": True, "lan": True, "next": "<p>"}, + "<kwd-group>": { + "size": 12, + "regex": r"(?i)(palabra.*clave.*:|keyword.*:)", + }, + "<history>": { + "size": 12, + "regex": r"\d{2}/\d{2}/\d{4}", + }, + "<corresp>": { + "size": 12, + "regex": r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}", + }, + "<sec>": {"size": 16, "bold": True, "next": None}, + "<sub-sec>": {"size": 12, "italic": True, "next": None}, + "<sub-sec-2>": {"size": 14, "bold": True, "next": None}, +} + +order_labels_body = { + "<sec>": { + "size": 16, + "bold": True, + }, + "<sub-sec>": { + "size": 12, + "italic": True, + }, + "<p>": { + "size": 12, + }, +} diff --git a/markup_doc/forms.py b/markup_doc/forms.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/markup_doc/forms.py @@ -0,0 +1 @@ + diff --git a/markup_doc/migrations/0001_initial.py b/markup_doc/migrations/0001_initial.py new file mode 100644 index 0000000..74340ef --- /dev/null +++ b/markup_doc/migrations/0001_initial.py @@ -0,0 +1,2291 @@ +# Generated by Django 5.0.3 on 2025-09-07 17:04 + +import django.db.models.deletion +import markup_doc.models +import wagtail.blocks +import wagtail.fields +import wagtail.images.blocks +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="CollectionValuesModel", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("acron", models.CharField(max_length=10, unique=True)), + ("name", models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name="ArticleDocx", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "created", + models.DateTimeField( + auto_now_add=True, verbose_name="Creation date" + ), + ), + ( + "updated", + models.DateTimeField( + auto_now=True, verbose_name="Last update date" + ), + ), + ( + "title", + models.TextField( + blank=True, null=True, verbose_name="Document Title" + ), + ), + ( + "file", + models.FileField( + blank=True, + null=True, + upload_to="uploads_docx/", + verbose_name="Document", + ), + ), + ("estatus", models.IntegerField(default=0)), + ( + "creator", + models.ForeignKey( + editable=False, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="%(class)s_creator", + to=settings.AUTH_USER_MODEL, + verbose_name="Creator", + ), + ), + ( + "updated_by", + models.ForeignKey( + blank=True, + editable=False, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="%(class)s_last_mod_user", + to=settings.AUTH_USER_MODEL, + verbose_name="Updater", + ), + ), + ], + options={ + "abstract": False, + }, + ), + migrations.CreateModel( + name="ArticleDocxMarkup", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "created", + models.DateTimeField( + auto_now_add=True, verbose_name="Creation date" + ), + ), + ( + "updated", + models.DateTimeField( + auto_now=True, verbose_name="Last update date" + ), + ), + ( + "title", + models.TextField( + blank=True, null=True, verbose_name="Document Title" + ), + ), + ( + "file", + models.FileField( + blank=True, + null=True, + upload_to="uploads_docx/", + verbose_name="Document", + ), + ), + ("estatus", models.IntegerField(default=0)), + ( + "collection", + models.CharField( + default=markup_doc.models.get_default_collection_acron, + max_length=10, + ), + ), + ( + "journal_title", + models.TextField( + blank=True, null=True, verbose_name="Journal Title" + ), + ), + ( + "acronym", + models.TextField(blank=True, null=True, verbose_name="Acronym"), + ), + ( + "short_title", + models.TextField(blank=True, null=True, verbose_name="Short Title"), + ), + ( + "title_nlm", + models.TextField(blank=True, null=True, verbose_name="NLM Title"), + ), + ( + "issn", + models.TextField( + blank=True, null=True, verbose_name="ISSN (id SciELO)" + ), + ), + ( + "pissn", + models.TextField(blank=True, null=True, verbose_name="Print ISSN"), + ), + ( + "eissn", + models.TextField( + blank=True, null=True, verbose_name="Electronic ISSN" + ), + ), + ( + "nimtitle", + models.TextField(blank=True, null=True, verbose_name="Nimtitle"), + ), + ( + "pubname", + models.TextField( + blank=True, null=True, verbose_name="Publisher Name" + ), + ), + ( + "license", + models.URLField( + blank=True, + max_length=500, + null=True, + verbose_name="License (URL)", + ), + ), + ( + "vol", + models.IntegerField(blank=True, null=True, verbose_name="Volume"), + ), + ( + "supplvol", + models.IntegerField( + blank=True, null=True, verbose_name="Suppl Volume" + ), + ), + ( + "issue", + models.IntegerField(blank=True, null=True, verbose_name="Issue"), + ), + ( + "supplno", + models.IntegerField( + blank=True, null=True, verbose_name="Suppl Num" + ), + ), + ( + "issid_part", + models.TextField(blank=True, null=True, verbose_name="Isid Part"), + ), + ( + "dateiso", + models.TextField(blank=True, null=True, verbose_name="Dateiso"), + ), + ( + "month", + models.TextField( + blank=True, null=True, verbose_name="Month/Season" + ), + ), + ( + "fpage", + models.TextField(blank=True, null=True, verbose_name="First Page"), + ), + ("seq", models.TextField(blank=True, null=True, verbose_name="@Seq")), + ( + "lpage", + models.TextField(blank=True, null=True, verbose_name="Last Page"), + ), + ( + "elocatid", + models.TextField( + blank=True, null=True, verbose_name="Elocation ID" + ), + ), + ( + "order", + models.TextField( + blank=True, null=True, verbose_name="Order (In TOC)" + ), + ), + ( + "pagcount", + models.TextField(blank=True, null=True, verbose_name="Pag count"), + ), + ( + "doctopic", + models.TextField(blank=True, null=True, verbose_name="Doc Topic"), + ), + ( + "language", + models.CharField( + blank=True, + choices=[ + ("aa", "Afar"), + ("af", "Afrikaans"), + ("ak", "Akan"), + ("sq", "Albanian"), + ("am", "Amharic"), + ("ar", "Arabic"), + ("an", "Aragonese"), + ("hy", "Armenian"), + ("as", "Assamese"), + ("av", "Avaric"), + ("ae", "Avestan"), + ("ay", "Aymara"), + ("az", "Azerbaijani"), + ("bm", "Bambara"), + ("ba", "Bashkir"), + ("eu", "Basque"), + ("be", "Belarusian"), + ("bn", "Bengali"), + ("bi", "Bislama"), + ("bs", "Bosnian"), + ("br", "Breton"), + ("bg", "Bulgarian"), + ("my", "Burmese"), + ("ca", "Catalan, Valencian"), + ("ch", "Chamorro"), + ("ce", "Chechen"), + ("ny", "Chichewa, Chewa, Nyanja"), + ("zh", "Chinese"), + ( + "cu", + "Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian, Old Church Slavonic", + ), + ("cv", "Chuvash"), + ("kw", "Cornish"), + ("co", "Corsican"), + ("cr", "Cree"), + ("hr", "Croatian"), + ("cs", "Czech"), + ("da", "Danish"), + ("dv", "Divehi, Dhivehi, Maldivian"), + ("nl", "Dutch, Flemish"), + ("dz", "Dzongkha"), + ("en", "English"), + ("eo", "Esperanto"), + ("et", "Estonian"), + ("ee", "Ewe"), + ("fo", "Faroese"), + ("fj", "Fijian"), + ("fi", "Finnish"), + ("fr", "French"), + ("fy", "Western Frisian"), + ("ff", "Fulah"), + ("gd", "Gaelic, Scottish Gaelic"), + ("gl", "Galician"), + ("lg", "Ganda"), + ("ka", "Georgian"), + ("de", "German"), + ("el", "Greek, Modern (1453–)"), + ("kl", "Kalaallisut, Greenlandic"), + ("gn", "Guarani"), + ("gu", "Gujarati"), + ("ht", "Haitian, Haitian Creole"), + ("ha", "Hausa"), + ("he", "Hebrew"), + ("hz", "Herero"), + ("hi", "Hindi"), + ("ho", "Hiri Motu"), + ("hu", "Hungarian"), + ("is", "Icelandic"), + ("io", "Ido"), + ("ig", "Igbo"), + ("id", "Indonesian"), + ( + "ia", + "Interlingua (International Auxiliary Language Association)", + ), + ("ie", "Interlingue, Occidental"), + ("iu", "Inuktitut"), + ("ik", "Inupiaq"), + ("ga", "Irish"), + ("it", "Italian"), + ("ja", "Japanese"), + ("jv", "Javanese"), + ("kn", "Kannada"), + ("kr", "Kanuri"), + ("ks", "Kashmiri"), + ("kk", "Kazakh"), + ("km", "Central Khmer"), + ("ki", "Kikuyu, Gikuyu"), + ("rw", "Kinyarwanda"), + ("ky", "Kirghiz, Kyrgyz"), + ("kv", "Komi"), + ("kg", "Kongo"), + ("ko", "Korean"), + ("kj", "Kuanyama, Kwanyama"), + ("ku", "Kurdish"), + ("lo", "Lao"), + ("la", "Latin"), + ("lv", "Latvian"), + ("li", "Limburgan, Limburger, Limburgish"), + ("ln", "Lingala"), + ("lt", "Lithuanian"), + ("lu", "Luba-Katanga"), + ("lb", "Luxembourgish, Letzeburgesch"), + ("mk", "Macedonian"), + ("mg", "Malagasy"), + ("ms", "Malay"), + ("ml", "Malayalam"), + ("mt", "Maltese"), + ("gv", "Manx"), + ("mi", "Maori"), + ("mr", "Marathi"), + ("mh", "Marshallese"), + ("mn", "Mongolian"), + ("na", "Nauru"), + ("nv", "Navajo, Navaho"), + ("nd", "North Ndebele"), + ("nr", "South Ndebele"), + ("ng", "Ndonga"), + ("ne", "Nepali"), + ("no", "Norwegian"), + ("nb", "Norwegian Bokmål"), + ("nn", "Norwegian Nynorsk"), + ("ii", "Sichuan Yi, Nuosu"), + ("oc", "Occitan"), + ("oj", "Ojibwa"), + ("or", "Oriya"), + ("om", "Oromo"), + ("os", "Ossetian, Ossetic"), + ("pi", "Pali"), + ("ps", "Pashto, Pushto"), + ("fa", "Persian"), + ("pl", "Polish"), + ("pt", "Português"), + ("pa", "Punjabi, Panjabi"), + ("qu", "Quechua"), + ("ro", "Romanian, Moldavian, Moldovan"), + ("rm", "Romansh"), + ("rn", "Rundi"), + ("ru", "Russian"), + ("se", "Northern Sami"), + ("sm", "Samoan"), + ("sg", "Sango"), + ("sa", "Sanskrit"), + ("sc", "Sardinian"), + ("sr", "Serbian"), + ("sn", "Shona"), + ("sd", "Sindhi"), + ("si", "Sinhala, Sinhalese"), + ("sk", "Slovak"), + ("sl", "Slovenian"), + ("so", "Somali"), + ("st", "Southern Sotho"), + ("es", "Español"), + ("su", "Sundanese"), + ("sw", "Swahili"), + ("ss", "Swati"), + ("sv", "Swedish"), + ("tl", "Tagalog"), + ("ty", "Tahitian"), + ("tg", "Tajik"), + ("ta", "Tamil"), + ("tt", "Tatar"), + ("te", "Telugu"), + ("th", "Thai"), + ("bo", "Tibetan"), + ("ti", "Tigrinya"), + ("to", "Tonga (Tonga Islands)"), + ("ts", "Tsonga"), + ("tn", "Tswana"), + ("tr", "Turkish"), + ("tk", "Turkmen"), + ("tw", "Twi"), + ("ug", "Uighur, Uyghur"), + ("uk", "Ukrainian"), + ("ur", "Urdu"), + ("uz", "Uzbek"), + ("ve", "Venda"), + ("vi", "Vietnamese"), + ("vo", "Volapük"), + ("wa", "Walloon"), + ("cy", "Welsh"), + ("wo", "Wolof"), + ("xh", "Xhosa"), + ("yi", "Yiddish"), + ("yo", "Yoruba"), + ("za", "Zhuang, Chuang"), + ("zu", "Zulu"), + ], + max_length=10, + null=True, + verbose_name="Language", + ), + ), + ( + "spsversion", + models.TextField(blank=True, null=True, verbose_name="Sps version"), + ), + ( + "artdate", + models.DateField(blank=True, null=True, verbose_name="Artdate"), + ), + ( + "ahpdate", + models.DateField(blank=True, null=True, verbose_name="Ahpdate"), + ), + ( + "file_xml", + models.FileField( + blank=True, + null=True, + upload_to="generate_xml/", + verbose_name="Document xml", + ), + ), + ( + "text_xml", + models.TextField(blank=True, null=True, verbose_name="Text XML"), + ), + ( + "content", + wagtail.fields.StreamField( + [ + ( + "paragraph_with_language", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "language", + wagtail.blocks.ChoiceBlock( + choices=[ + ("aa", "Afar"), + ("af", "Afrikaans"), + ("ak", "Akan"), + ("sq", "Albanian"), + ("am", "Amharic"), + ("ar", "Arabic"), + ("an", "Aragonese"), + ("hy", "Armenian"), + ("as", "Assamese"), + ("av", "Avaric"), + ("ae", "Avestan"), + ("ay", "Aymara"), + ("az", "Azerbaijani"), + ("bm", "Bambara"), + ("ba", "Bashkir"), + ("eu", "Basque"), + ("be", "Belarusian"), + ("bn", "Bengali"), + ("bi", "Bislama"), + ("bs", "Bosnian"), + ("br", "Breton"), + ("bg", "Bulgarian"), + ("my", "Burmese"), + ("ca", "Catalan, Valencian"), + ("ch", "Chamorro"), + ("ce", "Chechen"), + ("ny", "Chichewa, Chewa, Nyanja"), + ("zh", "Chinese"), + ( + "cu", + "Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian, Old Church Slavonic", + ), + ("cv", "Chuvash"), + ("kw", "Cornish"), + ("co", "Corsican"), + ("cr", "Cree"), + ("hr", "Croatian"), + ("cs", "Czech"), + ("da", "Danish"), + ( + "dv", + "Divehi, Dhivehi, Maldivian", + ), + ("nl", "Dutch, Flemish"), + ("dz", "Dzongkha"), + ("en", "English"), + ("eo", "Esperanto"), + ("et", "Estonian"), + ("ee", "Ewe"), + ("fo", "Faroese"), + ("fj", "Fijian"), + ("fi", "Finnish"), + ("fr", "French"), + ("fy", "Western Frisian"), + ("ff", "Fulah"), + ("gd", "Gaelic, Scottish Gaelic"), + ("gl", "Galician"), + ("lg", "Ganda"), + ("ka", "Georgian"), + ("de", "German"), + ("el", "Greek, Modern (1453–)"), + ("kl", "Kalaallisut, Greenlandic"), + ("gn", "Guarani"), + ("gu", "Gujarati"), + ("ht", "Haitian, Haitian Creole"), + ("ha", "Hausa"), + ("he", "Hebrew"), + ("hz", "Herero"), + ("hi", "Hindi"), + ("ho", "Hiri Motu"), + ("hu", "Hungarian"), + ("is", "Icelandic"), + ("io", "Ido"), + ("ig", "Igbo"), + ("id", "Indonesian"), + ( + "ia", + "Interlingua (International Auxiliary Language Association)", + ), + ("ie", "Interlingue, Occidental"), + ("iu", "Inuktitut"), + ("ik", "Inupiaq"), + ("ga", "Irish"), + ("it", "Italian"), + ("ja", "Japanese"), + ("jv", "Javanese"), + ("kn", "Kannada"), + ("kr", "Kanuri"), + ("ks", "Kashmiri"), + ("kk", "Kazakh"), + ("km", "Central Khmer"), + ("ki", "Kikuyu, Gikuyu"), + ("rw", "Kinyarwanda"), + ("ky", "Kirghiz, Kyrgyz"), + ("kv", "Komi"), + ("kg", "Kongo"), + ("ko", "Korean"), + ("kj", "Kuanyama, Kwanyama"), + ("ku", "Kurdish"), + ("lo", "Lao"), + ("la", "Latin"), + ("lv", "Latvian"), + ( + "li", + "Limburgan, Limburger, Limburgish", + ), + ("ln", "Lingala"), + ("lt", "Lithuanian"), + ("lu", "Luba-Katanga"), + ( + "lb", + "Luxembourgish, Letzeburgesch", + ), + ("mk", "Macedonian"), + ("mg", "Malagasy"), + ("ms", "Malay"), + ("ml", "Malayalam"), + ("mt", "Maltese"), + ("gv", "Manx"), + ("mi", "Maori"), + ("mr", "Marathi"), + ("mh", "Marshallese"), + ("mn", "Mongolian"), + ("na", "Nauru"), + ("nv", "Navajo, Navaho"), + ("nd", "North Ndebele"), + ("nr", "South Ndebele"), + ("ng", "Ndonga"), + ("ne", "Nepali"), + ("no", "Norwegian"), + ("nb", "Norwegian Bokmål"), + ("nn", "Norwegian Nynorsk"), + ("ii", "Sichuan Yi, Nuosu"), + ("oc", "Occitan"), + ("oj", "Ojibwa"), + ("or", "Oriya"), + ("om", "Oromo"), + ("os", "Ossetian, Ossetic"), + ("pi", "Pali"), + ("ps", "Pashto, Pushto"), + ("fa", "Persian"), + ("pl", "Polish"), + ("pt", "Português"), + ("pa", "Punjabi, Panjabi"), + ("qu", "Quechua"), + ( + "ro", + "Romanian, Moldavian, Moldovan", + ), + ("rm", "Romansh"), + ("rn", "Rundi"), + ("ru", "Russian"), + ("se", "Northern Sami"), + ("sm", "Samoan"), + ("sg", "Sango"), + ("sa", "Sanskrit"), + ("sc", "Sardinian"), + ("sr", "Serbian"), + ("sn", "Shona"), + ("sd", "Sindhi"), + ("si", "Sinhala, Sinhalese"), + ("sk", "Slovak"), + ("sl", "Slovenian"), + ("so", "Somali"), + ("st", "Southern Sotho"), + ("es", "Español"), + ("su", "Sundanese"), + ("sw", "Swahili"), + ("ss", "Swati"), + ("sv", "Swedish"), + ("tl", "Tagalog"), + ("ty", "Tahitian"), + ("tg", "Tajik"), + ("ta", "Tamil"), + ("tt", "Tatar"), + ("te", "Telugu"), + ("th", "Thai"), + ("bo", "Tibetan"), + ("ti", "Tigrinya"), + ("to", "Tonga (Tonga Islands)"), + ("ts", "Tsonga"), + ("tn", "Tswana"), + ("tr", "Turkish"), + ("tk", "Turkmen"), + ("tw", "Twi"), + ("ug", "Uighur, Uyghur"), + ("uk", "Ukrainian"), + ("ur", "Urdu"), + ("uz", "Uzbek"), + ("ve", "Venda"), + ("vi", "Vietnamese"), + ("vo", "Volapük"), + ("wa", "Walloon"), + ("cy", "Welsh"), + ("wo", "Wolof"), + ("xh", "Xhosa"), + ("yi", "Yiddish"), + ("yo", "Yoruba"), + ("za", "Zhuang, Chuang"), + ("zu", "Zulu"), + ], + label="Language", + required=False, + ), + ), + ( + "paragraph", + wagtail.blocks.TextBlock( + label="Title", required=False + ), + ), + ] + ), + ), + ( + "paragraph", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "paragraph", + wagtail.blocks.TextBlock( + label="Paragraph", required=False + ), + ), + ] + ), + ), + ( + "author_paragraph", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "paragraph", + wagtail.blocks.TextBlock( + label="Paragraph", required=False + ), + ), + ( + "surname", + wagtail.blocks.TextBlock( + label="Surname", required=False + ), + ), + ( + "given_names", + wagtail.blocks.TextBlock( + label="Given names", required=False + ), + ), + ( + "orcid", + wagtail.blocks.TextBlock( + label="Orcid", required=False + ), + ), + ( + "affid", + wagtail.blocks.TextBlock( + label="Aff id", required=False + ), + ), + ( + "char", + wagtail.blocks.TextBlock( + label="Char link", required=False + ), + ), + ] + ), + ), + ( + "aff_paragraph", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "paragraph", + wagtail.blocks.TextBlock( + label="Paragraph", required=False + ), + ), + ( + "affid", + wagtail.blocks.TextBlock( + label="Aff id", required=False + ), + ), + ( + "text_aff", + wagtail.blocks.TextBlock( + label="Full text Aff", required=False + ), + ), + ( + "char", + wagtail.blocks.TextBlock( + label="Char link", required=False + ), + ), + ( + "orgname", + wagtail.blocks.TextBlock( + label="Orgname", required=False + ), + ), + ( + "orgdiv2", + wagtail.blocks.TextBlock( + label="Orgdiv2", required=False + ), + ), + ( + "orgdiv1", + wagtail.blocks.TextBlock( + label="Orgdiv1", required=False + ), + ), + ( + "zipcode", + wagtail.blocks.TextBlock( + label="Zipcode", required=False + ), + ), + ( + "city", + wagtail.blocks.TextBlock( + label="City", required=False + ), + ), + ( + "state", + wagtail.blocks.TextBlock( + label="State", required=False + ), + ), + ( + "country", + wagtail.blocks.TextBlock( + label="Country", required=False + ), + ), + ( + "code_country", + wagtail.blocks.TextBlock( + label="Code country", required=False + ), + ), + ( + "original", + wagtail.blocks.TextBlock( + label="Original", required=False + ), + ), + ] + ), + ), + ], + blank=True, + use_json_field=True, + ), + ), + ( + "content_body", + wagtail.fields.StreamField( + [ + ( + "paragraph", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "paragraph", + wagtail.blocks.TextBlock( + label="Paragraph", required=False + ), + ), + ] + ), + ), + ( + "paragraph_with_language", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "language", + wagtail.blocks.ChoiceBlock( + choices=[ + ("aa", "Afar"), + ("af", "Afrikaans"), + ("ak", "Akan"), + ("sq", "Albanian"), + ("am", "Amharic"), + ("ar", "Arabic"), + ("an", "Aragonese"), + ("hy", "Armenian"), + ("as", "Assamese"), + ("av", "Avaric"), + ("ae", "Avestan"), + ("ay", "Aymara"), + ("az", "Azerbaijani"), + ("bm", "Bambara"), + ("ba", "Bashkir"), + ("eu", "Basque"), + ("be", "Belarusian"), + ("bn", "Bengali"), + ("bi", "Bislama"), + ("bs", "Bosnian"), + ("br", "Breton"), + ("bg", "Bulgarian"), + ("my", "Burmese"), + ("ca", "Catalan, Valencian"), + ("ch", "Chamorro"), + ("ce", "Chechen"), + ("ny", "Chichewa, Chewa, Nyanja"), + ("zh", "Chinese"), + ( + "cu", + "Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian, Old Church Slavonic", + ), + ("cv", "Chuvash"), + ("kw", "Cornish"), + ("co", "Corsican"), + ("cr", "Cree"), + ("hr", "Croatian"), + ("cs", "Czech"), + ("da", "Danish"), + ( + "dv", + "Divehi, Dhivehi, Maldivian", + ), + ("nl", "Dutch, Flemish"), + ("dz", "Dzongkha"), + ("en", "English"), + ("eo", "Esperanto"), + ("et", "Estonian"), + ("ee", "Ewe"), + ("fo", "Faroese"), + ("fj", "Fijian"), + ("fi", "Finnish"), + ("fr", "French"), + ("fy", "Western Frisian"), + ("ff", "Fulah"), + ("gd", "Gaelic, Scottish Gaelic"), + ("gl", "Galician"), + ("lg", "Ganda"), + ("ka", "Georgian"), + ("de", "German"), + ("el", "Greek, Modern (1453–)"), + ("kl", "Kalaallisut, Greenlandic"), + ("gn", "Guarani"), + ("gu", "Gujarati"), + ("ht", "Haitian, Haitian Creole"), + ("ha", "Hausa"), + ("he", "Hebrew"), + ("hz", "Herero"), + ("hi", "Hindi"), + ("ho", "Hiri Motu"), + ("hu", "Hungarian"), + ("is", "Icelandic"), + ("io", "Ido"), + ("ig", "Igbo"), + ("id", "Indonesian"), + ( + "ia", + "Interlingua (International Auxiliary Language Association)", + ), + ("ie", "Interlingue, Occidental"), + ("iu", "Inuktitut"), + ("ik", "Inupiaq"), + ("ga", "Irish"), + ("it", "Italian"), + ("ja", "Japanese"), + ("jv", "Javanese"), + ("kn", "Kannada"), + ("kr", "Kanuri"), + ("ks", "Kashmiri"), + ("kk", "Kazakh"), + ("km", "Central Khmer"), + ("ki", "Kikuyu, Gikuyu"), + ("rw", "Kinyarwanda"), + ("ky", "Kirghiz, Kyrgyz"), + ("kv", "Komi"), + ("kg", "Kongo"), + ("ko", "Korean"), + ("kj", "Kuanyama, Kwanyama"), + ("ku", "Kurdish"), + ("lo", "Lao"), + ("la", "Latin"), + ("lv", "Latvian"), + ( + "li", + "Limburgan, Limburger, Limburgish", + ), + ("ln", "Lingala"), + ("lt", "Lithuanian"), + ("lu", "Luba-Katanga"), + ( + "lb", + "Luxembourgish, Letzeburgesch", + ), + ("mk", "Macedonian"), + ("mg", "Malagasy"), + ("ms", "Malay"), + ("ml", "Malayalam"), + ("mt", "Maltese"), + ("gv", "Manx"), + ("mi", "Maori"), + ("mr", "Marathi"), + ("mh", "Marshallese"), + ("mn", "Mongolian"), + ("na", "Nauru"), + ("nv", "Navajo, Navaho"), + ("nd", "North Ndebele"), + ("nr", "South Ndebele"), + ("ng", "Ndonga"), + ("ne", "Nepali"), + ("no", "Norwegian"), + ("nb", "Norwegian Bokmål"), + ("nn", "Norwegian Nynorsk"), + ("ii", "Sichuan Yi, Nuosu"), + ("oc", "Occitan"), + ("oj", "Ojibwa"), + ("or", "Oriya"), + ("om", "Oromo"), + ("os", "Ossetian, Ossetic"), + ("pi", "Pali"), + ("ps", "Pashto, Pushto"), + ("fa", "Persian"), + ("pl", "Polish"), + ("pt", "Português"), + ("pa", "Punjabi, Panjabi"), + ("qu", "Quechua"), + ( + "ro", + "Romanian, Moldavian, Moldovan", + ), + ("rm", "Romansh"), + ("rn", "Rundi"), + ("ru", "Russian"), + ("se", "Northern Sami"), + ("sm", "Samoan"), + ("sg", "Sango"), + ("sa", "Sanskrit"), + ("sc", "Sardinian"), + ("sr", "Serbian"), + ("sn", "Shona"), + ("sd", "Sindhi"), + ("si", "Sinhala, Sinhalese"), + ("sk", "Slovak"), + ("sl", "Slovenian"), + ("so", "Somali"), + ("st", "Southern Sotho"), + ("es", "Español"), + ("su", "Sundanese"), + ("sw", "Swahili"), + ("ss", "Swati"), + ("sv", "Swedish"), + ("tl", "Tagalog"), + ("ty", "Tahitian"), + ("tg", "Tajik"), + ("ta", "Tamil"), + ("tt", "Tatar"), + ("te", "Telugu"), + ("th", "Thai"), + ("bo", "Tibetan"), + ("ti", "Tigrinya"), + ("to", "Tonga (Tonga Islands)"), + ("ts", "Tsonga"), + ("tn", "Tswana"), + ("tr", "Turkish"), + ("tk", "Turkmen"), + ("tw", "Twi"), + ("ug", "Uighur, Uyghur"), + ("uk", "Ukrainian"), + ("ur", "Urdu"), + ("uz", "Uzbek"), + ("ve", "Venda"), + ("vi", "Vietnamese"), + ("vo", "Volapük"), + ("wa", "Walloon"), + ("cy", "Welsh"), + ("wo", "Wolof"), + ("xh", "Xhosa"), + ("yi", "Yiddish"), + ("yo", "Yoruba"), + ("za", "Zhuang, Chuang"), + ("zu", "Zulu"), + ], + label="Language", + required=False, + ), + ), + ( + "paragraph", + wagtail.blocks.TextBlock( + label="Title", required=False + ), + ), + ] + ), + ), + ( + "compound_paragraph", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "eid", + wagtail.blocks.TextBlock( + label="Equation id", required=False + ), + ), + ( + "content", + wagtail.blocks.StreamBlock( + [ + ( + "text", + wagtail.blocks.TextBlock( + label="Text" + ), + ), + ( + "formula", + wagtail.blocks.TextBlock( + label="Formula" + ), + ), + ], + label="Content", + required=True, + ), + ), + ] + ), + ), + ( + "image", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "figid", + wagtail.blocks.TextBlock( + label="Fig id", required=False + ), + ), + ( + "figlabel", + wagtail.blocks.TextBlock( + label="Fig label", required=False + ), + ), + ( + "title", + wagtail.blocks.TextBlock( + label="Title", required=False + ), + ), + ( + "alttext", + wagtail.blocks.TextBlock( + label="Alt text", required=False + ), + ), + ( + "image", + wagtail.images.blocks.ImageChooserBlock( + required=True + ), + ), + ] + ), + ), + ( + "table", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "tabid", + wagtail.blocks.TextBlock( + label="Table id", required=False + ), + ), + ( + "tablabel", + wagtail.blocks.TextBlock( + label="Table label", required=False + ), + ), + ( + "title", + wagtail.blocks.TextBlock( + label="Title", required=False + ), + ), + ( + "content", + wagtail.blocks.TextBlock( + label="Content", required=False + ), + ), + ] + ), + ), + ], + blank=True, + use_json_field=True, + ), + ), + ( + "content_back", + wagtail.fields.StreamField( + [ + ( + "paragraph", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "paragraph", + wagtail.blocks.TextBlock( + label="Paragraph", required=False + ), + ), + ] + ), + ), + ( + "ref_paragraph", + wagtail.blocks.StructBlock( + [ + ( + "label", + wagtail.blocks.ChoiceBlock( + choices=[ + ("<abstract>", "<abstract>"), + ( + "<abstract-title>", + "<abstract-title>", + ), + ("<aff>", "<aff>"), + ("<article-id>", "<article-id>"), + ( + "<article-title>", + "<article-title>", + ), + ( + "<author-notes>", + "<author-notes>", + ), + ("<contrib>", "<contrib>"), + ( + "<date-accepted>", + "<date-accepted>", + ), + ( + "<date-received>", + "<date-received>", + ), + ("<fig>", "<fig>"), + ("<fig-attrib>", "<fig-attrib>"), + ("<history>", "<history>"), + ("<kwd-title>", "<kwd-title>"), + ("<kwd-group>", "<kwd-group>"), + ("<list>", "<list>"), + ("<p>", "<p>"), + ("<sec>", "<sec>"), + ("<sub-sec>", "<sub-sec>"), + ("<subject>", "<subject>"), + ("<table>", "<table>"), + ("<table-foot>", "<table-foot>"), + ("<title>", "<title>"), + ( + "<trans-abstract>", + "<trans-abstract>", + ), + ("<trans-title>", "<trans-title>"), + ( + "<translate-front>", + "<translate-front>", + ), + ( + "<translate-body>", + "<translate-body>", + ), + ( + "<disp-formula>", + "<disp-formula>", + ), + ( + "<inline-formula>", + "<inline-formula>", + ), + ("<formula>", "<formula>"), + ], + label="Label", + required=False, + ), + ), + ( + "paragraph", + wagtail.blocks.TextBlock( + label="Paragraph", required=False + ), + ), + ( + "reftype", + wagtail.blocks.TextBlock( + label="Ref type", required=False + ), + ), + ( + "refid", + wagtail.blocks.TextBlock( + label="Ref id", required=False + ), + ), + ( + "authors", + wagtail.blocks.StreamBlock( + [ + ( + "Author", + wagtail.blocks.StructBlock( + [ + ( + "surname", + wagtail.blocks.TextBlock( + label="Surname", + required=False, + ), + ), + ( + "given_names", + wagtail.blocks.TextBlock( + label="Given names", + required=False, + ), + ), + ] + ), + ) + ], + label="Authors", + required=False, + ), + ), + ( + "date", + wagtail.blocks.TextBlock( + label="Date", required=False + ), + ), + ( + "title", + wagtail.blocks.TextBlock( + label="Title", required=False + ), + ), + ( + "chapter", + wagtail.blocks.TextBlock( + label="Chapter", required=False + ), + ), + ( + "edition", + wagtail.blocks.TextBlock( + label="Edition", required=False + ), + ), + ( + "source", + wagtail.blocks.TextBlock( + label="Source", required=False + ), + ), + ( + "vol", + wagtail.blocks.TextBlock( + label="Vol", required=False + ), + ), + ( + "issue", + wagtail.blocks.TextBlock( + label="Issue", required=False + ), + ), + ( + "pages", + wagtail.blocks.TextBlock( + label="Pages", required=False + ), + ), + ( + "fpage", + wagtail.blocks.TextBlock( + label="First page", required=False + ), + ), + ( + "lpage", + wagtail.blocks.TextBlock( + label="Last page", required=False + ), + ), + ( + "doi", + wagtail.blocks.TextBlock( + label="DOI", required=False + ), + ), + ( + "access_id", + wagtail.blocks.TextBlock( + label="Access id", required=False + ), + ), + ( + "degree", + wagtail.blocks.TextBlock( + label="Degree", required=False + ), + ), + ( + "organization", + wagtail.blocks.TextBlock( + label="Organization", required=False + ), + ), + ( + "location", + wagtail.blocks.TextBlock( + label="Location", required=False + ), + ), + ( + "org_location", + wagtail.blocks.TextBlock( + label="Org location", required=False + ), + ), + ( + "num_pages", + wagtail.blocks.TextBlock( + label="Num pages", required=False + ), + ), + ( + "uri", + wagtail.blocks.TextBlock( + label="Uri", required=False + ), + ), + ( + "version", + wagtail.blocks.TextBlock( + label="Version", required=False + ), + ), + ( + "access_date", + wagtail.blocks.TextBlock( + label="Access date", required=False + ), + ), + ] + ), + ), + ], + blank=True, + use_json_field=True, + ), + ), + ( + "creator", + models.ForeignKey( + editable=False, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="%(class)s_creator", + to=settings.AUTH_USER_MODEL, + verbose_name="Creator", + ), + ), + ( + "updated_by", + models.ForeignKey( + blank=True, + editable=False, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="%(class)s_last_mod_user", + to=settings.AUTH_USER_MODEL, + verbose_name="Updater", + ), + ), + ], + options={ + "abstract": False, + }, + ), + migrations.CreateModel( + name="MarkupXML", + fields=[], + options={ + "proxy": True, + "indexes": [], + "constraints": [], + }, + bases=("markup_doc.articledocxmarkup",), + ), + migrations.CreateModel( + name="UploadDocx", + fields=[], + options={ + "proxy": True, + "indexes": [], + "constraints": [], + }, + bases=("markup_doc.articledocxmarkup",), + ), + migrations.CreateModel( + name="CollectionModel", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "collection", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="markup_doc.collectionvaluesmodel", + ), + ), + ], + ), + migrations.CreateModel( + name="JournalModel", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "title", + models.TextField(blank=True, null=True, verbose_name="Title"), + ), + ( + "short_title", + models.TextField(blank=True, null=True, verbose_name="Short Title"), + ), + ( + "title_nlm", + models.TextField(blank=True, null=True, verbose_name="NLM Title"), + ), + ( + "acronym", + models.TextField(blank=True, null=True, verbose_name="Acronym"), + ), + ( + "issn", + models.TextField( + blank=True, null=True, verbose_name="ISSN (id SciELO)" + ), + ), + ( + "pissn", + models.TextField(blank=True, null=True, verbose_name="Print ISSN"), + ), + ( + "eissn", + models.TextField( + blank=True, null=True, verbose_name="Electronic ISSN" + ), + ), + ( + "pubname", + models.TextField( + blank=True, null=True, verbose_name="Publisher Name" + ), + ), + ], + options={ + "unique_together": {("title",)}, + }, + ), + migrations.AddField( + model_name="articledocxmarkup", + name="journal", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="markup_doc.journalmodel", + ), + ), + ] diff --git a/markup_doc/migrations/0002_alter_articledocx_estatus_and_more.py b/markup_doc/migrations/0002_alter_articledocx_estatus_and_more.py new file mode 100644 index 0000000..7ab4524 --- /dev/null +++ b/markup_doc/migrations/0002_alter_articledocx_estatus_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 5.0.8 on 2025-09-21 23:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("markup_doc", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="articledocx", + name="estatus", + field=models.IntegerField( + blank=True, + choices=[(1, "Processing"), (2, "Processed")], + default=1, + verbose_name="Process estatus", + ), + ), + migrations.AlterField( + model_name="articledocxmarkup", + name="estatus", + field=models.IntegerField( + blank=True, + choices=[(1, "Processing"), (2, "Processed")], + default=1, + verbose_name="Process estatus", + ), + ), + ] diff --git a/markup_doc/migrations/__init__.py b/markup_doc/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/markup_doc/models.py b/markup_doc/models.py new file mode 100644 index 0000000..a7e4ab5 --- /dev/null +++ b/markup_doc/models.py @@ -0,0 +1,491 @@ +from django import forms +from django.db import models +from django.urls import reverse +from django.utils.html import format_html +from django.utils.translation import gettext_lazy as _ +from modelcluster.models import ClusterableModel +from wagtail.admin.panels import FieldPanel, ObjectList, TabbedInterface +from wagtail.blocks import ChoiceBlock, StreamBlock, StructBlock, TextBlock +from wagtail.fields import StreamField +from wagtail.images.blocks import ImageChooserBlock +from wagtailautocomplete.edit_handlers import AutocompletePanel + +from core.choices import LANGUAGE +from core.forms import CoreAdminModelForm +from core.models import CommonControlField + +from .choices import front_labels + + +class ProcessStatus(models.IntegerChoices): + PROCESSING = 1, _("Processing") + PROCESSED = 2, _("Processed") + + +class ReadOnlyFileWidget(forms.Widget): + def render(self, name, value, attrs=None, renderer=None): + if value: + # Muestra el archivo como un enlace de descarga + # return format_html('<a href="{}" target="_blank" download>{}</a>', value.url, value.name.split('/')[-1]) + instance = value.instance + url = reverse("generate_xml", args=[instance.pk]) + return format_html( + '<a href="{}" target="_blank" download>Download XML</a>', url + ) + return "" + + +class ArticleDocx(CommonControlField): + title = models.TextField(_("Document Title"), null=True, blank=True) + file = models.FileField( + null=True, + blank=True, + verbose_name=_("Document"), + upload_to="uploads_docx/", + ) + estatus = models.IntegerField( + _("Process estatus"), + choices=ProcessStatus.choices, + blank=True, + default=ProcessStatus.PROCESSING, + ) + + panels = [ + FieldPanel("title"), + FieldPanel("file"), + ] + + base_form_class = CoreAdminModelForm + + def __unicode__(self): + return f"{self.title} | {self.estatus}" + + def __str__(self): + title = self.title or "" + return f"{title} | {self.estatus}" + + @classmethod + def get(cls, title): + return cls.objects.get(title=title) + + @classmethod + def update(cls, title, estatus): + try: + obj = cls.get(title=title) + except (cls.DoesNotExist, ValueError): + pass + + obj.estatus = estatus + obj.save() + return obj + + +class ParagraphWithLanguageBlock(StructBlock): + label = ChoiceBlock(choices=front_labels, required=False, label=_("Label")) + language = ChoiceBlock(choices=LANGUAGE, required=False, label="Language") + paragraph = TextBlock(required=False, label=_("Title")) + + class Meta: + label = _("Paragraph with Language") + + +class ParagraphBlock(StructBlock): + label = ChoiceBlock(choices=front_labels, required=False, label=_("Label")) + paragraph = TextBlock(required=False, label=_("Paragraph")) + + class Meta: + label = _("Paragraph") + + +class CompoundParagraphBlock(StructBlock): + label = ChoiceBlock(choices=front_labels, required=False, label=_("Label")) + eid = TextBlock(required=False, label=_("Equation id")) + content = StreamBlock( + [ + ("text", TextBlock(label=_("Text"))), + ("formula", TextBlock(label=_("Formula"))), + ], + label=_("Content"), + required=True, + ) + + class Meta: + label = _("Compound paragraph") + + +class ImageBlock(StructBlock): + label = ChoiceBlock(choices=front_labels, required=False, label=_("Label")) + figid = TextBlock(required=False, label=_("Fig id")) + figlabel = TextBlock(required=False, label=_("Fig label")) + title = TextBlock(required=False, label=_("Title")) + alttext = TextBlock(required=False, label=_("Alt text")) + image = ImageChooserBlock(required=True) + + class Meta: + label = _("Image") + + +class TableBlock(StructBlock): + label = ChoiceBlock(choices=front_labels, required=False, label=_("Label")) + tabid = TextBlock(required=False, label=_("Table id")) + tablabel = TextBlock(required=False, label=_("Table label")) + title = TextBlock(required=False, label=_("Title")) + content = TextBlock(required=False, label=_("Content")) + + class Meta: + label = _("Table") + + +class AuthorParagraphBlock(ParagraphBlock): + surname = TextBlock(required=False, label=_("Surname")) + given_names = TextBlock(required=False, label=_("Given names")) + orcid = TextBlock(required=False, label=_("Orcid")) + affid = TextBlock(required=False, label=_("Aff id")) + char = TextBlock(required=False, label=_("Char link")) + + class Meta: + label = _("Author Paragraph") + + +class AffParagraphBlock(ParagraphBlock): + affid = TextBlock(required=False, label=_("Aff id")) + text_aff = TextBlock(required=False, label=_("Full text Aff")) + char = TextBlock(required=False, label=_("Char link")) + orgname = TextBlock(required=False, label=_("Orgname")) + orgdiv2 = TextBlock(required=False, label=_("Orgdiv2")) + orgdiv1 = TextBlock(required=False, label=_("Orgdiv1")) + zipcode = TextBlock(required=False, label=_("Zipcode")) + city = TextBlock(required=False, label=_("City")) + state = TextBlock(required=False, label=_("State")) + country = TextBlock(required=False, label=_("Country")) + code_country = TextBlock(required=False, label=_("Code country")) + original = TextBlock(required=False, label=_("Original")) + + class Meta: + label = _("Aff Paragraph") + + +class RefNameBlock(StructBlock): + surname = TextBlock(required=False, label=_("Surname")) + given_names = TextBlock(required=False, label=_("Given names")) + + +class RefParagraphBlock(ParagraphBlock): + reftype = TextBlock(required=False, label=_("Ref type")) + refid = TextBlock(required=False, label=_("Ref id")) + # authors = ListBlock(RefNameBlock(), label=_("Authors")) + authors = StreamBlock( + [ + ("Author", RefNameBlock()), + ], + label=_("Authors"), + required=False, + ) + date = TextBlock(required=False, label=_("Date")) + title = TextBlock(required=False, label=_("Title")) + chapter = TextBlock(required=False, label=_("Chapter")) + edition = TextBlock(required=False, label=_("Edition")) + source = TextBlock(required=False, label=_("Source")) + vol = TextBlock(required=False, label=_("Vol")) + issue = TextBlock(required=False, label=_("Issue")) + pages = TextBlock(required=False, label=_("Pages")) + fpage = TextBlock(required=False, label=_("First page")) + lpage = TextBlock(required=False, label=_("Last page")) + doi = TextBlock(required=False, label=_("DOI")) + access_id = TextBlock(required=False, label=_("Access id")) + degree = TextBlock(required=False, label=_("Degree")) + organization = TextBlock(required=False, label=_("Organization")) + location = TextBlock(required=False, label=_("Location")) + org_location = TextBlock(required=False, label=_("Org location")) + num_pages = TextBlock(required=False, label=_("Num pages")) + uri = TextBlock(required=False, label=_("Uri")) + version = TextBlock(required=False, label=_("Version")) + access_date = TextBlock(required=False, label=_("Access date")) + + class Meta: + label = _("Ref Paragraph") + + +class CollectionValuesModel(models.Model): + acron = models.CharField(max_length=10, unique=True) + name = models.CharField(max_length=255) + + autocomplete_search_field = "acron" + + def autocomplete_label(self): + return str(self) + + def __str__(self): + return f"{self.acron.upper()} - {self.name}" + + +class CollectionModel(models.Model): + collection = models.ForeignKey( + CollectionValuesModel, null=True, blank=True, on_delete=models.SET_NULL + ) + + autocomplete_search_field = "collection.acron" + + def autocomplete_label(self): + return str(self) + + panels = [ + AutocompletePanel("collection"), + ] + + def __str__(self): + if not self.collection: + return "" + acron = self.collection.acron or "" + return f"{acron.upper()} - {acron}" + + +class JournalModel(models.Model): + title = models.TextField(_("Title"), null=True, blank=True) + short_title = models.TextField(_("Short Title"), null=True, blank=True) + title_nlm = models.TextField(_("NLM Title"), null=True, blank=True) + acronym = models.TextField(_("Acronym"), null=True, blank=True) + issn = models.TextField(_("ISSN (id SciELO)"), null=True, blank=True) + pissn = models.TextField(_("Print ISSN"), null=True, blank=True) + eissn = models.TextField(_("Electronic ISSN"), null=True, blank=True) + pubname = models.TextField(_("Publisher Name"), null=True, blank=True) + + autocomplete_search_field = "title" + + class Meta: + unique_together = ("title",) + + def autocomplete_label(self): + return str(self) + + def __str__(self): + return self.title or "" + + +def get_default_collection_acron(): + try: + obj = CollectionModel.objects.select_related("collection").first() + return obj.collection.acron if obj and obj.collection else "" + except Exception: + return "" + + +class ArticleDocxMarkup(CommonControlField, ClusterableModel): + title = models.TextField(_("Document Title"), null=True, blank=True) + file = models.FileField( + null=True, + blank=True, + verbose_name=_("Document"), + upload_to="uploads_docx/", + ) + estatus = models.IntegerField( + _("Process estatus"), + choices=ProcessStatus.choices, + blank=True, + default=ProcessStatus.PROCESSING, + ) + + collection = models.CharField(max_length=10, default=get_default_collection_acron) + journal = models.ForeignKey( + JournalModel, null=True, blank=True, on_delete=models.SET_NULL + ) + + journal_title = models.TextField(_("Journal Title"), null=True, blank=True) + acronym = models.TextField(_("Acronym"), null=True, blank=True) + short_title = models.TextField(_("Short Title"), null=True, blank=True) + title_nlm = models.TextField(_("NLM Title"), null=True, blank=True) + issn = models.TextField(_("ISSN (id SciELO)"), null=True, blank=True) + pissn = models.TextField(_("Print ISSN"), null=True, blank=True) + eissn = models.TextField(_("Electronic ISSN"), null=True, blank=True) + nimtitle = models.TextField(_("Nimtitle"), null=True, blank=True) + pubname = models.TextField(_("Publisher Name"), null=True, blank=True) + license = models.URLField( + max_length=500, blank=True, null=True, verbose_name=_("License (URL)") + ) + vol = models.IntegerField(verbose_name=_("Volume"), null=True, blank=True) + supplvol = models.IntegerField( + verbose_name=_("Suppl Volume"), null=True, blank=True + ) + issue = models.IntegerField(verbose_name=_("Issue"), null=True, blank=True) + supplno = models.IntegerField(verbose_name=_("Suppl Num"), null=True, blank=True) + issid_part = models.TextField(_("Isid Part"), null=True, blank=True) + dateiso = models.TextField(_("Dateiso"), null=True, blank=True) + month = models.TextField(_("Month/Season"), null=True, blank=True) + fpage = models.TextField(_("First Page"), null=True, blank=True) + seq = models.TextField(_("@Seq"), null=True, blank=True) + lpage = models.TextField(_("Last Page"), null=True, blank=True) + elocatid = models.TextField(_("Elocation ID"), null=True, blank=True) + order = models.TextField(_("Order (In TOC)"), null=True, blank=True) + pagcount = models.TextField(_("Pag count"), null=True, blank=True) + doctopic = models.TextField(_("Doc Topic"), null=True, blank=True) + language = models.CharField( + _("Language"), max_length=10, choices=LANGUAGE, null=True, blank=True + ) + spsversion = models.TextField(_("Sps version"), null=True, blank=True) + artdate = models.DateField(_("Artdate"), null=True, blank=True) + ahpdate = models.DateField(_("Ahpdate"), null=True, blank=True) + + file_xml = models.FileField( + null=True, + blank=True, + verbose_name=_("Document xml"), + upload_to="generate_xml/", + ) + + text_xml = models.TextField(_("Text XML"), null=True, blank=True) + + content = StreamField( + [ + ("paragraph_with_language", ParagraphWithLanguageBlock()), + ("paragraph", ParagraphBlock()), + ("author_paragraph", AuthorParagraphBlock()), + ("aff_paragraph", AffParagraphBlock()), + ], + blank=True, + use_json_field=True, + ) + + content_body = StreamField( + [ + ("paragraph", ParagraphBlock()), + ("paragraph_with_language", ParagraphWithLanguageBlock()), + ("compound_paragraph", CompoundParagraphBlock()), + ("image", ImageBlock()), + ("table", TableBlock()), + ], + blank=True, + use_json_field=True, + ) + + content_back = StreamField( + [ + ("paragraph", ParagraphBlock()), + ("ref_paragraph", RefParagraphBlock()), + ], + blank=True, + use_json_field=True, + ) + + panels = [ + FieldPanel("title"), + FieldPanel("file"), + FieldPanel("collection"), + AutocompletePanel("journal"), + ] + + def __unicode__(self): + return f"{self.title} | {self.estatus}" + + def __str__(self): + title = self.title or "" + return f"{title} | {self.estatus}" + + @property + def url_download(self): + return self.file_xml.url if self.file_xml else None + + @classmethod + def create(cls, title): + obj = cls() + obj.title = title + obj.save() + return obj + + @classmethod + def get(cls, title): + return cls.objects.get(title=title) + + @classmethod + def update(cls, title, estatus): + try: + obj = cls.get(title=title) + except (cls.DoesNotExist, ValueError): + pass + + obj.estatus = estatus + obj.save() + return obj + + base_form_class = CoreAdminModelForm + + +class UploadDocx(ArticleDocxMarkup): + panels_doc = [ + FieldPanel("title"), + FieldPanel("file"), + ] + + edit_handler = TabbedInterface( + [ + ObjectList(panels_doc, heading=_("Document")), + ] + ) + + class Meta: + proxy = True + + +class MarkupXML(ArticleDocxMarkup): + panels_front = [ + FieldPanel("content"), + # InlinePanel("element_docx", label=_("Elements Docx")), + ] + + panels_body = [ + FieldPanel("content_body"), + ] + + panels_back = [ + FieldPanel("content_back"), + ] + + panels_xml = [ + FieldPanel("file_xml", widget=ReadOnlyFileWidget()), + FieldPanel("text_xml"), + ] + + panels_details = [ + FieldPanel("collection"), + AutocompletePanel("journal"), + FieldPanel("journal_title"), + FieldPanel("short_title"), + FieldPanel("title_nlm"), + FieldPanel("acronym"), + FieldPanel("issn"), + FieldPanel("pissn"), + FieldPanel("eissn"), + FieldPanel("nimtitle"), + FieldPanel("pubname"), + FieldPanel("license"), + FieldPanel("vol"), + FieldPanel("supplvol"), + FieldPanel("issue"), + FieldPanel("supplno"), + FieldPanel("issid_part"), + FieldPanel("dateiso"), + FieldPanel("month"), + FieldPanel("fpage"), + FieldPanel("seq"), + FieldPanel("lpage"), + FieldPanel("elocatid"), + FieldPanel("order"), + FieldPanel("pagcount"), + FieldPanel("doctopic"), + FieldPanel("language"), + FieldPanel("spsversion"), + FieldPanel("artdate"), + FieldPanel("ahpdate"), + ] + + edit_handler = TabbedInterface( + [ + ObjectList(panels_xml, heading="XML"), + ObjectList(panels_details, heading=_("Details")), + ObjectList(panels_front, heading="Front"), + ObjectList(panels_body, heading="Body"), + ObjectList(panels_back, heading="Back"), + ] + ) + + class Meta: + proxy = True diff --git a/markup_doc/sync_api.py b/markup_doc/sync_api.py new file mode 100644 index 0000000..fd34af3 --- /dev/null +++ b/markup_doc/sync_api.py @@ -0,0 +1,105 @@ +import logging + +from django.conf import settings +from django.db import transaction + +from core.utils.requester import fetch_data as fetch +from markup_doc.models import CollectionModel, CollectionValuesModel, JournalModel + +logger = logging.getLogger(__name__) + + +def sync_collection_from_api(): + url = settings.CORE_COLLECTION_API_URL + all_results = [] + + while url: + logger.info("Syncing collections page: %s", url) + data = fetch( + url, headers={"Accept": "application/json"}, json=True, timeout=(10, 60) + ) + all_results.extend(data["results"]) + url = data["next"] + + logger.info("Deleting existing collection data before sync") + CollectionModel.objects.all().delete() + CollectionValuesModel.objects.all().delete() + + for item in all_results: + acron = item.get("acron3") + name = item.get("main_name", "").strip() + if acron and name: + CollectionValuesModel.objects.update_or_create( + acron=acron, defaults={"name": name} + ) + + +def sync_journals_from_api(): + journals = JournalModel.objects.all() + if journals.exists(): + journals.delete() + + obj = CollectionModel.objects.select_related("collection").first() + + acron_selected = obj.collection.acron if obj and obj.collection else None + if not acron_selected: + logger.warning("No collection selected; skipping journal sync") + return + + new_journals = [] + + url = settings.CORE_JOURNAL_API_URL + while url: + logger.info("Syncing journals page: %s", url) + data = fetch( + url, headers={"Accept": "application/json"}, json=True, timeout=(10, 60) + ) + + for item in data["results"]: + title = item.get("title", None) + short_title = item.get("short_title", None) + acronym = item.get("acronym", None) + pissn = item.get("official", {}).get("issn_print", None) + eissn = item.get("official", {}).get("issn_electronic", None) + acronym = item.get("acronym", None) + pubname = item.get("publisher", []) + title_in_database = item.get("title_in_database", []) + title_nlm = None + + if title_in_database: + for t in title_in_database: + if t.get("name", None) == "MEDLINE": + title_nlm = t.get("title", None) + + if pubname: + pubname = pubname[0].get("name", None) + + scielo_journals = item.get("scielo_journal", []) + + # Obtener la primera colección asociada, si existe + collection_acron = None + issn_scielo = None + if scielo_journals: + collection_acron = scielo_journals[0].get("collection_acron") + issn_scielo = scielo_journals[0].get("issn_scielo", None) + + if not title or acron_selected != collection_acron: + continue # Saltar si falta el título + + journal = JournalModel( + title=title, + short_title=short_title or None, + title_nlm=title_nlm or None, + acronym=acronym or None, + issn=issn_scielo or None, + pissn=pissn or None, + eissn=eissn or None, + pubname=pubname or None, + ) + new_journals.append(journal) + + url = data.get("next") + + if new_journals: + with transaction.atomic(): + JournalModel.objects.bulk_create(new_journals, ignore_conflicts=True) diff --git a/markup_doc/tasks.py b/markup_doc/tasks.py new file mode 100644 index 0000000..9121a25 --- /dev/null +++ b/markup_doc/tasks.py @@ -0,0 +1,9 @@ +# Local application imports +from config import celery_app + +from markup_doc.sync_api import sync_journals_from_api + + +@celery_app.task() +def task_sync_journals_from_api(): + sync_journals_from_api() diff --git a/markup_doc/tests.py b/markup_doc/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/markup_doc/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/markup_doc/wagtail_hooks.py b/markup_doc/wagtail_hooks.py new file mode 100644 index 0000000..2e4677c --- /dev/null +++ b/markup_doc/wagtail_hooks.py @@ -0,0 +1,191 @@ +from django.http import HttpResponseRedirect +from django.template.response import TemplateResponse +from django.utils.translation import gettext_lazy as _ +from wagtail.admin import messages +from wagtail.snippets.models import register_snippet +from wagtail.snippets.views.snippets import ( + CreateView, + EditView, + SnippetViewSet, + SnippetViewSetGroup, +) +from wagtail_modeladmin.options import ModelAdmin + +from markup_doc.models import ( + ArticleDocx, + ArticleDocxMarkup, + CollectionModel, + JournalModel, + MarkupXML, + ProcessStatus, + UploadDocx, +) +from markup_doc.sync_api import sync_collection_from_api +from markup_doc.tasks import task_sync_journals_from_api + + +class ArticleDocxCreateView(CreateView): + # def get_form_class(self): + def dispatch(self, request, *args, **kwargs): + if not CollectionModel.objects.exists(): + messages.warning(request, "Debes seleccionar primero una colección.") + return HttpResponseRedirect(self.get_success_url()) + if not JournalModel.objects.exists(): + messages.warning( + request, "Espera un momento, aún no existen elementos en Journal." + ) + return HttpResponseRedirect(self.get_success_url()) + return super().dispatch(request, *args, **kwargs) + + def form_valid(self, form): + self.object = form.save_all(self.request.user) + self.object.estatus = ProcessStatus.PROCESSING + self.object.save() + return HttpResponseRedirect(self.get_success_url()) + + +class ArticleDocxEditView(EditView): + def form_valid(self, form): + form.instance.updated_by = self.request.user + form.instance.save() + return HttpResponseRedirect(self.get_success_url()) + + +class ArticleDocxAdmin(ModelAdmin): + model = ArticleDocx + create_view_class = ArticleDocxCreateView + menu_label = _("Documents") + menu_icon = "folder" + menu_order = 1 + add_to_settings_menu = False # or True to add your model to the Settings sub-menu + exclude_from_explorer = ( + False # or True to exclude pages of this type from Wagtail's explorer view + ) + list_per_page = 20 + list_display = ("title", "get_estatus_display") + + +class ArticleDocxMarkupCreateView(CreateView): + def form_valid(self, form): + self.object = form.save_all(self.request.user) + return HttpResponseRedirect(self.get_success_url()) + + +class ArticleDocxMarkupAdmin(ModelAdmin): + model = ArticleDocxMarkup + create_view_class = ArticleDocxMarkupCreateView + menu_label = _("Documents Markup") + menu_icon = "folder" + menu_order = 1 + add_to_settings_menu = False # or True to add your model to the Settings sub-menu + exclude_from_explorer = ( + False # or True to exclude pages of this type from Wagtail's explorer view + ) + list_per_page = 20 + + +class UploadDocxViewSet(SnippetViewSet): + model = UploadDocx + add_view_class = ArticleDocxCreateView + menu_label = _("Carregar DOCX") + menu_icon = "folder" + menu_order = 1 + add_to_settings_menu = False + exclude_from_explorer = False + list_per_page = 20 + list_display = ("title", "get_estatus_display") # Usar estatus, não status + search_fields = ("title",) + list_filter = ("estatus",) # Usar estatus, não status + + +class MarkupXMLViewSet(SnippetViewSet): + model = MarkupXML + add_view_class = ArticleDocxMarkupCreateView + edit_view_class = ArticleDocxEditView + menu_label = _("XML marcado") # Alterado de "MarkupXML" + menu_icon = "folder" + menu_order = 1 + add_to_settings_menu = False + exclude_from_explorer = False + list_display = ("title",) + list_per_page = 20 + search_fields = ("title",) + + +class CollectionModelCreateView(CreateView): + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + sync_collection_from_api() + return context + + def form_valid(self, form): + form.instance.save() + task_sync_journals_from_api.delay() + return HttpResponseRedirect(self.get_success_url()) + + +class CollectionModelViewSet(SnippetViewSet): + model = CollectionModel + add_view_class = CollectionModelCreateView + menu_label = _("Modelo de Coleções") # Alterado de "CollectionModel" + menu_icon = "folder" + menu_order = 1 + add_to_settings_menu = False + exclude_from_explorer = False + list_per_page = 20 + list_display = ("collection",) + + +class JournalModelCreateView(CreateView): + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + task_sync_journals_from_api + return context + + +class JournalModelViewSet(SnippetViewSet): + model = JournalModel + menu_label = _("Modelo de Revistas") # Alterado de "JournalModel" + menu_icon = "folder" + menu_order = 1 + add_to_settings_menu = False + exclude_from_explorer = False + list_per_page = 20 + list_display = ("title",) + + def index_view(self, request): + response = super().index_view(request) + + if isinstance(response, TemplateResponse): + if not CollectionModel.objects.exists(): + messages.warning(request, "Debes seleccionar primero una colección.") + response.context_data["can_add"] = False + response.context_data["can_add_snippet"] = False + return response + + if not JournalModel.objects.exists(): + messages.warning( + request, + "Sincronizando journals desde la API, espera unos momentos…", + ) + response.context_data["can_add"] = False + response.context_data["can_add_snippet"] = False + return response + + return response + + +class MarkupSnippetViewSetGroup(SnippetViewSetGroup): + menu_name = "docx_files" # Renomeado de 'docx_processor' + menu_label = _("DOCX Files") + menu_icon = "folder-open-inverse" + menu_order = 0 # Mudado de 1 para 0 para ficar na primeira posição + items = ( + UploadDocxViewSet, + MarkupXMLViewSet, + CollectionModelViewSet, + JournalModelViewSet, + ) + + +register_snippet(MarkupSnippetViewSetGroup)