Skip to content

Commit

Permalink
Merge pull request #572 from robertatakenaka/rc-rc3.0.0rc4
Browse files Browse the repository at this point in the history
Corrige o fluxo de solicitação de mudanças em artigos já publicados
  • Loading branch information
robertatakenaka authored Nov 20, 2024
2 parents ced41ea + ef0c886 commit 4c8b0d5
Show file tree
Hide file tree
Showing 22 changed files with 618 additions and 282 deletions.
47 changes: 22 additions & 25 deletions article/button_helper.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from django.utils.translation import gettext as _
from wagtail.contrib.modeladmin.helpers import ButtonHelper

# FIXME
# from upload.choices import PC_ERRATUM, PC_UPDATE

from .choices import AS_REQUIRE_ERRATUM, AS_REQUIRE_UPDATE
from article.choices import AS_REQUIRE_ERRATUM, AS_REQUIRE_UPDATE


class RequestArticleChangeButtonHelper(ButtonHelper):
Expand Down Expand Up @@ -60,13 +57,13 @@ def get_buttons_for_obj(
if url_name.endswith("_modeladmin_index"):
classnames.extend(ArticleButtonHelper.index_button_classnames)

if ph.user_can_make_article_change(usr, obj.article) and obj.article.status in (
AS_REQUIRE_ERRATUM,
AS_REQUIRE_UPDATE,
):
if obj.demanded_user == usr:
btns.append(self.submit_change(obj, classnames))
btns.append(self.see_instructions(obj, classnames))
# if ph.user_can_make_article_change(usr, obj.article) and obj.article.status in (
# AS_REQUIRE_ERRATUM,
# AS_REQUIRE_UPDATE,
# ):
# if obj.demanded_user == usr:
# btns.append(self.submit_change(obj, classnames))
# btns.append(self.see_instructions(obj, classnames))

return btns

Expand Down Expand Up @@ -123,19 +120,19 @@ def get_buttons_for_obj(
if url_name == "article_article_modeladmin_index":
classnames.extend(ArticleButtonHelper.index_button_classnames)

if ph.user_can_request_article_change(usr, obj) and obj.status not in (
AS_REQUIRE_UPDATE,
AS_REQUIRE_ERRATUM,
):
btns.append(self.request_change(obj, classnames))

if ph.user_can_make_article_change(usr, obj) and obj.status in (
AS_REQUIRE_ERRATUM,
AS_REQUIRE_UPDATE,
):
for rac in obj.requestarticlechange_set.all():
if rac.demanded_user == usr:
btns.append(self.submit_change(obj, classnames))
break
# if ph.user_can_request_article_change(usr, obj) and obj.status not in (
# AS_REQUIRE_UPDATE,
# AS_REQUIRE_ERRATUM,
# ):
# btns.append(self.request_change(obj, classnames))

# if ph.user_can_make_article_change(usr, obj) and obj.status in (
# AS_REQUIRE_ERRATUM,
# AS_REQUIRE_UPDATE,
# ):
# for rac in obj.requestarticlechange_set.all():
# if rac.demanded_user == usr:
# btns.append(self.submit_change(obj, classnames))
# break

return btns
2 changes: 1 addition & 1 deletion article/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def clean(self):

def save_all(self, user):
request_article_change = super().save_all(user)
article = request_article_change
article = request_article_change.article
if request_article_change.change_type == choices.RCT_ERRATUM:
article.status = choices.AS_REQUIRE_ERRATUM
elif request_article_change.change_type == choices.RCT_UPDATE:
Expand Down
62 changes: 40 additions & 22 deletions article/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,27 @@ class Article(ClusterableModel, CommonControlField):
)
panel_article_ids.children = [
# FieldPanel("pid_v2"),
FieldPanel("pid_v3"),
FieldPanel("pid_v3", read_only=True),
# FieldPanel("aop_pid"),
]

panel_article_details = MultiFieldPanel(
heading="Article details", classname="collapsible"
)
panel_article_details.children = [
FieldPanel("first_publication_date"),
FieldPanel("article_type"),
FieldPanel("status"),
FieldPanel("first_publication_date", read_only=True),
FieldPanel("article_type", read_only=True),
FieldPanel("status", read_only=True),
InlinePanel(relation_name="title_with_lang", label="Title with Language"),
FieldPanel("elocation_id"),
FieldPanel("fpage"),
FieldPanel("lpage"),
FieldPanel("elocation_id", read_only=True),
FieldPanel("fpage", read_only=True),
FieldPanel("lpage", read_only=True),
]

panels = [
panel_article_ids,
panel_article_details,
FieldPanel("issue", classname="collapsible"),
FieldPanel("issue", classname="collapsible", read_only=True),
]

base_form_class = ArticleForm
Expand Down Expand Up @@ -346,24 +346,38 @@ def multilingual_sections(self):
def display_sections(self):
return str(self.multilingual_sections)

def update_status(self, new_status=None):
# TODO create PublicationEvent
if self.status == choices.AS_UPDATE_SUBMITTED:
self.status = choices.AS_REQUIRE_UPDATE
self.save()
return

if self.status == choices.AS_ERRATUM_SUBMITTED:
self.status = choices.AS_REQUIRE_ERRATUM
self.save()
return

def update_status(self, new_status=None, rollback=False):
# AS_UPDATE_SUBMITTED = "update-submitted"
# AS_ERRATUM_SUBMITTED = "erratum-submitted"
# AS_REQUIRE_UPDATE = "required-update"
# AS_REQUIRE_ERRATUM = "required-erratum"
# AS_PREPARE_TO_PUBLISH = "prepare-to-publish"
# AS_READY_TO_PUBLISH = "ready-to-publish"
# AS_SCHEDULED_TO_PUBLISH = "scheduled-to-publish"
# AS_PUBLISHED = "published"
self.status = new_status or choices.AS_PUBLISHED
self.save()

# TODO create PublicationEvent

if rollback:
if self.status == choices.AS_ERRATUM_SUBMITTED:
self.status = choices.AS_REQUIRE_ERRATUM
self.save()
return
elif self.status not in (choices.AS_REQUIRE_UPDATE, choices.AS_REQUIRE_ERRATUM):
self.status = choices.AS_REQUIRE_UPDATE
self.save()
return
else:
if self.status == choices.AS_REQUIRE_UPDATE:
self.status = choices.AS_UPDATE_SUBMITTED
self.save()
return
if self.status == choices.AS_REQUIRE_ERRATUM:
self.status = choices.AS_ERRATUM_SUBMITTED
self.save()
return
self.status = new_status or choices.AS_PUBLISHED
self.save()

def get_zip_filename_and_content(self):
return self.sps_pkg.get_zip_filename_and_content()
Expand All @@ -380,6 +394,10 @@ class ArticleTitle(HTMLTextModel, CommonControlField):
"Article", on_delete=models.CASCADE, related_name="title_with_lang"
)

panels = [
FieldPanel("text", read_only=True),
FieldPanel("language", read_only=True),
]

class RelatedItem(CommonControlField):
item_type = models.CharField(
Expand Down
2 changes: 1 addition & 1 deletion article/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ArticleModelAdminGroup(ModelAdminGroup):
items = (
ArticleModelAdmin,
# RelatedItemModelAdmin,
RequestArticleChangeModelAdmin,
# omitir temporariamente RequestArticleChangeModelAdmin,
# ApprovedArticleModelAdmin,
)

Expand Down
4 changes: 2 additions & 2 deletions core/templates/wagtailadmin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
{% else %}
<img src="{% static 'images/logos/logo_scielo_negative100x100.png' %}" alt="SciELO logo"/>
{% endif %}
<br/>Upload v3.0.0rc3
{% endblock %}
<br/>Upload v3.0.0rc4
{% endblock %}
12 changes: 12 additions & 0 deletions journal/migrations/0007_merge_20241113_1945.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Generated by Django 5.0.3 on 2024-11-13 19:45

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("journal", "0005_journaltoc_alter_journal_official_journal_and_more"),
("journal", "0006_alter_journalsection_text"),
]

operations = []
77 changes: 39 additions & 38 deletions package/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def save_file(self, name, content):
try:
self.file.delete(save=True)
except Exception as e:
pass
logging.exception(f"Unable to delete {self.file.path} {e} {type(e)}")
try:
self.file.save(name, ContentFile(content))
except Exception as e:
Expand Down Expand Up @@ -340,7 +340,7 @@ def save_file(self, name, content):
try:
self.file.delete(save=True)
except Exception as e:
pass
logging.exception(f"Unable to delete {self.file.path} {e} {type(e)}")
try:
self.file.save(name, ContentFile(content))
except Exception as e:
Expand Down Expand Up @@ -628,45 +628,29 @@ def add_pid_v3_to_zip(cls, user, zip_xml_file_path, is_public, article_proc):
def save_pkg_zip_file(self, user, zip_file_path, article_proc):
operation = article_proc.start(user, "save_pkg_zip_file")
filename = self.sps_pkg_name + ".zip"
# saved original
try:
with TemporaryDirectory() as targetdir:
with TemporaryDirectory() as workdir:
target = os.path.join(targetdir, filename)
package = SPPackage.from_file(zip_file_path, workdir)
package.optimise(new_package_file_path=target, preserve_files=False)

# saved optimised
with open(target, "rb") as fp:
self.save_file(filename, fp.read())
operation.finish(
user,
completed=True,
detail={"source": target, "optimized": True},
)
with open(zip_file_path, "rb") as fp:
self.save_file(filename, fp.read())
operation.finish(
user,
completed=True,
detail={"source": zip_file_path, "optimized": False},
)
except Exception as e:
# saved original
try:
with open(zip_file_path, "rb") as fp:
self.save_file(filename, fp.read())
operation.finish(
user,
completed=True,
detail={"source": zip_file_path, "optimized": False, "message": str(e)},
)
except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
operation.finish(
user,
exc_traceback=exc_traceback,
exception=e,
detail={"source": zip_file_path, "optimized": False},
)
exc_type, exc_value, exc_traceback = sys.exc_info()
operation.finish(
user,
exc_traceback=exc_traceback,
exception=e,
detail={"source": zip_file_path, "optimized": False},
)

def save_file(self, name, content):
try:
self.file.delete(save=True)
except Exception as e:
pass
logging.exception(f"Unable to delete {self.file.path} {e} {type(e)}")
try:
self.file.save(name, ContentFile(content))
except Exception as e:
Expand All @@ -688,8 +672,8 @@ def upload_package_to_the_cloud(self, user, original_pkg_components, article_pro
xml_with_pre = self.upload_items_to_the_cloud(
user,
article_proc,
"upload_assets_to_the_cloud",
self.upload_assets_to_the_cloud,
"upload_zip_content_to_the_cloud",
self.upload_zip_content_to_the_cloud,
**{"original_pkg_components": original_pkg_components},
)
self.upload_items_to_the_cloud(
Expand Down Expand Up @@ -776,10 +760,27 @@ def upload_to_the_cloud(
response["filename"] = filename
return response

def upload_assets_to_the_cloud(self, user, original_pkg_components):
def upload_zip_content_to_the_cloud(self, user, original_pkg_components):
filename = self.sps_pkg_name + ".zip"
try:
result = {}
with TemporaryDirectory() as targetdir:
with TemporaryDirectory() as workdir:
zip_file_path = os.path.join(targetdir, filename)
package = SPPackage.from_file(zip_file_path, workdir)
package.optimise(new_package_file_path=target, preserve_files=False)
result = self.upload_components_to_the_cloud(user, original_pkg_components, zip_file_path)
return result
except Exception as e:
zip_file_path = self.file.path
return self.upload_components_to_the_cloud(user, original_pkg_components, zip_file_path)


def upload_components_to_the_cloud(self, user, original_pkg_components, zip_file_path):
xml_with_pre = None
items = []
with ZipFile(self.file.path) as optimised_fp:

with ZipFile(zip_file_path) as optimised_fp:
for item in set(optimised_fp.namelist()):
name, ext = os.path.splitext(item)
content = optimised_fp.read(item)
Expand Down
2 changes: 1 addition & 1 deletion proc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def publish(
self.migrated_data.content_type == "article" and
(not self.sps_pkg or not self.sps_pkg.registered_in_core)
):
detail["registered_in_core"] = self.self.sps_pkg.registered_in_core
detail["registered_in_core"] = self.sps_pkg.registered_in_core
doit = False
else:
doit = tracker_choices.allowed_to_run(
Expand Down
2 changes: 1 addition & 1 deletion production-v3.0.0rc2.yml → production-v3.0.0rc4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:
django: &django
image: infrascielo/upload
image: infrascielo/upload:v3.0.0rc4
container_name: upload_production_django
platform: linux/x86_64
depends_on:
Expand Down
25 changes: 19 additions & 6 deletions publication/api/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ def add_author(self, surname, given_names, suffix, affiliation, orcid):
# )
# self.data["authors"].append(_author)

def add_collab(self, name):
# collab
self.data.setdefault("collabs", [])
self.data["collabs"].append({"name": name})

def add_translated_title(self, language, text):
# translated_titles"] = EmbeddedDocumentListField(TranslatedTitle))
if self.data["translated_titles"] is None:
Expand Down Expand Up @@ -186,16 +191,24 @@ def add_doi_with_lang(self, language, doi):
_doi_with_lang_item["language"] = language
self.data["doi_with_lang"].append(_doi_with_lang_item)

def add_related_article(self, doi, ref_id, related_type):
def add_related_article(self, ref_id, related_type, ext_link_type, href):
# related_article"] = EmbeddedDocumentListField(RelatedArticle))
if self.data["related_articles"] is None:
self.data["related_articles"] = []
_related_article = {}
_related_article["doi"] = doi
_related_article["ref_id"] = ref_id
_related_article["related_type"] = related_type
self.data["related_articles"].append(_related_article)

if ext_link_type == "doi":
_related_article["doi"] = href
_related_article["ref_id"] = ref_id
_related_article["related_type"] = related_type
self.data["related_articles"].append(_related_article)
else:
pass
# TODO depende de resolver https://github.com/scieloorg/opac_5/issues/212
# _related_article["href"] = href
# _related_article["ref_id"] = ref_id
# _related_article["related_type"] = related_type
# self.data["related_articles"].append(_related_article)

def add_xml(self, xml):
self.data["xml"] = xml

Expand Down
Loading

0 comments on commit 4c8b0d5

Please sign in to comment.