Skip to content

Commit eeb8905

Browse files
committed
feat(amazon): Add system & user setting for Amazon region
Adds a setting to the system and user settings pages to allow users to select their Amazon region. This setting does nothing in this PR, but will be used in a PR further up the stack to select the correct Amazon regional site when searching for books.
1 parent 58a2980 commit eeb8905

File tree

7 files changed

+67
-2
lines changed

7 files changed

+67
-2
lines changed

cps/constants.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,26 @@ def _read_text(path: str, default: str = "") -> str:
232232
"zh_Hans_CN": _("Chinese (Simplified, China)"),
233233
"zh_Hant_TW": _("Chinese (Traditional, Taiwan)"),
234234
}
235+
236+
# NOTE: Keep "com" as the first entry, whichever region is first is the default region until one is chosen by the admin
237+
# or the user. All other regions should be kept in alphabetical order.
238+
AMAZON_REGIONS = [
239+
"com",
240+
"ae",
241+
"ca",
242+
"co.jp",
243+
"co.uk",
244+
"com.au",
245+
"com.br",
246+
"com.mx",
247+
"de",
248+
"es",
249+
"fr",
250+
"ie",
251+
"in",
252+
"it",
253+
"nl",
254+
"sa",
255+
"se",
256+
"sg",
257+
]

cps/cwa_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,8 @@ def set_cwa_settings():
914914
cwa_settings=cwa_settings, ignorable_formats=ignorable_formats, target_formats=target_formats,
915915
automerge_options=automerge_options, autoingest_options=autoingest_options,
916916
hardcover_token_available=hardcover_token_available,
917-
next_duplicate_scan_run=next_scan_run, config=config)
917+
next_duplicate_scan_run=next_scan_run, config=config,
918+
amazon_regions=constants.AMAZON_REGIONS)
918919

919920

920921
def get_next_duplicate_scan_run(settings):

cps/templates/cwa_settings.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,19 @@ <h4 class="settings-section-header">🔖 {{_('Hardcover Auto-Fetch Settings')}}<
734734
</div>
735735
</div>
736736

737+
<div class="settings-container">
738+
<div class="form-group">
739+
<h4 class="settings-section-header">{{_('Metadata Provider Settings')}}</h4>
740+
<label for="amazon_region" style="padding-right: 10px; margin-bottom: 16px !important;">{{_('Choose an Amazon region')}}:</label>
741+
<select class="cwa-settings-select" name="amazon_region" id="amazon_region">
742+
<option value="">({{ _('Default') }})</option>
743+
{% for region in amazon_regions -%}
744+
<option value="{{ region }}"{% if cwa_settings['amazon_region'] == region %} selected{% endif %}>www.amazon.{{ region }}</option>
745+
{% endfor %}
746+
</select>
747+
</div>
748+
</div>
749+
737750
<div class="settings-container">
738751
<h4 class="settings-section-header">{{_('Web UI Settings')}}</h4>
739752

cps/templates/user_edit.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,19 @@ <h4 class="settings-section-header">{{_('Book Language Filter')}}</h4>
292292
</div>
293293
{% endif %}
294294

295+
<div class="settings-container" style="max-width: none; margin-inline: 0rem;">
296+
<div class="form-group" style="margin-bottom: 20px; display: flex; flex-direction: column; gap: 0.5rem;">
297+
<h4 class="settings-section-header">{{_('Metadata Provider Settings')}}</h4>
298+
<label for="amazon_region" style="margin-bottom: 8px !important;">{{_('Choose an Amazon region')}}:</label>
299+
<select class="form-control" name="amazon_region" id="amazon_region">
300+
<option value="">({{ _('Global Default') }})</option>
301+
{% for region in amazon_regions -%}
302+
<option value="{{ region }}"{% if amazon_region == region %} selected{% endif %}>www.amazon.{{ region }}</option>
303+
{% endfor %}
304+
</select>
305+
</div>
306+
</div>
307+
295308
<!-- OAuth & API Integrations Card -->
296309
{% if (registered_oauth.keys()| length > 0 and not new_user and profile) or (hardcover_support and not new_user) or (kobo_support and not new_user) %}
297310
<div class="settings-container" style="max-width: none; margin-inline: 0rem;">

cps/ub.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ class User(UserBase, Base):
287287
auto_send_enabled = Column(Boolean, default=False)
288288
# Allow entering additional email addresses on send-to-eReader
289289
allow_additional_ereader_emails = Column(Boolean, default=True)
290+
amazon_region = Column(String, default=None)
290291

291292

292293
if oauth_support:
@@ -926,6 +927,16 @@ def migrate_user_table(engine, _session):
926927
print(f"[Migration] Warning: Could not update duplicates sidebar setting: {e}")
927928
_session.rollback()
928929

930+
# Migration to add Amazon region setting
931+
try:
932+
_session.query(exists().where(User.amazon_region)).scalar()
933+
_session.commit()
934+
except exc.OperationalError:
935+
with engine.connect() as conn:
936+
trans = conn.begin()
937+
conn.execute(text("ALTER TABLE user ADD column 'amazon_region' String DEFAULT ''"))
938+
trans.commit()
939+
929940
def migrate_oauth_provider_table(engine, _session):
930941
try:
931942
_session.query(exists().where(OAuthProvider.oauth_base_url)).scalar()

cps/web.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,7 @@ def change_profile(kobo_support, hardcover_support, local_oauth_check, oauth_sta
24322432
current_user.auto_send_enabled = to_save.get("auto_send_enabled") == "on"
24332433
current_user.auto_metadata_fetch = to_save.get("auto_metadata_fetch") == "on"
24342434
current_user.allow_additional_ereader_emails = to_save.get("allow_additional_ereader_emails") == "on"
2435+
current_user.amazon_region = to_save.get("amazon_region", "")
24352436

24362437
# Handle hidden magic shelf templates and custom shelves
24372438
from . import magic_shelf
@@ -2774,6 +2775,8 @@ def profile():
27742775
title=_(f"{current_user.name.capitalize()}'s Profile", name=current_user.name),
27752776
page="me",
27762777
registered_oauth=local_oauth_check,
2778+
amazon_regions=constants.AMAZON_REGIONS,
2779+
amazon_region=getattr(current_user, "amazon_region", ""),
27772780
oauth_status=oauth_status)
27782781

27792782

scripts/cwa_schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ CREATE TABLE IF NOT EXISTS cwa_settings(
101101
duplicate_scan_cron TEXT DEFAULT '' NOT NULL,
102102
duplicate_scan_hour INTEGER DEFAULT 3 NOT NULL,
103103
duplicate_scan_chunk_size INTEGER DEFAULT 5000 NOT NULL,
104-
duplicate_scan_debounce_seconds INTEGER DEFAULT 5 NOT NULL
104+
duplicate_scan_debounce_seconds INTEGER DEFAULT 5 NOT NULL,
105+
amazon_region TEXT DEFAULT "com" NOT NULL
105106
);
106107

107108
-- Persisted scheduled jobs (initial focus: auto-send). Rows remain until dispatched or manually cleared.

0 commit comments

Comments
 (0)