Skip to content

Commit

Permalink
Fixes bugs in adding annotations to segmentations
Browse files Browse the repository at this point in the history
  • Loading branch information
manrajgrover committed Jul 17, 2020
1 parent 2b76402 commit 8ea3842
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 173 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ dmypy.json
*.db

# vscode settings
.vscode/*.json
**/.vscode/*.json

# Sample files
!*.sample.json
Expand Down
7 changes: 7 additions & 0 deletions backend/.vscode/settings.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.venvPath": "~/.envs",
"python.pythonPath": "",
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"python.linting.enabled": true
}
15 changes: 2 additions & 13 deletions backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_redis import FlaskRedis
from werkzeug.exceptions import HTTPException, default_exceptions

from backend.config import Config


def create_app(test_config=None):
def create_app():
app = Flask(__name__, instance_relative_config=True)

app.config.from_object(Config)
app.logger.info(app.config["UPLOAD_FOLDER"])

Path(app.config["UPLOAD_FOLDER"]).mkdir(parents=True, exist_ok=True)

return app
Expand All @@ -31,16 +30,6 @@ def create_app(test_config=None):

from backend import models


def handle_error(error):
if isinstance(error, HTTPException):
return jsonify(message=error.description, code=error.code), error.code
return jsonify(message="An error occured", code=500), 500


for exc in default_exceptions:
app.register_error_handler(exc, handle_error)

from .routes import auth, api

app.register_blueprint(auth)
Expand Down
25 changes: 25 additions & 0 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from flask import jsonify
from werkzeug.exceptions import HTTPException, default_exceptions

from backend import app, db


Expand All @@ -11,3 +14,25 @@ def teardown_request(exception):
if exception:
db.session.rollback()
db.session.remove()


@app.errorhandler(Exception)
def handle_invalid_usage(error):
app.logger.error(error)
return jsonify(message="An error occured", code=500), 500


def handle_error(error):
if isinstance(error, HTTPException):

if error.code == 500:
app.logger.error(error)
else:
app.logger.info(error)

return jsonify(message=error.description, code=error.code), error.code
return jsonify(message="An error occured", code=500), 500


for exc in default_exceptions:
app.register_error_handler(exc, handle_error)
8 changes: 4 additions & 4 deletions backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class Data(db.Model):
def update_marked_review(self, marked_review):
self.is_marked_for_review = marked_review

def set_segmentations(self, segmentations):
self.segmentations = segmentations

def to_dict(self):
return {
"original_filename": self.original_filename,
Expand Down Expand Up @@ -278,10 +281,7 @@ class Segmentation(db.Model):
)

values = db.relationship(
"LabelValue",
secondary=annotation_table,
back_populates="segmentations",
single_parent=True,
"LabelValue", secondary=annotation_table, back_populates="segmentations",
)

def set_start_time(self, start_time):
Expand Down
Loading

0 comments on commit 8ea3842

Please sign in to comment.