From 8d561ed4232346ad47c5eac3baee01978018db9b Mon Sep 17 00:00:00 2001 From: "create-issue-branch[bot]" <53036503+create-issue-branch[bot]@users.noreply.github.com> Date: Thu, 23 Sep 2021 11:01:02 +0200 Subject: [PATCH] Non-UTC default timezone for new users (#190) Use the FLEXMEASURES_TIMEZONE config setting as a more sensible default for new users. * Create draft PR for #189 * Apply default user timezone from FLEXMEASURES_TIMEZONE config setting * Changelog entry Co-authored-by: Flix6x Co-authored-by: F.N. Claessen --- documentation/changelog.rst | 1 + flexmeasures/data/scripts/cli_tasks/data_add.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/documentation/changelog.rst b/documentation/changelog.rst index 977ce66cf..02a5933cb 100644 --- a/documentation/changelog.rst +++ b/documentation/changelog.rst @@ -20,6 +20,7 @@ Bugfixes Infrastructure / Support ---------------------- * FlexMeasures plugins can be Python packages now. We provide `a cookie-cutter template `_ for this approach. [see `PR #182 `_] +* Set default timezone for new users using the FLEXMEASURES_TIMEZONE config setting [see `PR #190 `_] v0.6.1 | September XX, 2021 diff --git a/flexmeasures/data/scripts/cli_tasks/data_add.py b/flexmeasures/data/scripts/cli_tasks/data_add.py index e013d060f..0ca3fe317 100755 --- a/flexmeasures/data/scripts/cli_tasks/data_add.py +++ b/flexmeasures/data/scripts/cli_tasks/data_add.py @@ -99,11 +99,14 @@ def new_account(name: str, roles: List[str]): @click.option("--roles", help="e.g. anonymous,Prosumer,CPO") @click.option( "--timezone", - default="UTC", - help="timezone as string, e.g. 'UTC' or 'Europe/Amsterdam'", + help="timezone as string, e.g. 'UTC' or 'Europe/Amsterdam' (defaults to FLEXMEASURES_TIMEZONE config setting)", ) def new_user( - username: str, email: str, account_id: int, roles: List[str], timezone: str + username: str, + email: str, + account_id: int, + roles: List[str], + timezone: Optional[str], ): """ Create a FlexMeasures user. @@ -111,6 +114,11 @@ def new_user( The `users create` task from Flask Security Too is too simple for us. Use this to add email, timezone and roles. """ + if timezone is None: + timezone = app.config.get("FLEXMEASURES_TIMEZONE") + print( + f"Setting user timezone to {timezone} (taken from FLEXMEASURES_TIMEZONE config setting)..." + ) try: pytz.timezone(timezone) except pytz.UnknownTimeZoneError: