Skip to content

Commit

Permalink
cleanup create_obj function
Browse files Browse the repository at this point in the history
  • Loading branch information
acwhite211 committed Dec 20, 2024
1 parent 2254274 commit 2c647bb
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions specifyweb/specify/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,7 @@ def create_obj(collection, agent, model, data: Dict[str, Any], parent_obj=None):
model = get_model_or_404(model)
data = cleanData(model, data, agent)
obj = model()
if (
obj._meta.model_name == "collectionobjectgroupjoin"
and parent_obj._meta.model_name == "collectionobject"
and data["childco"] == "/api/specify/collectionobject/"
):
parent_obj.save() # temporary fix for saving co cojo.childco
data['childco'] = f"{data['childco']}{parent_obj.id}/"
_handle_special_create_priors(obj, data, parent_obj)
handle_fk_fields(collection, agent, obj, data)
set_fields_from_data(obj, data)
set_field_if_exists(obj, 'createdbyagent', agent)
Expand Down Expand Up @@ -1091,4 +1085,15 @@ def _handle_special_save_priors(obj):

def _handle_special_update_priors(obj, data):
data = modify_update_of_interaction_sibling_preps(obj, data)
pass

def _save_parent_co_prior(obj, data, parent_obj):
if (
obj._meta.model_name == "collectionobjectgroupjoin"
and parent_obj._meta.model_name == "collectionobject"
and data["childco"] == "/api/specify/collectionobject/"
):
parent_obj.save() # temporary fix for saving co cojo.childco
data['childco'] = f"{data['childco']}{parent_obj.id}/"

def _handle_special_create_priors(obj, data, parent_obj):
_save_parent_co_prior(obj, data, parent_obj)

0 comments on commit 2c647bb

Please sign in to comment.