diff --git a/rowers/ownapistuff.py b/rowers/ownapistuff.py index 4a1754bf..3ec7088e 100644 --- a/rowers/ownapistuff.py +++ b/rowers/ownapistuff.py @@ -85,9 +85,9 @@ def get_token(code): client_auth = requests.auth.HTTPBasicAuth(TEST_CLIENT_ID, TEST_CLIENT_SECRET) post_data = {"grant_type": "authorization_code", "code": code, - "redirect_uri": TEST_REDIRECT_URI, - "client_secret": TEST_CLIENT_SECRET, - "client_id":TEST_CLIENT_ID, + "redirect_uri": "http://localhost:8000/rowers/test_callback", + "client_secret": "aapnootmies", + "client_id":1, } headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} @@ -99,12 +99,12 @@ def get_token(code): data=json.dumps(post_data), headers=headers) - print response.text token_json = response.json() thetoken = token_json['access_token'] expires_in = token_json['expires_in'] refresh_token = token_json['refresh_token'] + return [thetoken,expires_in,refresh_token] def make_authorization_url(request): diff --git a/rowers/permissions.py b/rowers/permissions.py index 03c1652b..67afe16c 100644 --- a/rowers/permissions.py +++ b/rowers/permissions.py @@ -13,9 +13,10 @@ class IsOwnerOrReadOnly(permissions.BasePermission): return True # Write permissions are only allowed to the owner of the snippet. - return obj.owner == request.user + return obj.user == request.user class IsOwnerOrNot(permissions.BasePermission): + def has_object_permission(self, request, view, obj): r = Rower.objects.get(user=request.user) return (obj.user == r) diff --git a/rowers/serializers.py b/rowers/serializers.py index b0890f54..e0c8b560 100644 --- a/rowers/serializers.py +++ b/rowers/serializers.py @@ -1,5 +1,5 @@ from rest_framework import serializers -from rowers.models import Workout,Rower +from rowers.models import Workout,Rower,StrokeData import datetime @@ -93,8 +93,8 @@ class WorkoutSerializer(serializers.ModelSerializer): class StrokeDataSerializer(serializers.Serializer): workoutid = serializers.IntegerField strokedata = serializers.JSONField - - def create(self, validated_data): + + def create(self, workoutid, strokedata): """ Create and enter a new set of stroke data into the DB """ @@ -103,3 +103,5 @@ class StrokeDataSerializer(serializers.Serializer): print "fake serializer" return 1 + + diff --git a/rowers/templates/about_us.html b/rowers/templates/about_us.html index 34c64464..e562c356 100644 --- a/rowers/templates/about_us.html +++ b/rowers/templates/about_us.html @@ -142,6 +142,7 @@ You will be taken to the secure PayPal payment site.
On this page, a work in progress, I will collect useful information + for developers of rowing data apps and hardware.
+ +I presume you have an app (smartphone app, dedicated hardware, web site) + where your users (customers) generate, collect or store their rowing + related workout data. You can now offer your users easy ways to get + their data on this site.
+ +There are three ways to allow your users to get data to Rowsandall.com.
+ +Enable export of TCX, FIT or CSV formatted files from your app. + The users + upload the file to Rowsandall.com.
+ +Similar as above, generate TCX, FIT or CSV formatted files and + email them + to workouts@rowsandall.com directly from your app. The From: field + should be the email address of the registered user.
+ +We are building a REST API which will allow you to post and + receive stroke + data from the site directly.
+ +The REST API is a work in progress.
+ +All files adhering to the standards TCX and FIT formats will be parsed.
+ +However, some rowing related parameters are not supported by TCX and FIT. Therefore, we are supporting the CSV format that is documented in the following link.
+ + + +Using this standard will guarantee that your user's data are accepted + without complaints.
+ +As a registered user, you can register an app.
+ + +Standard Oauth2 authentication. + Get authorization code by pointing your user to the authorization URL. + Exchange authorization code for an access token. When access token expires, + use the refresh token to refresh it.
+ +Once you have a registered app, you have gone through the authorization + and have successfully obtained an access token, you can use it to place + POST, GET and PUT requests.
+ +The workout summary data and the stroke data are obtained and sent + separately.
+ +You can only post stroke data to an existing workout with + workout number {id}. If the workout already has stroke data, you + will get a duplication error. This functionality will be expanded in the + future to enable updating stroke data. Stroke data for workout {id} are + posted to:
+ +The payload is application/json data and looks as follows:
+ +
+ {
+ "distance": [5,12,19,27,35,43,51,59,67,75,82,90,100],
+ "power": [112,221,511,673,744,754,754,749,729,729,726,709,707],
+ "hr": [132,131,131,132,133,136,139,142,145,147,150,152,153],
+ "pace": [145800,116400,88100,80400,77700,77400,77400,77600,78300,78300,78400,79000,79100],
+ "spm": [11,41,56,59,55,48,48,48,48,48,48,48,49],
+ "time": [0,2200,4599,7000,9599,12000,14400,16799,19400,21799,24200,26599,2900],
+}
+
+
+ Mandatory data fields are:
+Optional data fiels are:
+Consistency checks will be done and the stroke data will be + refused if the mandatory data fields don't pass the checks. + All mandatory data fields + must have the same number of records. If an optional data field + fails a test, its values are silently replaced by zeros.
+ +