Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementar verificação de disponibilidade de artigos em scielo.br #462

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b8901ab
Coloca _get_user em um lugar comum aos aplicativos
samuelveigarangel May 17, 2024
490530f
realiza mudanca do _get_user
samuelveigarangel May 17, 2024
793a84e
realiza mudanca do _get_user
samuelveigarangel May 17, 2024
48118d4
realiza mudanca do _get_user
samuelveigarangel May 17, 2024
783ae05
realiza mudanca do _get_user
samuelveigarangel May 17, 2024
0e7779d
realiza mudanca do _get_user e remove _get_user em task_publish_model…
samuelveigarangel May 17, 2024
5582b74
realiza mudanca do _get_user
samuelveigarangel May 17, 2024
91a5b6c
Cria os modelos e seus metodos de classe (CheckArticleAvailability, S…
samuelveigarangel May 21, 2024
4a6b2e8
Insere o paramentro date nos metodos das classes CheckArticleAvailabi…
samuelveigarangel May 21, 2024
4db2b20
Cria tasks que realizam a verificacao da disponibilidade do artigo no…
samuelveigarangel May 21, 2024
627c144
Cria ScieloSiteStatusAdmin
samuelveigarangel May 21, 2024
465f4a6
script para executar initiate_article_availability_check
samuelveigarangel May 21, 2024
c47344c
migracao
samuelveigarangel May 21, 2024
f3f615f
Corrige for em initiate_article_availability_check
samuelveigarangel May 21, 2024
9bb5aea
Cria Choices VERIFY_ARTICLE_TYPE E VERIFY_HTTP_ERROR_CODE
samuelveigarangel May 23, 2024
4bc73af
- Adiciona campo type e available em ScieloSiteStatus
samuelveigarangel May 23, 2024
5f978ff
- Adiciona bloco try-except em initiate_article_availability_check e …
samuelveigarangel May 23, 2024
a99427b
Adiciona novos displays e filter em ScieloSiteStatus
samuelveigarangel May 23, 2024
2706e9d
migracao
samuelveigarangel May 23, 2024
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
11 changes: 11 additions & 0 deletions article/choices.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.utils.translation import gettext as _
from core.utils.requester import NonRetryableError, RetryableError

# Model RequestArticleChange, Field change_type
RCT_UPDATE = "update"
Expand Down Expand Up @@ -124,3 +125,13 @@
(AS_SCHEDULED_TO_PUBLISH, _("Scheduled to publish")),
(AS_PUBLISHED, _("Published")),
)

VERIFY_ARTICLE_TYPE = [
("TEXT", _("Text")),
("PDF", _("pdf")),
]

VERIFY_HTTP_ERROR_CODE = [
(RetryableError, _("Excessively long response time. Retry later")),
(NonRetryableError, _("Site not found.")),
]
141 changes: 141 additions & 0 deletions article/migrations/0002_scielositestatus_checkarticleavailability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Generated by Django 5.0.3 on 2024-05-23 15:09

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("article", "0001_initial"),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name="ScieloSiteStatus",
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"
),
),
("check_date", models.DateTimeField(blank=True, null=True)),
("url_site_scielo", models.SlugField(max_length=500, unique=True)),
("status", models.CharField(blank=True, max_length=80, null=True)),
(
"type",
models.CharField(
blank=True,
choices=[("TEXT", "Texto"), ("PDF", "pdf")],
max_length=10,
null=True,
),
),
("available", models.BooleanField(default=False)),
(
"creator",
models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
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.CASCADE,
related_name="%(class)s_last_mod_user",
to=settings.AUTH_USER_MODEL,
verbose_name="Updater",
),
),
],
options={
"verbose_name": "Scielo Site Status",
"verbose_name_plural": "Scielo Site Status",
},
),
migrations.CreateModel(
name="CheckArticleAvailability",
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"
),
),
(
"article",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="article.article",
unique=True,
),
),
(
"creator",
models.ForeignKey(
editable=False,
on_delete=django.db.models.deletion.CASCADE,
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.CASCADE,
related_name="%(class)s_last_mod_user",
to=settings.AUTH_USER_MODEL,
verbose_name="Updater",
),
),
("site_status", models.ManyToManyField(to="article.scielositestatus")),
],
options={
"abstract": False,
},
),
]
202 changes: 201 additions & 1 deletion article/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import datetime

from django.contrib.auth import get_user_model
from django.db import models
from django.db import models, IntegrityError
from django.utils.translation import gettext_lazy as _
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
Expand Down Expand Up @@ -29,6 +30,10 @@
User = get_user_model()


def verify_type_of_url(type):
return dict(choices.VERIFY_ARTICLE_TYPE).get("PDF") if type else dict(choices.VERIFY_ARTICLE_TYPE).get("TEXT")


class Article(ClusterableModel, CommonControlField):
"""
No contexto de Upload, Article deve conter o mínimo de campos,
Expand Down Expand Up @@ -314,3 +319,198 @@ def __str__(self) -> str:
return f"{self.article or self.pid_v3} - {self.deadline}"

base_form_class = RequestArticleChangeForm


class CheckArticleAvailability(CommonControlField):
"""
Modelo para armazenar o status de disponibilidade nos sites,
tanto na nova versao, quanto na antiga, do scielo.br.
"""
article = models.ForeignKey(
Copy link
Member

@robertatakenaka robertatakenaka Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelveigarangel adicione a collection de modo que checará a disponibilidade em todas as coleções. Também deveria ser considerado a disponibilidade no site QA, inclusive saber se está disponível em ambos ou em somente um

Article,
on_delete=models.SET_NULL,
null=True,
unique=True,
)
site_status = models.ManyToManyField(
"ScieloSiteStatus"
)

def __str__(self):
return f"{self.article.pid_v3}"

@classmethod
def get(cls, article):
return cls.objects.get(article=article)

def create_or_update_scielo_site_status(
self,
url,
status,
type,
available,
user,
date=None,
):
obj = ScieloSiteStatus.create_or_update(
url=url,
status=status,
type=type,
available=available,
date=date,
user=user,
)
self.site_status.add(obj)
self.save()


@classmethod
def create(
cls,
article,
status,
available,
url,
type,
user,
date=None,
):
try:
obj = cls(
article=article,
creator=user,
)
obj.save()
except IntegrityError:
obj = cls.get(article=article)
obj.create_or_update_scielo_site_status(
url=url,
status=status,
type=type,
available=available,
user=user,
date=date,
)
return obj

@classmethod
def create_or_update(cls,
article,
status,
available,
url,
type,
user,
date=None,
):
try:
obj = cls.get(article=article)
obj.create_or_update_scielo_site_status(
url=url,
status=status,
type=type,
available=available,
date=date,
user=user,
)
return obj
except cls.DoesNotExist:
cls.create(
article=article,
status=status,
available=available,
url=url,
type=type,
date=date,
user=user
)

class ScieloSiteStatus(CommonControlField):
check_date = models.DateTimeField(null=True, blank=True)
url_site_scielo = models.SlugField(max_length=500, unique=True)
status = models.CharField(
max_length=80,
null=True,
blank=True
)
type = models.CharField(
max_length=10,
choices=choices.VERIFY_ARTICLE_TYPE,
null=True,
blank=True,
)
available = models.BooleanField(default=False)

def update(
self,
status,
type,
available,
date=None,
):
self.check_date = date or datetime.datetime.now()
self.status = status
self.available = available
self.type = verify_type_of_url(type)
self.save()
return self

class Meta:
verbose_name = "Scielo Site Status"
verbose_name_plural = "Scielo Site Status"

@classmethod
def get(cls, url):
return cls.objects.get(url_site_scielo=url)


@classmethod
def create(
cls,
url,
status,
type,
available,
user,
date=None,
):
date = date or datetime.datetime.now()
obj = cls(
check_date=date,
url_site_scielo=url,
status=status,
type=verify_type_of_url(type),
available=available,
creator=user
)
obj.save()
return obj

@classmethod
def create_or_update(
cls,
url,
status,
type,
available,
user,
date=None,
):
try:
obj = cls.get(url=url)
obj.update(
status=status,
type=type,
available=available,
date=date
)
return obj
except cls.DoesNotExist:
return cls.create(
url=url,
status=status,
type=type,
available=available,
user=user,
date=date
)
11 changes: 11 additions & 0 deletions article/scripts/load_check_article.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from article.tasks import initiate_article_availability_check


def run(pid_v3, username=None, user_id=None):
initiate_article_availability_check.apply_async(
kwargs=dict(
username=username,
user_id=user_id,
article_pid_v3=pid_v3,
)
)
Loading