Skip to content

Commit

Permalink
Fixes #874 : Storing data of responses in ember data (#892)
Browse files Browse the repository at this point in the history
<!-- Add the issue number that is fixed by this PR (In the form Fixes #123) -->
Fixes #874

#### Checklist

- [x] I have read the [Contribution & Best practices Guide](https://blog.fossasia.org/open-source-developer-guide-and-best-practices-at-fossasia) and my PR follows them.
- [x] My branch is up-to-date with the Upstream `development` branch.
- [ ] I have added necessary documentation (if appropriate)

### Preview Link 

- **Replace XXX with your PR no**
- Link to live demo: http://pr-XXX-fossasia-badgeyay.surge.sh  

#### Changes proposed in this pull request:

- Added CSV Upload class according to JSON API
- Storing responses from the backend for badge generation

__Text data Upload__
![image](https://user-images.githubusercontent.com/18033231/40734150-32a8d0ba-6455-11e8-8ae2-df6d8cc13c0b.png)

__CSV Upload__

![image](https://user-images.githubusercontent.com/18033231/40734171-417189a2-6455-11e8-9cc6-80aef1d8b565.png)
  • Loading branch information
yashLadha authored and djmgit committed May 31, 2018
1 parent fc7ac4e commit 8157a2c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
8 changes: 3 additions & 5 deletions api/controllers/fileUploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from api.models.user import User
from api.schemas.file import (
FileSchema,
ManualFileSchema
ManualFileSchema,
CSVUploadSchema
)
from flask import current_app as app
from api.schemas.errors import UserNotFound
Expand Down Expand Up @@ -81,10 +82,7 @@ def fileUpload():

file_upload = File(filename=csvName, filetype='csv', uploader=fetch_user)
file_upload.save_to_db()
return jsonify(
Response(200).generateMessage({
'message': 'CSV Uploaded successfully',
'unique_id': csvName}))
return jsonify(CSVUploadSchema().dump(file_upload).data)


@router.route('/manual_data', methods=['POST'])
Expand Down
19 changes: 19 additions & 0 deletions api/schemas/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,22 @@ class Meta:
include_resource_linkage=True,
type_='User'
)


class CSVUploadSchema(Schema):
class Meta:
type_ = 'csv-file'
self_view = 'fileUploader.fileUpload'
kwargs = {'id': '<id>'}

id = fields.Str(required=True, dump_only=True)
filename = fields.Str(required=True)
filetype = fields.Str(required=True)
user_id = fields.Relationship(
self_url='/api/upload/manual_data',
self_url_kwargs={'file_id': '<id>'},
related_url='/user/register',
related_url_kwargs={'id': '<id>'},
include_resource_linkage=True,
type_='User'
)
3 changes: 1 addition & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
}
},
"addons": [
"heroku-postgresql",
{
"plan": "hobby-dev"
"plan": "heroku-postgresql"
}
]
}
2 changes: 1 addition & 1 deletion frontend/app/controllers/create-badges.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default Controller.extend({
let csv_ = this.get('store').createRecord('csv-file', {
uid,
csvFile : csvData,
extension : '.csv'
extension : 'csv'
});
csv_.save()
.catch(err => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/models/csv-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const { Model, attr } = DS;
export default Model.extend({
uid : attr('string'),
csvFile : attr('string'),
extension : attr('string')
extension : attr('string'),
filename : attr('string')
});
3 changes: 2 additions & 1 deletion frontend/app/models/cust-img-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const { Model, attr } = DS;
export default Model.extend({
uid : attr('string'),
imageData : attr('string'),
extension : attr('string')
extension : attr('string'),
filename : attr('string')
});
3 changes: 2 additions & 1 deletion frontend/app/models/text-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const { Model, attr } = DS;
export default Model.extend({
uid : attr('string'),
manual_data : attr('string'),
time : attr('date')
time : attr('date'),
filename : attr('string')
});

0 comments on commit 8157a2c

Please sign in to comment.