-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: schemas #66
WIP: schemas #66
Changes from 9 commits
3bdb6aa
4c6ce36
4c2e92d
5c2dd0f
c684b86
4a498b3
e2ae650
f8f7930
2969e52
e0f26bd
5881956
986d5fa
4dc419c
f7bcfb1
6068349
263441b
d0a0ac7
c026c1b
55d3619
1394df2
61ffe55
9c3c8d6
79b75a9
6222199
4420cb5
b7d3565
1491d88
a990ed9
5df3883
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
from flask import Flask, abort, request, render_template, redirect, url_for | ||
|
||
from regolith.validators import validate | ||
|
||
app = Flask('regolith') | ||
|
||
|
||
|
@@ -59,6 +61,17 @@ def collection_page(dbname, collname): | |
f.write(form['body']) | ||
traceback.print_exc() | ||
raise | ||
tv, errors = validate(dbname, body) | ||
if not tv: | ||
td = tempfile.TemporaryDirectory() | ||
n = os.path.join(td.name, 'regolith.txt') | ||
print(errors) | ||
print('Writing text file to {}. ' | ||
'Please try again.'.format(n)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these prints should go into the body of the error message below. At the very least, they should be printed to stderr.... |
||
with open(n) as f: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file isn't opened in write mode. Do you have any tests for the invalid case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we have any tests for the app. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made an issue #69 |
||
f.write(form['body']) | ||
raise ValueError('Error while validating the record') | ||
|
||
rc.client.update_one(dbname, collname, {'_id': body['_id']}, body) | ||
status = 'saved ✓' | ||
status_id = str(body['_id']) | ||
|
@@ -75,6 +88,16 @@ def collection_page(dbname, collname): | |
f.write(form['body']) | ||
traceback.print_exc() | ||
raise | ||
tv, errors = validate(dbname, body) | ||
if not tv: | ||
td = tempfile.TemporaryDirectory() | ||
n = os.path.join(td.name, 'regolith.txt') | ||
print(errors) | ||
print('Writing text file to {}. ' | ||
'Please try again.'.format(n)) | ||
with open(n) as f: | ||
f.write(form['body']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
raise ValueError('Error while validating the record') | ||
try: | ||
added = rc.client.insert_one(dbname, collname, body) | ||
except Exception: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8 two newlines required after import lines