Adding ability to autovivify an appropriate attachment point when manually entering a fit

This commit is contained in:
Ian Roddis committed 2026-07-31 08:59:34 -03:00
1 parent 92ca6b2a9f
commit 23d07505bd
3 files changed
+136 -6

No files matched your search

+44 -6
View File
@@ -2268,24 +2268,62 @@ async def create_augmented_part_fit(
request: Request,
augmented_part_id: int,
own_attachment_point_id: int = Form(...),
other_augmented_part_id: str = Form(""),
other_attachment_point_id: str = Form(""),
label: FitLabel = Form(FitLabel.EXACT),
db: AsyncSession = Depends(get_db),
actor: User = Depends(web_require("fits:write")),
):
error = None
if not other_attachment_point_id:
error = "Select the other part's attachment point."
else:
ap_a = await attachment_point_crud.get(db, own_attachment_point_id)
auto_created_ap = None
ap_a = await attachment_point_crud.get(db, own_attachment_point_id)
ap_b = None
if ap_a is None:
error = "Attachment point not found."
elif other_attachment_point_id:
ap_b = await attachment_point_crud.get(db, int(other_attachment_point_id))
if ap_a is None or ap_b is None:
if ap_b is None:
error = "Attachment point not found."
elif ap_a.augmented_part_id == ap_b.augmented_part_id:
elif other_augmented_part_id:
other_part = await augmented_part_crud.get(db, int(other_augmented_part_id))
if other_part is None:
error = "Part not found."
elif await attachment_point_crud.list_for_augmented_part(db, other_part.id):
error = "Select the other part's attachment point."
else:
ap_b = await attachment_point_crud.create(
db,
augmented_part_id=other_part.id,
attachment_point_name_id=ap_a.attachment_point_name_id,
iso_thread_id=ap_a.iso_thread_id,
unc_thread_id=ap_a.unc_thread_id,
clamp_connection_id=ap_a.clamp_connection_id,
static_connection_id=ap_a.static_connection_id,
)
auto_created_ap = ap_b
else:
error = "Select the other part's attachment point."
if error is None and ap_b is not None:
if ap_a.augmented_part_id == ap_b.augmented_part_id:
error = "A part cannot fit itself."
elif await fit_crud.get_by_attachment_points(db, ap_a, ap_b) is not None:
error = "That fit already exists."
else:
if auto_created_ap is not None:
await audit_crud.log(
db,
actor=actor,
action="create",
resource_type="AttachmentPoint",
resource_id=auto_created_ap.id,
description=audit_crud.describe_create(
"AttachmentPoint",
auto_created_ap.id,
f"auto-created on AugmentedPart #{auto_created_ap.augmented_part_id} "
f"to match attachment point {ap_a.id}",
),
)
fit = await fit_crud.create(db, ap_a=ap_a, ap_b=ap_b, label=label)
await audit_crud.log(
db,