From 3acdabb4dad62f12363a9fe4c986ad65715025b3 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 14 Jun 2018 13:39:18 +0200 Subject: [PATCH] API & Client: fix - user edition - title for activity with gpx and no name in gpx - style --- .../fittrackee_api/activities/utils.py | 17 ++++++--- .../tests/test_activities_api_1_post.py | 35 +++++++++++++++++++ fittrackee_client/src/actions/user.js | 1 + fittrackee_client/src/components/App.css | 2 +- .../src/components/Dashboard/Records.jsx | 2 +- fittrackee_client/src/fitTrackeeApi/index.js | 2 +- 6 files changed, 51 insertions(+), 8 deletions(-) diff --git a/fittrackee_api/fittrackee_api/activities/utils.py b/fittrackee_api/fittrackee_api/activities/utils.py index e2ffac40..f5f3caba 100644 --- a/fittrackee_api/fittrackee_api/activities/utils.py +++ b/fittrackee_api/fittrackee_api/activities/utils.py @@ -25,14 +25,21 @@ class ActivityException(Exception): def get_datetime_with_tz(timezone, activity_date, gpx_data=None): - # activity date in gpx are directly in UTC activity_date_tz = None - if timezone and not gpx_data: + if timezone: user_tz = pytz.timezone(timezone) - activity_date_tz = user_tz.localize(activity_date) - if not gpx_data: + utc_tz = pytz.utc + if gpx_data: + # activity date in gpx is in UTC, but in naive datetime + fmt = '%Y-%m-%d %H:%M:%S' + activity_date_string = activity_date.strftime(fmt) + activity_date_tmp = utc_tz.localize( + datetime.strptime(activity_date_string, fmt)) + activity_date_tz = activity_date_tmp.astimezone(user_tz) + else: + activity_date_tz = user_tz.localize(activity_date) + activity_date = activity_date_tz.astimezone(utc_tz) # make datetime 'naive' like in gpx file - activity_date = activity_date_tz.astimezone(pytz.utc) activity_date = activity_date.replace(tzinfo=None) return activity_date_tz, activity_date diff --git a/fittrackee_api/fittrackee_api/tests/test_activities_api_1_post.py b/fittrackee_api/fittrackee_api/tests/test_activities_api_1_post.py index 112382df..0c360c07 100644 --- a/fittrackee_api/fittrackee_api/tests/test_activities_api_1_post.py +++ b/fittrackee_api/fittrackee_api/tests/test_activities_api_1_post.py @@ -311,6 +311,41 @@ def test_add_an_activity_with_gpx_without_name( assert_activity_data_with_gpx(data) +def test_add_an_activity_with_gpx_without_name_timezone( + app, user_1, sport_1_cycling, gpx_file_wo_name +): + user_1.timezone = 'Europe/Paris' + client = app.test_client() + resp_login = client.post( + '/api/auth/login', + data=json.dumps(dict( + email='test@test.com', + password='12345678' + )), + content_type='application/json' + ) + response = client.post( + '/api/activities', + data=dict( + file=(BytesIO(str.encode(gpx_file_wo_name)), 'example.gpx'), + data='{"sport_id": 1}' + ), + headers=dict( + content_type='multipart/form-data', + Authorization='Bearer ' + json.loads( + resp_login.data.decode() + )['auth_token'] + ) + ) + data = json.loads(response.data.decode()) + + assert response.status_code == 201 + assert 'created' in data['status'] + assert len(data['data']['activities']) == 1 + assert 'Cycling - 2018-03-13 13:44:45' == data['data']['activities'][0]['title'] # noqa + assert_activity_data_with_gpx(data) + + def test_get_an_activity_with_gpx_notes( app, user_1, sport_1_cycling, gpx_file ): diff --git a/fittrackee_client/src/actions/user.js b/fittrackee_client/src/actions/user.js index 88fc6aff..d6170aeb 100644 --- a/fittrackee_client/src/actions/user.js +++ b/fittrackee_client/src/actions/user.js @@ -85,6 +85,7 @@ export const handleProfileFormSubmit = formData => dispatch => { 'Password and password confirmation don\'t match.' )) } + delete formData.id return FitTrackeeGenericApi .postData('auth/profile/edit', formData) .then(ret => { diff --git a/fittrackee_client/src/components/App.css b/fittrackee_client/src/components/App.css index e6b00fb8..e1c289b9 100644 --- a/fittrackee_client/src/components/App.css +++ b/fittrackee_client/src/components/App.css @@ -46,7 +46,7 @@ a { color: #40578a; } -input, textarea { +input[type="text"], textarea { width: 100%; } diff --git a/fittrackee_client/src/components/Dashboard/Records.jsx b/fittrackee_client/src/components/Dashboard/Records.jsx index 7a386903..d3fb9be3 100644 --- a/fittrackee_client/src/components/Dashboard/Records.jsx +++ b/fittrackee_client/src/components/Dashboard/Records.jsx @@ -27,7 +27,7 @@ export default function RecordsCard (props) { ? 'No records' : (Object.keys(recordsBySport).map(sportLabel => ( diff --git a/fittrackee_client/src/fitTrackeeApi/index.js b/fittrackee_client/src/fitTrackeeApi/index.js index 3d59d604..be5bcef1 100644 --- a/fittrackee_client/src/fitTrackeeApi/index.js +++ b/fittrackee_client/src/fitTrackeeApi/index.js @@ -40,7 +40,7 @@ export default class FitTrackeeApi { static postData(target, data) { const params = { - url: `${apiUrl}${target}/${data.id}`, + url: `${apiUrl}${target}${data.id ? `/${data.id}` : '' }`, method: 'POST', body: data, type: 'application/json',