-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add api for fetching timezones (#1959)
SDCP-279
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Feature: Localization | ||
|
||
@auth | ||
Scenario: Get timezones | ||
|
||
When we get "/locales/timezones" | ||
Then we get existing resource | ||
""" | ||
{"timezones": [ | ||
{ | ||
"id": "America/Edmonton", | ||
"name": "Mountain Time", | ||
"location": "Canada (Edmonton) Time" | ||
} | ||
]} | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
import pytz | ||
import flask | ||
import babel.dates as dates | ||
|
||
from apps.auth import get_user | ||
|
||
|
||
bp = flask.Blueprint('locales', __name__) | ||
|
||
|
||
@bp.route('/locales/timezones') | ||
def locales_view(): | ||
if not flask.current_app.auth.authorized([], 'locales', 'GET'): | ||
flask.abort(401) | ||
user = get_user() | ||
lang = user.get('language', flask.current_app.config.get('DEFAULT_LANGUAGE', 'en')).replace('-', '_') | ||
return flask.jsonify({ | ||
'timezones': [ | ||
{ | ||
'id': tz, | ||
'name': dates.get_timezone_name(tz, locale=lang), | ||
'location': dates.get_timezone_location(tz, locale=lang), | ||
} for tz in pytz.common_timezones | ||
] | ||
}) | ||
|
||
|
||
def init_app(app): | ||
bp.url_prefix = '/{}'.format(app.config['URL_PREFIX'].lstrip('/')) | ||
app.register_blueprint(bp) |