Skip to content

Commit

Permalink
#4146: Add deprecation notice on create_galley_from_file
Browse files Browse the repository at this point in the history
  • Loading branch information
mauromsl authored and ajrbyers committed May 1, 2024
1 parent e33d105 commit b976a2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/migrations/0088_fix_untyped_galleys.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class Migration(migrations.Migration):
('metrics', '0010_auto_20230317_1534'),
]


def fix_untyped_galleys(apps, schema_editor):
""" Fixes galleys that haven't had a type set and linked metrics records"""

Galley = apps.get_model('core', 'Galley')
ArticleAccess = apps.get_model('metrics','ArticleAccess')
for galley in Galley.objects.filter(type="",file__isnull=False, article__isnull=False):
for galley in Galley.objects.filter(type="", file__isnull=False, article__isnull=False):
_, galley_type = get_galley_label_and_type(galley.file)
galley.galley_type = galley_type
galley.save()
Expand All @@ -27,6 +28,6 @@ def fix_untyped_galleys(apps, schema_editor):
).update(galley_type=galley_type)


operations = [
migrations.RunPython(fix_untyped_galleys, reverse_code=migrations.RunPython.noop),
]
operations = [
migrations.RunPython(fix_untyped_galleys, reverse_code=migrations.RunPython.noop),
]
6 changes: 6 additions & 0 deletions src/journal/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from shutil import copyfile
from urllib.parse import urlencode
from uuid import uuid4
import warnings

from django.contrib import messages
from django.conf import settings
Expand Down Expand Up @@ -85,6 +86,11 @@ def list_scss(journal):
def create_galley_from_file(file_object, article_object, owner=None):
# we copy the file here so that the user submitting has no control over the typeset files
# N.B. os.path.splitext[1] always returns the final file extension, even in a multi-dotted (.txt.html etc.) input

warnings.warn(
"'create_galley_from_file' is deprecated and will be removed,"
" use production.logic.save_galley instead."
)
new_filename = str(uuid4()) + str(os.path.splitext(file_object.uuid_filename)[1])
folder_structure = os.path.join(settings.BASE_DIR, 'files', 'articles', str(article_object.id))

Expand Down

0 comments on commit b976a2a

Please sign in to comment.