Skip to content

Commit

Permalink
[SDESK-7327] Replace flask_babel with quart_babel (superdesk#2060)
Browse files Browse the repository at this point in the history
* [SDESK-7327] Replace flask_babel with quart_babel

* fix github repo for core

* use superdesk/async branch
  • Loading branch information
MarkLark86 authored Aug 16, 2024
1 parent c2a4be6 commit abd9fb4
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 44 deletions.
40 changes: 7 additions & 33 deletions server/planning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import logging
import superdesk
from flask_babel import lazy_gettext
from quart_babel import lazy_gettext

from superdesk.resource_fields import ID_FIELD
from .agendas import AgendasResource, AgendasService
Expand Down Expand Up @@ -292,38 +292,12 @@ def init_app(app):

init_scheduled_exports_task(app)

# Create 'type' required for planning module if not already preset
with app.app_context():
vocabulary_service = superdesk.get_resource_service("vocabularies")
types = vocabulary_service.find_one(req=None, _id="type")
if types:
items = types.get("items") or []
added_types = []
type_names = [t["qcode"] for t in items]

planning_type_list = [
{"is_active": True, "name": "Planning item", "qcode": "planning"},
{"is_active": True, "name": "Event", "qcode": "event"},
{
"is_active": True,
"name": "Featured Stories",
"qcode": "planning_featured",
},
]

for item in planning_type_list:
if item["qcode"] not in type_names:
added_types.append(item)

if len(added_types) > 0:
vocabulary_service.patch(types.get(ID_FIELD), {"items": (items + added_types)})

custom_loaders = jinja2.ChoiceLoader(
app.jinja_loader.loaders + [jinja2.FileSystemLoader(os.path.join(_SERVER_PATH, "templates"))]
)
app.jinja_loader = custom_loaders

register_jinja_filter("formatted_address", get_formatted_address)
custom_loaders = jinja2.ChoiceLoader(
app.jinja_loader.loaders + [jinja2.FileSystemLoader(os.path.join(_SERVER_PATH, "templates"))]
)
app.jinja_loader = custom_loaders

register_jinja_filter("formatted_address", get_formatted_address)

# add planning translations directory
app.config["BABEL_TRANSLATION_DIRECTORIES"] += ";" + os.path.join(_SERVER_PATH, "translations")
Expand Down
2 changes: 1 addition & 1 deletion server/planning/assignments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# at https://www.sourcefabric.org/superdesk/license

import superdesk
from flask_babel import lazy_gettext
from quart_babel import lazy_gettext
from superdesk.services import BaseService
from .assignments import AssignmentsResource, AssignmentsService
from .assignments_content import AssignmentsContentResource, AssignmentsContentService
Expand Down
2 changes: 1 addition & 1 deletion server/planning/assignments/assignments_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license
from copy import deepcopy
from flask_babel import _
from quart_babel import gettext as _

from superdesk.resource_fields import ID_FIELD
from superdesk import Resource, Service, get_resource_service
Expand Down
2 changes: 1 addition & 1 deletion server/planning/content_profiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# at https://www.sourcefabric.org/superdesk/license

from eve import Eve
from flask_babel import lazy_gettext
from quart_babel import lazy_gettext

import superdesk

Expand Down
2 changes: 1 addition & 1 deletion server/planning/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# at https://www.sourcefabric.org/superdesk/license

import superdesk
from flask_babel import lazy_gettext
from quart_babel import lazy_gettext
from .events import EventsResource, EventsService
from .events_spike import (
EventsSpikeResource,
Expand Down
2 changes: 1 addition & 1 deletion server/planning/feeding_services/onclusive_api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Optional
from datetime import timedelta, datetime
from flask_babel import lazy_gettext
from quart_babel import lazy_gettext
from superdesk.io.registry import register_feeding_service_parser
from superdesk.io.feeding_services.http_base_service import HTTPFeedingServiceBase
from superdesk.timer import timer
Expand Down
2 changes: 1 addition & 1 deletion server/planning/io/ingest_rule_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Dict, Any, Optional
import logging

from flask_babel import lazy_gettext
from quart_babel import lazy_gettext
from bson import ObjectId

from superdesk.resource_fields import ID_FIELD
Expand Down
2 changes: 1 addition & 1 deletion server/planning/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from flask_babel import lazy_gettext
from quart_babel import lazy_gettext
import superdesk
from .locations_service import LocationsResource, LocationsService

Expand Down
2 changes: 1 addition & 1 deletion server/planning/planning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from flask_babel import lazy_gettext
from quart_babel import lazy_gettext

import superdesk

Expand Down
2 changes: 1 addition & 1 deletion server/planning/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# at https://www.sourcefabric.org/superdesk/license

import superdesk
from flask_babel import lazy_gettext
from quart_babel import lazy_gettext
from .planning_search import PlanningSearchResource, PlanningSearchService
from .eventsplanning_search import EventsPlanningResource, EventsPlanningService
from .eventsplanning_filters import (
Expand Down
2 changes: 1 addition & 1 deletion server/planning/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from bson.objectid import ObjectId
from bson.errors import InvalidId
from flask_babel import lazy_gettext
from quart_babel import lazy_gettext
from eve.utils import str_to_date, ParsedRequest
import arrow
import pytz
Expand Down
2 changes: 1 addition & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ pytest-env

-e .
# Install in editable state so we get feature fixtures
-e git+https://github.com/superdesk/superdesk-core.git@async#egg=superdesk-core
-e git+https://github.com/superdesk/superdesk-core.git@async

0 comments on commit abd9fb4

Please sign in to comment.