Skip to content

Commit

Permalink
data update to add section to content profiles (#2714)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis authored Sep 25, 2024
1 parent 58b39fd commit 41768d5
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions superdesk/data_updates/00034_20240924-123459_content_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8; -*-
# This file is part of Superdesk.
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license
#
# Author : tomas
# Creation: 2024-09-24 12:34

from superdesk.commands.data_updates import BaseDataUpdate
from eve.utils import config

header_fields = [
"slugline",
"keywords",
"genre",
"anpa_take_key",
"place",
"language",
"priority",
"urgency",
"anpa_category",
"subject",
"company_codes",
"ednote",
"authors",
]


class DataUpdate(BaseDataUpdate):
resource = "content_types"

def forwards(self, mongodb_collection, mongodb_database):
for profile in mongodb_collection.find({}):
try:
editor = profile.get("editor", {})
for field, properties in editor.items():
if properties and "section" not in properties:
properties["section"] = "header" if field in header_fields else "content"

mongodb_collection.update(
{"_id": profile.get(config.ID_FIELD)}, {"$set": {"editor": profile["editor"]}}
)
print(f"Content Profile {profile['_id']} updated successfully")
except Exception as e:
print(f"Error updating Content Profile {profile['_id']}: {str(e)}")

def backwards(self, mongodb_collection, mongodb_database):
raise NotImplementedError()

0 comments on commit 41768d5

Please sign in to comment.