pearmut 0.2.9__py3-none-any.whl → 0.2.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pearmut/app.py CHANGED
@@ -291,7 +291,11 @@ async def _download_annotations(
291
291
  with open(output_path, "r") as f:
292
292
  output[campaign_id] = [json.loads(x) for x in f.readlines()]
293
293
 
294
- return JSONResponse(content=output, status_code=200)
294
+ return JSONResponse(
295
+ content=output,
296
+ status_code=200,
297
+ headers={"Content-Disposition": 'inline; filename="annotations.json"'}
298
+ )
295
299
 
296
300
 
297
301
  @app.get("/download-progress")
@@ -315,7 +319,11 @@ async def _download_progress(
315
319
 
316
320
  output[cid] = progress_data[cid]
317
321
 
318
- return JSONResponse(content=output, status_code=200)
322
+ return JSONResponse(
323
+ content=output,
324
+ status_code=200,
325
+ headers={"Content-Disposition": 'inline; filename="progress.json"'}
326
+ )
319
327
 
320
328
 
321
329
  static_dir = f"{os.path.dirname(os.path.abspath(__file__))}/static/"
@@ -324,6 +332,16 @@ if not os.path.exists(static_dir + "index.html"):
324
332
  "Static directory not found. Please build the frontend first."
325
333
  )
326
334
 
335
+ # Mount user assets from data/assets/
336
+ assets_dir = f"{ROOT}/data/assets"
337
+ os.makedirs(assets_dir, exist_ok=True)
338
+
339
+ app.mount(
340
+ "/assets",
341
+ StaticFiles(directory=assets_dir, follow_symlink=True),
342
+ name="assets",
343
+ )
344
+
327
345
  app.mount(
328
346
  "/",
329
347
  StaticFiles(directory=static_dir, html=True, follow_symlink=True),
pearmut/assignment.py CHANGED
@@ -84,9 +84,13 @@ def get_i_item_taskbased(
84
84
 
85
85
  # try to get existing annotations if any
86
86
  items_existing = get_db_log_item(campaign_id, user_id, item_i)
87
+ payload_existing = None
87
88
  if items_existing:
88
89
  # get the latest ones
89
- payload_existing = items_existing[-1]["annotations"]
90
+ latest_item = items_existing[-1]
91
+ payload_existing = {"annotations": latest_item["annotations"]}
92
+ if "comment" in latest_item:
93
+ payload_existing["comment"] = latest_item["comment"]
90
94
 
91
95
  if item_i < 0 or item_i >= len(data_all[campaign_id]["data"][user_id]):
92
96
  return JSONResponse(
@@ -107,7 +111,7 @@ def get_i_item_taskbased(
107
111
  if k.startswith("protocol")
108
112
  },
109
113
  "payload": data_all[campaign_id]["data"][user_id][item_i]
110
- } | ({"payload_existing": payload_existing} if items_existing else {}),
114
+ } | ({"payload_existing": payload_existing} if payload_existing else {}),
111
115
  status_code=200
112
116
  )
113
117
 
@@ -127,9 +131,13 @@ def get_i_item_singlestream(
127
131
  # try to get existing annotations if any
128
132
  # note the None user_id since it is shared
129
133
  items_existing = get_db_log_item(campaign_id, None, item_i)
134
+ payload_existing = None
130
135
  if items_existing:
131
136
  # get the latest ones
132
- payload_existing = items_existing[-1]["annotations"]
137
+ latest_item = items_existing[-1]
138
+ payload_existing = {"annotations": latest_item["annotations"]}
139
+ if "comment" in latest_item:
140
+ payload_existing["comment"] = latest_item["comment"]
133
141
 
134
142
  if item_i < 0 or item_i >= len(data_all[campaign_id]["data"]):
135
143
  return JSONResponse(
@@ -150,7 +158,7 @@ def get_i_item_singlestream(
150
158
  if k.startswith("protocol")
151
159
  },
152
160
  "payload": data_all[campaign_id]["data"][item_i]
153
- } | ({"payload_existing": payload_existing} if items_existing else {}),
161
+ } | ({"payload_existing": payload_existing} if payload_existing else {}),
154
162
  status_code=200
155
163
  )
156
164
 
@@ -173,9 +181,13 @@ def get_next_item_taskbased(
173
181
 
174
182
  # try to get existing annotations if any
175
183
  items_existing = get_db_log_item(campaign_id, user_id, item_i)
184
+ payload_existing = None
176
185
  if items_existing:
177
186
  # get the latest ones
178
- payload_existing = items_existing[-1]["annotations"]
187
+ latest_item = items_existing[-1]
188
+ payload_existing = {"annotations": latest_item["annotations"]}
189
+ if "comment" in latest_item:
190
+ payload_existing["comment"] = latest_item["comment"]
179
191
 
180
192
  return JSONResponse(
181
193
  content={
@@ -190,7 +202,7 @@ def get_next_item_taskbased(
190
202
  if k.startswith("protocol")
191
203
  },
192
204
  "payload": data_all[campaign_id]["data"][user_id][item_i]
193
- } | ({"payload_existing": payload_existing} if items_existing else {}),
205
+ } | ({"payload_existing": payload_existing} if payload_existing else {}),
194
206
  status_code=200
195
207
  )
196
208
 
@@ -222,9 +234,13 @@ def get_next_item_singlestream(
222
234
  # try to get existing annotations if any
223
235
  # note the None user_id since it is shared
224
236
  items_existing = get_db_log_item(campaign_id, None, item_i)
237
+ payload_existing = None
225
238
  if items_existing:
226
239
  # get the latest ones
227
- payload_existing = items_existing[-1]["annotations"]
240
+ latest_item = items_existing[-1]
241
+ payload_existing = {"annotations": latest_item["annotations"]}
242
+ if "comment" in latest_item:
243
+ payload_existing["comment"] = latest_item["comment"]
228
244
 
229
245
  return JSONResponse(
230
246
  content={
@@ -239,7 +255,7 @@ def get_next_item_singlestream(
239
255
  if k.startswith("protocol")
240
256
  },
241
257
  "payload": data_all[campaign_id]["data"][item_i]
242
- } | ({"payload_existing": payload_existing} if items_existing else {}),
258
+ } | ({"payload_existing": payload_existing} if payload_existing else {}),
243
259
  status_code=200
244
260
  )
245
261
 
pearmut/cli.py CHANGED
@@ -272,15 +272,10 @@ def _add_single_campaign(data_file, overwrite, server):
272
272
 
273
273
  if not os.path.isdir(assets_real_path):
274
274
  raise ValueError(f"Assets source path '{assets_real_path}' must be an existing directory.")
275
-
276
- if not os.path.isdir(STATIC_DIR):
277
- raise ValueError(
278
- f"Static directory '{STATIC_DIR}' does not exist. "
279
- "Please build the frontend first."
280
- )
281
275
 
282
276
  # Symlink path is based on the destination, stripping the 'assets/' prefix
283
- symlink_path = f"{STATIC_DIR}/{assets_destination}".rstrip("/")
277
+ # User assets are now stored under data/assets/ instead of static/assets/
278
+ symlink_path = f"{ROOT}/data/{assets_destination}".rstrip("/")
284
279
 
285
280
  # Remove existing symlink if present and we are overriding the same campaign
286
281
  if os.path.lexists(symlink_path):
@@ -392,7 +387,7 @@ def main():
392
387
  campaign_data = json.load(f)
393
388
  destination = campaign_data.get("info", {}).get("assets", {}).get("destination")
394
389
  if destination:
395
- symlink_path = f"{STATIC_DIR}/{destination}".rstrip("/")
390
+ symlink_path = f"{ROOT}/data/{destination}".rstrip("/")
396
391
  if os.path.islink(symlink_path):
397
392
  os.remove(symlink_path)
398
393
  print(f"Assets symlink removed: {symlink_path}")