Skip to content

Commit

Permalink
#154: Move common.models to common.database
Browse files Browse the repository at this point in the history
- The only model in common.models was for the database backend (there's no model for the Python ICAT backend), hence the change
- This commit also includes the changes required to correctly import the file from the new location
- Updated the file tree in the README
  • Loading branch information
MRichards99 committed Oct 20, 2020
1 parent cf83b3f commit 56b7606
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 51 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ This is illustrated below.
│ ├── database
│ │ ├── backend.py
│ │ ├── filters.py
│ │ └── helpers.py
│ │ ├── helpers.py
│ │ └── models.py
│ ├── icat
│ ├── models
│ │ └── db_models.py
│ ├── backends.py
│ ├── constants.py
│ ├── exceptions.py
Expand Down Expand Up @@ -134,7 +133,7 @@ session endpoint.


#### Mapped classes
The classes mapped from the database are stored in `/common/models/db_models.py`. Each model was
The classes mapped from the database are stored in `/common/database/models.py`. Each model was
automatically generated using sqlacodegen. A class `EntityHelper` is defined so that each model may
inherit two methods `to_dict()` and `update_from_dict(dictionary)`, both used for returning entities
and updating them, in a form easily converted to JSON.
Expand Down
2 changes: 1 addition & 1 deletion common/database/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
requires_session_id,
)
from common.helpers import queries_records
from common.models.db_models import SESSION
from common.database.models import SESSION
import uuid
from common.exceptions import AuthenticationError
import datetime
Expand Down
8 changes: 4 additions & 4 deletions common/database/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
IncludeFilter,
)
from common.exceptions import FilterError, MultipleIncludeError
from common.models import db_models
from common.database import models

from sqlalchemy import asc, desc
import logging
Expand Down Expand Up @@ -57,15 +57,15 @@ def apply_filter(self, query):
)

if self.included_included_field:
included_table = getattr(db_models, self.field)
included_included_table = getattr(db_models, self.included_field)
included_table = getattr(models, self.field)
included_included_table = getattr(models, self.included_field)
query.base_query = query.base_query.join(included_table).join(
included_included_table
)
field = getattr(included_included_table, self.included_included_field)

elif self.included_field:
included_table = getattr(db_models, self.field)
included_table = getattr(models, self.field)
query.base_query = query.base_query.join(included_table)
field = getattr(included_table, self.included_field)

Expand Down
4 changes: 1 addition & 3 deletions common/database/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
BadRequestError,
MultipleIncludeError,
)
from common.models import db_models
from common.models.db_models import (
INVESTIGATIONUSER,
from common.database.models import (
INVESTIGATION,
INSTRUMENT,
FACILITYCYCLE,
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion common/icat/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

from common.config import config
from common.exceptions import AuthenticationError
from common.models.db_models import SESSION

log = logging.getLogger()

Expand Down
Empty file removed common/models/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion src/resources/entities/entity_map.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from common.models.db_models import (
from common.database.models import (
APPLICATION,
DATACOLLECTIONDATAFILE,
DATACOLLECTIONPARAMETER,
Expand Down
2 changes: 1 addition & 1 deletion src/resources/non_entities/sessions_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
get_row_by_id,
)
from common.helpers import get_session_id_from_auth_header
from common.models.db_models import SESSION
from common.database.models import SESSION
from common.backends import backend
from common.exceptions import AuthenticationError

Expand Down
2 changes: 1 addition & 1 deletion test/test_entityHelper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
from unittest import TestCase

from common.models.db_models import DATAFILE, DATASET, DATAFILEFORMAT, INVESTIGATION
from common.database.models import DATAFILE, DATASET, DATAFILEFORMAT, INVESTIGATION


class TestEntityHelper(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
get_session_id_from_auth_header,
get_filters_from_query_string,
)
from common.models.db_models import SESSION
from common.database.models import SESSION
from test.test_base import FlaskAppTest


Expand Down
Loading

0 comments on commit 56b7606

Please sign in to comment.