From e6d2ad914f96df25ef271378a6478e2cec31fe31 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 8 May 2018 19:27:39 +0200 Subject: [PATCH] API & Client: adding activity w/o gpx update --- mpwo_api/mpwo_api/activities/activities.py | 2 +- mpwo_api/mpwo_api/tests/test_activities.py | 4 +- .../ActivityForms/FormWithoutGpx.jsx | 60 ++++++++++++------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/mpwo_api/mpwo_api/activities/activities.py b/mpwo_api/mpwo_api/activities/activities.py index 8b49226a..c8c2bf20 100644 --- a/mpwo_api/mpwo_api/activities/activities.py +++ b/mpwo_api/mpwo_api/activities/activities.py @@ -207,7 +207,7 @@ def post_activity_no_gpx(auth_user_id): user_id=auth_user_id, sport_id=activity_data.get('sport_id'), activity_date=datetime.strptime( - activity_data.get('activity_date'), '%Y-%m-%d'), + activity_data.get('activity_date'), '%Y-%m-%d %H:%M'), duration=timedelta(seconds=activity_data.get('duration')) ) new_activity.moving = new_activity.duration diff --git a/mpwo_api/mpwo_api/tests/test_activities.py b/mpwo_api/mpwo_api/tests/test_activities.py index ca11d688..0995d8b0 100644 --- a/mpwo_api/mpwo_api/tests/test_activities.py +++ b/mpwo_api/mpwo_api/tests/test_activities.py @@ -270,7 +270,7 @@ def test_add_an_activity_no_gpx(app): data=json.dumps(dict( sport_id=1, duration=3600, - activity_date='2018-05-15', + activity_date='2018-05-15 14:05', distance=10 )), headers=dict( @@ -285,7 +285,7 @@ def test_add_an_activity_no_gpx(app): assert 'created' in data['status'] assert len(data['data']['activities']) == 1 assert 'creation_date' in data['data']['activities'][0] - assert data['data']['activities'][0]['activity_date'] == 'Tue, 15 May 2018 00:00:00 GMT' # noqa + assert data['data']['activities'][0]['activity_date'] == 'Tue, 15 May 2018 14:05:00 GMT' # noqa assert data['data']['activities'][0]['user_id'] == 1 assert data['data']['activities'][0]['sport_id'] == 1 assert data['data']['activities'][0]['duration'] == '1:00:00' diff --git a/mpwo_client/src/components/Activities/ActivityForms/FormWithoutGpx.jsx b/mpwo_client/src/components/Activities/ActivityForms/FormWithoutGpx.jsx index ecf20001..be237e78 100644 --- a/mpwo_client/src/components/Activities/ActivityForms/FormWithoutGpx.jsx +++ b/mpwo_client/src/components/Activities/ActivityForms/FormWithoutGpx.jsx @@ -31,21 +31,35 @@ function FormWithoutGpx (props) {
@@ -54,6 +68,8 @@ function FormWithoutGpx (props) { @@ -78,18 +94,18 @@ export default connect( () => ({ }), dispatch => ({ onAddSport: e => { - const data = [].slice - .call(e.target.form.elements) - .reduce(function(map, obj) { - if (obj.name) { - if (obj.name === 'duration' || obj.name === 'distance') { - map[obj.name] = +obj.value - } else { - map[obj.name] = obj.value - } - } - return map - }, {}) + const d = e.target.form.duration.value.split(':') + const duration = +d[0] * 60 * 60 + +d[1] * 60 + +d[2] + + const activityDate = `${e.target.form.activity_date.value + } ${ e.target.form.activity_time.value}` + + const data = { + activity_date: activityDate, + distance: +e.target.form.distance.value, + duration, + sport_id: +e.target.form.sport_id.value, + } dispatch(addActivityWithoutGpx(data)) }, })