Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pydatalab/schemas/cell.json
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,19 @@
"title": "Display Order",
"type": "array"
},
"location": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The place where the item is located.",
"title": "Location"
},
"collections": {
"description": "Inlined info for the collections associated with this item.",
"items": {
Expand Down
26 changes: 13 additions & 13 deletions pydatalab/schemas/equipment.json
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,19 @@
"title": "Display Order",
"type": "array"
},
"location": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The place where the item is located.",
"title": "Location"
},
"collections": {
"description": "Inlined info for the collections associated with this item.",
"items": {
Expand Down Expand Up @@ -1306,19 +1319,6 @@
"description": "The manufacturer of this piece of equipment",
"title": "Manufacturer"
},
"location": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Place where the equipment is located",
"title": "Location"
},
"contact": {
"anyOf": [
{
Expand Down
13 changes: 13 additions & 0 deletions pydatalab/schemas/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,19 @@
"title": "Display Order",
"type": "array"
},
"location": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The place where the item is located.",
"title": "Location"
},
"collections": {
"description": "Inlined info for the collections associated with this item.",
"items": {
Expand Down
62 changes: 31 additions & 31 deletions pydatalab/schemas/startingmaterial.json
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,37 @@
},
"description": "A model for representing an experimental sample, based on the connection\nwith cheminventory.net, which mixes container-level and substance-level\ninformation.",
"properties": {
"blocks_obj": {
"additionalProperties": {
"$ref": "#/$defs/DataBlockResponse"
},
"default": {},
"description": "A mapping from block ID to block data.",
"title": "Blocks Obj",
"type": "object"
},
"display_order": {
"default": [],
"description": "The order in which to display block data in the UI.",
"items": {
"type": "string"
},
"title": "Display Order",
"type": "array"
},
"location": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The place where the container is located.",
"title": "Location"
},
"chemform": {
"anyOf": [
{
Expand Down Expand Up @@ -1313,24 +1344,6 @@
"description": "Free-text details of the procedure applied to synthesise the sample",
"title": "Synthesis Description"
},
"blocks_obj": {
"additionalProperties": {
"$ref": "#/$defs/DataBlockResponse"
},
"default": {},
"description": "A mapping from block ID to block data.",
"title": "Blocks Obj",
"type": "object"
},
"display_order": {
"default": [],
"description": "The order in which to display block data in the UI.",
"items": {
"type": "string"
},
"title": "Display Order",
"type": "array"
},
"collections": {
"description": "Inlined info for the collections associated with this item.",
"items": {
Expand Down Expand Up @@ -1646,19 +1659,6 @@
"description": "Supplier or manufacturer of the chemical.",
"title": "Supplier"
},
"location": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The place where the container is located.",
"title": "Location"
},
"comment": {
"anyOf": [
{
Expand Down
3 changes: 0 additions & 3 deletions pydatalab/src/pydatalab/models/equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class Equipment(Item):
manufacturer: str | None = None
"""The manufacturer of this piece of equipment"""

location: str | None = None
"""Place where the equipment is located"""

contact: str | None = None
"""Contact information for equipment (e.g., email address or phone number)."""

Expand Down
11 changes: 10 additions & 1 deletion pydatalab/src/pydatalab/models/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pydatalab.models.files import File
from pydatalab.models.traits import (
HasBlocks,
HasLocation,
HasOwner,
HasRevisionControl,
IsCollectable,
Expand All @@ -18,7 +19,15 @@
)


class Item(Entry, HasOwner, HasRevisionControl, IsCollectable, HasBlocks, abc.ABC):
class Item(
Entry,
HasOwner,
HasRevisionControl,
IsCollectable,
HasLocation,
HasBlocks,
abc.ABC,
):
"""The generic model for data types that will be exposed with their own named endpoints."""

refcode: Refcode | None = None
Expand Down
4 changes: 2 additions & 2 deletions pydatalab/src/pydatalab/models/starting_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from pydantic import Field

from pydatalab.models.items import Item
from pydatalab.models.traits import HasSubstanceInfo, HasSynthesisInfo
from pydatalab.models.traits import HasLocation, HasSubstanceInfo, HasSynthesisInfo
from pydatalab.models.utils import IsoformatDateTime, StartingMaterialsStatus


class StartingMaterial(Item, HasSynthesisInfo, HasSubstanceInfo):
class StartingMaterial(Item, HasSynthesisInfo, HasSubstanceInfo, HasLocation):
"""A model for representing an experimental sample, based on the connection
with cheminventory.net, which mixes container-level and substance-level
information.
Expand Down
6 changes: 6 additions & 0 deletions pydatalab/src/pydatalab/models/traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"IsCollectable",
"HasSynthesisInfo",
"HasSubstanceInfo",
"HasLocation",
)


Expand Down Expand Up @@ -229,3 +230,8 @@ def add_molar_mass(cls, v, info):
return None

return v


class HasLocation(BaseModel):
location: str | None = Field(alias="Location")
"""The place where the item is located."""
23 changes: 23 additions & 0 deletions pydatalab/src/pydatalab/routes/v0_1/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,3 +1809,26 @@ def get_access_token_info(refcode: str):
), 200
else:
return jsonify({"status": "success", "has_token": False}), 200


@ITEMS.route("/locations", methods=["GET"])
def get_locations_for_items():
items = flask_mongo.db.items.distinct(
"location",
{
"location": {"$ne": None},
**get_default_permissions(user_only=False),
},
)
flat_locations = list(items)
nested_locations = {}
for location_locators in flat_locations:
comprising_locations = location_locators.split(">")
curr_dict = nested_locations
for location in comprising_locations:
location = location.strip()
if location not in curr_dict:
curr_dict[location] = {}
curr_dict = curr_dict[location]

return jsonify({"flat_locations": flat_locations, "nested_locations": nested_locations}), 200
19 changes: 19 additions & 0 deletions pydatalab/tests/server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pydatalab.models import Cell, Collection, Equipment, Sample, StartingMaterial
from pydatalab.models.people import AccountStatus
from pydatalab.mongo import flask_mongo

TEST_DATABASE_NAME = "__datalab-testing__"

Expand Down Expand Up @@ -609,6 +610,24 @@ def _insert_and_cleanup_item_from_model(model):
flask_mongo.db.items.delete_one({"refcode": model.refcode})


@pytest.fixture(scope="function", name="item_creator")
def fixture_item_creator():
ref_codes_to_remove = []

def _insert_item_from_model(model):
from pydatalab.models.utils import generate_unique_refcode
from pydatalab.mongo import flask_mongo

refcode = generate_unique_refcode()
model.refcode = refcode
flask_mongo.db.items.insert_one(model.model_dump(exclude_unset=False))
ref_codes_to_remove.append(refcode)
return model

yield _insert_item_from_model
flask_mongo.db.items.delete_many({"refcode": {"$in": ref_codes_to_remove}})


@pytest.fixture(scope="module", name="insert_default_sample")
def fixture_insert_default_sample(default_sample):
yield from _insert_and_cleanup_item_from_model(default_sample)
Expand Down
Loading
Loading