Skip to content

Commit

Permalink
Fix creating new taxonomy items failing
Browse files Browse the repository at this point in the history
Fix UI sending additional "specifications" attribute with taxonomy item requests.
Fix API not ignoring specifications in taxonomy item requests.
  • Loading branch information
buehlefs committed Feb 19, 2024
1 parent a3e22e0 commit 6342dde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
18 changes: 14 additions & 4 deletions muse_for_music/api/taxonomies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def post(self, taxonomy: str):
tax = get_taxonomy('list', taxonomy)
if tax is None:
abort(404, 'Taxonomy "{}" not found.'.format(taxonomy))
item = create_taxonomy_item(tax, request.get_json())
item_data = request.get_json()
item_data.pop("specifications", None)
item = create_taxonomy_item(tax, item_data)
db.session.add(item)
db.session.commit()
return marshal(item, taxonomy_item_get)
Expand Down Expand Up @@ -112,6 +114,7 @@ def create_taxonomy_item(tax: Type[T], new_values) -> T:
Returns:
T -- The created Taxonomy Item.
"""
new_values.pop("specifications", None) # TODO remove
item = tax(**new_values)
db.session.add(item)
return item
Expand Down Expand Up @@ -175,7 +178,9 @@ def put(self, taxonomy_type: str, taxonomy: str, item_id: int):
if tax is None:
abort(404, 'Taxonomy "{}" not found.'.format(taxonomy))
item = get_taxonomy_item(tax, item_id)
edit_taxonomy_item(item, request.get_json())
item_data = request.get_json()
item_data.pop("specifications", None)
edit_taxonomy_item(item, item_data)
return marshal(item, taxonomy_item_get)

@ns.response(400, 'Mismatching taxonomy type.')
Expand Down Expand Up @@ -216,7 +221,9 @@ def put(self, taxonomy: str, item_id: int):
if tax is None:
abort(404, 'Taxonomy "{}" not found.'.format(taxonomy))
item = get_taxonomy_item(tax, item_id)
edit_taxonomy_item(item, request.get_json())
item_data = request.get_json()
item_data.pop("specifications", None)
edit_taxonomy_item(item, item_data)
return marshal(item, taxonomy_item_get)

@ns.response(400, 'Mismatching taxonomy type.')
Expand Down Expand Up @@ -255,6 +262,7 @@ def post(self, taxonomy: str, item_id: int):
if tax is None:
abort(404, 'Taxonomy "{}" not found.'.format(taxonomy))
new_item = request.get_json()
new_item.pop("specifications", None)
if new_item['name'] == 'root':
abort(400, 'Name "root" is forbidden!')
new_item['parent'] = get_taxonomy_item(tax, item_id)
Expand All @@ -273,7 +281,9 @@ def put(self, taxonomy: str, item_id: int):
if tax is None:
abort(404, 'Taxonomy "{}" not found.'.format(taxonomy))
item = get_taxonomy_item(tax, item_id)
edit_taxonomy_item(item, request.get_json())
item_data = request.get_json()
item_data.pop("specifications", None)
edit_taxonomy_item(item, item_data)
return marshal(item, taxonomy_tree_item_get)

@ns.response(400, 'Mismatching taxonomy type.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ <h1 class="mv0" title>Neuer Eintrag:</h1>
<span>Kind von:</span>
<span>{{selectedParent?.name}}</span>
</div>
<dynamic-form [objectModel]="'TaxonomyItemPOST'" [startValues]="{}" (valid)="onValidChange($event)" (data)="onDataChange($event)" #form></dynamic-form>
<dynamic-form [objectModel]="'TaxonomyItemPOST'" [startValues]="{}" (valid)="onValidChange($event)" (data)="onDataChange($event)" [useSpecifications]="false" #form></dynamic-form>
</div>
</m4m-dialog>

<m4m-dialog [closable]="true" [dialogType]="'save-cancel'" [icon]="'save'" [okCallback]="editItem" #editItemDialog>
<h1 class="mv0" title>Eintrag bearbeiten:</h1>
<div class="w-100 ph3 pv2" body>
<dynamic-form [objectModel]="'TaxonomyItemPUT'" [startValues]="selectedItem" (valid)="onValidChange($event)" (data)="onDataChange($event)" #form></dynamic-form>
<dynamic-form [objectModel]="'TaxonomyItemPUT'" [startValues]="selectedItem" (valid)="onValidChange($event)" (data)="onDataChange($event)" [useSpecifications]="false" #form></dynamic-form>
</div>
</m4m-dialog>

<m4m-dialog [closable]="true" [dialogType]="'save-cancel'" [icon]="'save'" [okCallback]="editNaItem" #editNaItemDialog>
<h1 class="mv0" title>"Nicht Anwendbar" bearbeiten:</h1>
<div class="w-100 ph3 pv2" body>
<p>Bitte nur die Beschreibung anpassen!</p>
<dynamic-form [objectModel]="'TaxonomyItemPUT'" [startValues]="na" (valid)="onValidChange($event)" (data)="onDataChange($event)" #form></dynamic-form>
<dynamic-form [objectModel]="'TaxonomyItemPUT'" [startValues]="na" (valid)="onValidChange($event)" (data)="onDataChange($event)" [useSpecifications]="false" #form></dynamic-form>
</div>
</m4m-dialog>

Expand Down

0 comments on commit 6342dde

Please sign in to comment.