Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,6 @@

# 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/",
Expand All @@ -331,7 +327,6 @@
"CORE_ISSUE_FROM_DATE_CREATED",
default="2019-01-01",
)
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
Expand Down
1 change: 0 additions & 1 deletion markup_doc/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class Migration(migrations.Migration):
(
"collection",
models.CharField(
default=markup_doc.models.get_default_collection_acron,
max_length=10,
),
),
Expand Down
22 changes: 22 additions & 0 deletions markup_doc/migrations/0005_remove_collection_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("markup_doc", "0004_articledocxmarkup_xref_status"),
("markup_doc", "0003_remove_articledocxmarkup_dateiso_and_more"),
]

operations = [
migrations.RemoveField(
model_name="articledocxmarkup",
name="collection",
),
migrations.DeleteModel(
name="CollectionModel",
),
migrations.DeleteModel(
name="CollectionValuesModel",
),
]
45 changes: 0 additions & 45 deletions markup_doc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,40 +276,6 @@ 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)
Expand Down Expand Up @@ -400,14 +366,6 @@ def generate_issue_folder(self):
)


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(
Expand All @@ -434,7 +392,6 @@ class ArticleDocxMarkup(CommonControlField, ClusterableModel):
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
)
Expand Down Expand Up @@ -516,7 +473,6 @@ class ArticleDocxMarkup(CommonControlField, ClusterableModel):
panels = [
FieldPanel("title"),
FieldPanel("file"),
FieldPanel("collection"),
AutocompletePanel("journal"),
AutocompletePanel("issue"),
]
Expand Down Expand Up @@ -606,7 +562,6 @@ class MarkupXML(ArticleDocxMarkup):
]

panels_details = [
FieldPanel("collection"),
AutocompletePanel("journal"),
FieldPanel("journal_title"),
FieldPanel("short_title"),
Expand Down
2 changes: 1 addition & 1 deletion markup_doc/static/js/xref-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ document.addEventListener("DOMContentLoaded", function () {
if ( path.indexOf('markupxml/edit') == -1 ){
return false;
}
var ids = ['collection', 'journal_title', 'short_title', 'title_nlm', 'acronym', 'issn', 'pissn', 'eissn', 'pubname']
var ids = ['journal_title', 'short_title', 'title_nlm', 'acronym', 'issn', 'pissn', 'eissn', 'pubname']
$.each(ids, function(i, val){
const collectionField = document.querySelector('#id_'+val);
if (collectionField) {
Expand Down
30 changes: 1 addition & 29 deletions markup_doc/sync_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from core.models import CoreSyncState
from core.utils.requester import fetch_data as fetch
from core.utils.sync_state import finalize_core_sync_state, track_max_from_item
from markup_doc.models import CollectionModel, CollectionValuesModel, Issue, JournalModel
from markup_doc.models import Issue, JournalModel

logger = logging.getLogger(__name__)

Expand All @@ -25,31 +25,6 @@ def _iter_api_pages(url, resource_name):
url = data.get("next")


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 _build_journal_from_api_item(item):
title = item.get("title", None)
short_title = item.get("short_title", None)
Expand Down Expand Up @@ -94,7 +69,6 @@ def build_api_url_core(domain, endpoint, params):


def sync_journals_from_api(
collection_acron=None,
issn_scielo=None,
from_date_updated=None,
):
Expand All @@ -105,8 +79,6 @@ def sync_journals_from_api(
)

params = {"from_date_updated": from_date_updated}
if collection_acron:
params["collection"] = collection_acron
if issn_scielo:
params["issn_scielo"] = issn_scielo

Expand Down
2 changes: 0 additions & 2 deletions markup_doc/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ def clean_labels(text):
@celery_app.task()
def task_sync_journals_from_api(
user_id=None,
collection_acron=None,
issn_scielo=None,
from_date_updated=None,
):
sync_journals_from_api(
collection_acron=collection_acron,
issn_scielo=issn_scielo,
from_date_updated=from_date_updated,
)
Expand Down
43 changes: 1 addition & 42 deletions markup_doc/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@

from markup_doc import views
from markup_doc.models import (
CollectionModel,
Issue,
JournalModel,
MarkupXML,
ProcessedDocx,
ProcessStatus,
UploadDocx,
)
from markup_doc.sync_api import sync_collection_from_api
from markup_doc.tasks import get_labels, task_sync_journals_from_api, update_xml

from xml_manager.wagtail_hooks import (
Expand Down Expand Up @@ -71,9 +69,6 @@ def xref_js():

class ArticleDocxCreateView(CreateView):
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."
Expand Down Expand Up @@ -136,36 +131,6 @@ class MarkupXMLViewSet(SnippetViewSet):
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 = _("Coleção")
menu_icon = "folder-inverse"
add_to_admin_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 = _("Periódicos")
Expand All @@ -179,17 +144,12 @@ 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…",
)
task_sync_journals_from_api.delay()
response.context_data["can_add"] = False
response.context_data["can_add_snippet"] = False
return response
Expand Down Expand Up @@ -239,7 +199,6 @@ class ScieloSnippetViewSetGroup(SnippetViewSetGroup):
menu_icon = "folder-open-inverse"
menu_order = get_menu_order("scielo")
items = (
CollectionModelViewSet,
JournalModelViewSet,
)

Expand Down
Loading