Skip to content
Snippets Groups Projects
Commit 7aeea66a authored by Andy Summers's avatar Andy Summers
Browse files

Fix failing tests with POSTs and PUTs

parent bb9c7258
No related branches found
No related tags found
1 merge request!6Fix failing tests with POSTs and PUTs
.vscode/ .vscode/
*.py[cod] *.py[cod]
*.egg-info/ *.egg-info/
space_images/
item_images/
dist/ dist/
build/ build/
\ No newline at end of file *.gif
*.jpg
*.png
*.bmp
spotseeker_server/test/resources/**/image*
spotseeker_server/test/resources/space_images
spotseeker_server/test/resources/item_images
!fake_jpeg.jpg
!test_bmp.bmp
!test_bmp2.bmp
!test_gif.gif
!test_gif2.gif
!test_jpeg.jpg
!test_jpep2.jpg
!test_png.png
!test_png2.png
...@@ -504,6 +504,9 @@ class ItemExtendedInfo(models.Model): ...@@ -504,6 +504,9 @@ class ItemExtendedInfo(models.Model):
verbose_name_plural = "Item extended info" verbose_name_plural = "Item extended info"
unique_together = ('item', 'key') unique_together = ('item', 'key')
def __str__(self):
return f"({self.pk}) {self.key}: {self.value} item: {self.item.id}"
class ItemImage(models.Model): class ItemImage(models.Model):
""" An image of a Item. Multiple images can be associated with a Item, """ An image of a Item. Multiple images can be associated with a Item,
......
...@@ -65,7 +65,7 @@ urlpatterns = [ ...@@ -65,7 +65,7 @@ urlpatterns = [
path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb/constrain/<str:thumb_dimensions>', path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb/constrain/<str:thumb_dimensions>',
csrf_exempt(ThumbnailView().run), csrf_exempt(ThumbnailView().run),
{'constrain': True}), {'constrain': True}),
path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb/', path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb',
csrf_exempt(ThumbnailView().run), csrf_exempt(ThumbnailView().run),
name='spot-image-thumb'), name='spot-image-thumb'),
path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb/<str:thumb_dimensions>', path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb/<str:thumb_dimensions>',
...@@ -76,6 +76,9 @@ urlpatterns = [ ...@@ -76,6 +76,9 @@ urlpatterns = [
path('v1/item/<int:item_id>/image/<int:image_id>', path('v1/item/<int:item_id>/image/<int:image_id>',
csrf_exempt(ItemImageView().run), csrf_exempt(ItemImageView().run),
name='item-image'), name='item-image'),
path('v1/item/<int:item_id>/image/<int:image_id>/thumb',
csrf_exempt(ItemThumbnailView().run),
name='item-image-thumb'),
path('v1/item/<int:item_id>/image/<int:image_id>/thumb/constrain/<str:thumb_dimensions>', path('v1/item/<int:item_id>/image/<int:image_id>/thumb/constrain/<str:thumb_dimensions>',
csrf_exempt(ItemThumbnailView().run), csrf_exempt(ItemThumbnailView().run),
{'constrain': True}), {'constrain': True}),
......
...@@ -86,6 +86,9 @@ class ItemStash(object): ...@@ -86,6 +86,9 @@ class ItemStash(object):
def get_instance(self): def get_instance(self):
return self.instance return self.instance
def __str__(self):
return str(self.json)
@django.dispatch.receiver( @django.dispatch.receiver(
spot_pre_build, spot_pre_build,
...@@ -200,9 +203,9 @@ def clean_ei(old_ei_list, new_ei_forms): ...@@ -200,9 +203,9 @@ def clean_ei(old_ei_list, new_ei_forms):
found = False found = False
for ei_form in new_ei_forms: for ei_form in new_ei_forms:
if ei_form.fields['key'] == old_ei.key: if ei_form.cleaned_data['key'] == old_ei.key:
found = True found = True
if ei_form.fields['value'] == old_ei.value: if ei_form.cleaned_data['value'] == old_ei.value:
forms_to_remove.append(ei_form) forms_to_remove.append(ei_form)
else: else:
ei_form.instance = old_ei ei_form.instance = old_ei
...@@ -250,8 +253,15 @@ def _save_items(sender, **kwargs): ...@@ -250,8 +253,15 @@ def _save_items(sender, **kwargs):
ei_forms = item.get_ei_forms() ei_forms = item.get_ei_forms()
for item_ei in ei_forms: for item_ei in ei_forms:
# save the new EI # Check if an ItemExtendedInfo with this key and Item already exists,
item_ei_model = item_ei.save(commit=False) # create if it doesn't
item_ei_model, created = ItemExtendedInfo.objects.get_or_create(
key=item_ei.cleaned_data['key'],
item_id=item_model.id,
defaults=item_ei.cleaned_data
)
if not created and item_ei_model.value != item_ei.cleaned_data['value']:
item_ei_model.value = item_ei.cleaned_data['value']
item_ei_model.item = item_model item_ei_model.item = item_model
item_ei_model.save() item_ei_model.save()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment