|
28 | 28 | def _(): ...
|
29 | 29 |
|
30 | 30 |
|
31 |
| -def reserialize_blocks(display_order: list[str], blocks_obj: dict[str, dict]) -> dict[str, dict]: |
32 |
| - """Create the corresponding Python objects from JSON block data, then |
33 |
| - serialize it again as JSON to populate any missing properties. |
34 |
| -
|
35 |
| - Parameters: |
36 |
| - blocks_obj: A dictionary containing the JSON block data, keyed by block ID. |
37 |
| -
|
38 |
| - Returns: |
39 |
| - A dictionary with the re-serialized block data. |
40 |
| -
|
41 |
| - """ |
42 |
| - for block_id in display_order: |
43 |
| - try: |
44 |
| - block_data = blocks_obj[block_id] |
45 |
| - except KeyError: |
46 |
| - LOGGER.warning(f"block_id {block_id} found in display order but not in blocks_obj") |
47 |
| - continue |
48 |
| - blocktype = block_data["blocktype"] |
49 |
| - blocks_obj[block_id] = ( |
50 |
| - BLOCK_TYPES.get(blocktype, BLOCK_TYPES["notsupported"]).from_db(block_data).to_web() |
51 |
| - ) |
52 |
| - |
53 |
| - return blocks_obj |
54 |
| - |
55 |
| - |
56 |
| -# Seems to be obselete now? |
57 |
| -def dereference_files(file_ids: list[str | ObjectId]) -> dict[str, dict]: |
58 |
| - """For a list of Object IDs (as strings or otherwise), query the files collection |
59 |
| - and return a dictionary of the data stored under each ID. |
60 |
| -
|
61 |
| - Parameters: |
62 |
| - file_ids: The list of IDs of files to return; |
63 |
| -
|
64 |
| - Returns: |
65 |
| - The dereferenced data as a dictionary with (string) ID keys. |
66 |
| -
|
67 |
| - """ |
68 |
| - results = { |
69 |
| - str(f["_id"]): f |
70 |
| - for f in flask_mongo.db.files.find( |
71 |
| - { |
72 |
| - "_id": {"$in": [ObjectId(_id) for _id in file_ids]}, |
73 |
| - } |
74 |
| - ) |
75 |
| - } |
76 |
| - if len(results) != len(file_ids): |
77 |
| - raise RuntimeError( |
78 |
| - "Some file IDs did not have corresponding database entries.\n" |
79 |
| - f"Returned: {list(results.keys())}\n" |
80 |
| - f"Requested: {file_ids}\n" |
81 |
| - ) |
82 |
| - |
83 |
| - return results |
84 |
| - |
85 |
| - |
86 | 31 | @ITEMS.route("/equipment/", methods=["GET"])
|
87 | 32 | def get_equipment_summary():
|
88 | 33 | _project = {
|
@@ -837,12 +782,6 @@ def get_item_data(
|
837 | 782 | ):
|
838 | 783 | """Generates a JSON response for the item with the given `item_id`,
|
839 | 784 | or `refcode` additionally resolving relationships to files and other items.
|
840 |
| -
|
841 |
| - Parameters: |
842 |
| - load_blocks: Whether to regenerate any data blocks associated with this |
843 |
| - sample (i.e., create the Python object corresponding to the block and |
844 |
| - call its render function). |
845 |
| -
|
846 | 785 | """
|
847 | 786 | redirect_to_ui = bool(request.args.get("redirect-to-ui", default=False, type=json.loads))
|
848 | 787 | if refcode and redirect_to_ui and CONFIG.APP_URL:
|
@@ -911,8 +850,6 @@ def get_item_data(
|
911 | 850 | raise KeyError(f"Item {item_id=} has no type field in document.")
|
912 | 851 |
|
913 | 852 | doc = ItemModel(**doc)
|
914 |
| - if load_blocks: |
915 |
| - doc.blocks_obj = reserialize_blocks(doc.display_order, doc.blocks_obj) |
916 | 853 |
|
917 | 854 | # find any documents with relationships that mention this document
|
918 | 855 | relationships_query_results = flask_mongo.db.items.find(
|
|
0 commit comments