diff --git a/.gitignore b/.gitignore index 1443a8e2741d5ca43913df83ff5cc7e81e47ac9f..11f8422ebb484dede25b44fdd050b9dc365bf5fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,21 @@ .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 diff --git a/spotseeker_server/models.py b/spotseeker_server/models.py index ed39fb0835ef237889cf6a2d65baed5ac0e0a03f..cb2e10f54852cd1ab905c5da0ee76c3bab54ec8b 100644 --- a/spotseeker_server/models.py +++ b/spotseeker_server/models.py @@ -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, diff --git a/spotseeker_server/urls.py b/spotseeker_server/urls.py index 1c4ef59955efeda188cff536b340ee26796f98d9..e951d9e69834f950c401aff88187827b00390f8a 100644 --- a/spotseeker_server/urls.py +++ b/spotseeker_server/urls.py @@ -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}), diff --git a/spotseeker_server/views/spot_item.py b/spotseeker_server/views/spot_item.py index c177793d2d4b39459e3417f5652b3737c0007548..02541b6f265922494ccfc60194572cef47abeb6e 100644 --- a/spotseeker_server/views/spot_item.py +++ b/spotseeker_server/views/spot_item.py @@ -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()