API & Client: fix

- user edition
- title for activity with gpx and no name in gpx
- style
This commit is contained in:
Sam 2018-06-14 13:39:18 +02:00
parent 019ed42bae
commit 3acdabb4da
6 changed files with 51 additions and 8 deletions

View File

@ -25,14 +25,21 @@ class ActivityException(Exception):
def get_datetime_with_tz(timezone, activity_date, gpx_data=None): def get_datetime_with_tz(timezone, activity_date, gpx_data=None):
# activity date in gpx are directly in UTC
activity_date_tz = None activity_date_tz = None
if timezone and not gpx_data: if timezone:
user_tz = pytz.timezone(timezone) user_tz = pytz.timezone(timezone)
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_tz = user_tz.localize(activity_date)
if not gpx_data: activity_date = activity_date_tz.astimezone(utc_tz)
# make datetime 'naive' like in gpx file # make datetime 'naive' like in gpx file
activity_date = activity_date_tz.astimezone(pytz.utc)
activity_date = activity_date.replace(tzinfo=None) activity_date = activity_date.replace(tzinfo=None)
return activity_date_tz, activity_date return activity_date_tz, activity_date

View File

@ -311,6 +311,41 @@ def test_add_an_activity_with_gpx_without_name(
assert_activity_data_with_gpx(data) 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( def test_get_an_activity_with_gpx_notes(
app, user_1, sport_1_cycling, gpx_file app, user_1, sport_1_cycling, gpx_file
): ):

View File

@ -85,6 +85,7 @@ export const handleProfileFormSubmit = formData => dispatch => {
'Password and password confirmation don\'t match.' 'Password and password confirmation don\'t match.'
)) ))
} }
delete formData.id
return FitTrackeeGenericApi return FitTrackeeGenericApi
.postData('auth/profile/edit', formData) .postData('auth/profile/edit', formData)
.then(ret => { .then(ret => {

View File

@ -46,7 +46,7 @@ a {
color: #40578a; color: #40578a;
} }
input, textarea { input[type="text"], textarea {
width: 100%; width: 100%;
} }

View File

@ -27,7 +27,7 @@ export default function RecordsCard (props) {
? 'No records' ? 'No records'
: (Object.keys(recordsBySport).map(sportLabel => ( : (Object.keys(recordsBySport).map(sportLabel => (
<table <table
className="table table-borderless record-table" className="table table-borderless table-sm record-table"
key={sportLabel} key={sportLabel}
> >
<thead> <thead>

View File

@ -40,7 +40,7 @@ export default class FitTrackeeApi {
static postData(target, data) { static postData(target, data) {
const params = { const params = {
url: `${apiUrl}${target}/${data.id}`, url: `${apiUrl}${target}${data.id ? `/${data.id}` : '' }`,
method: 'POST', method: 'POST',
body: data, body: data,
type: 'application/json', type: 'application/json',