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

Merge branch 'more-failing-tests' into 'master'

Fix failing tests with POSTs and PUTs

See merge request !6
parents bb9c7258 7aeea66a
No related branches found
No related tags found
1 merge request!6Fix failing tests with POSTs and PUTs
.vscode/
*.py[cod]
*.egg-info/
space_images/
item_images/
dist/
build/
\ No newline at end of file
build/
*.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):
verbose_name_plural = "Item extended info"
unique_together = ('item', 'key')
def __str__(self):
return f"({self.pk}) {self.key}: {self.value} item: {self.item.id}"
class ItemImage(models.Model):
""" An image of a Item. Multiple images can be associated with a Item,
......
......@@ -65,7 +65,7 @@ urlpatterns = [
path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb/constrain/<str:thumb_dimensions>',
csrf_exempt(ThumbnailView().run),
{'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),
name='spot-image-thumb'),
path('v1/spot/<int:spot_id>/image/<int:image_id>/thumb/<str:thumb_dimensions>',
......@@ -76,6 +76,9 @@ urlpatterns = [
path('v1/item/<int:item_id>/image/<int:image_id>',
csrf_exempt(ItemImageView().run),
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>',
csrf_exempt(ItemThumbnailView().run),
{'constrain': True}),
......
......@@ -86,6 +86,9 @@ class ItemStash(object):
def get_instance(self):
return self.instance
def __str__(self):
return str(self.json)
@django.dispatch.receiver(
spot_pre_build,
......@@ -200,9 +203,9 @@ def clean_ei(old_ei_list, new_ei_forms):
found = False
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
if ei_form.fields['value'] == old_ei.value:
if ei_form.cleaned_data['value'] == old_ei.value:
forms_to_remove.append(ei_form)
else:
ei_form.instance = old_ei
......@@ -250,8 +253,15 @@ def _save_items(sender, **kwargs):
ei_forms = item.get_ei_forms()
for item_ei in ei_forms:
# save the new EI
item_ei_model = item_ei.save(commit=False)
# Check if an ItemExtendedInfo with this key and Item already exists,
# 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.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