From a1ee575406ecfaa2a17defd58dc14a8961021136 Mon Sep 17 00:00:00 2001 From: Anna Grund Date: Wed, 27 Sep 2023 22:05:06 +0300 Subject: [PATCH] [AJP-2] --- .gitignore | 2 +- ajapaik/ajapaik/forms.py | 8 +- ajapaik/ajapaik/models.py | 21 --- .../js/ajp-picture-category-retrival.js | 114 ++++-------- .../photo/_photo_comments_and_labels.html | 163 +++++++++++++----- .../object_categorization_service.py | 97 +---------- 6 files changed, 156 insertions(+), 249 deletions(-) diff --git a/.gitignore b/.gitignore index 9086ac79c..4b2e66f5c 100755 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -#/ajapaik/settings/local.py +/ajapaik/settings/local.py /ajapaik/settings/test.py /media/ diff --git a/ajapaik/ajapaik/forms.py b/ajapaik/ajapaik/forms.py index d23c8e5ac..3ba71e504 100644 --- a/ajapaik/ajapaik/forms.py +++ b/ajapaik/ajapaik/forms.py @@ -315,7 +315,6 @@ class FrontpagePagingForm(forms.Form): class ApiAlbumNearestPhotosForm(forms.Form): - print("HERE") id = forms.ModelChoiceField(queryset=Album.objects.filter(is_public=True), required=False) latitude = forms.FloatField(min_value=-85.05115, max_value=85) longitude = forms.FloatField(min_value=-180, max_value=180) @@ -325,7 +324,6 @@ class ApiAlbumNearestPhotosForm(forms.Form): class ApiFinnaNearestPhotosForm(forms.Form): - print("HERE") id = forms.ModelChoiceField(queryset=Album.objects.filter(is_public=True), required=False) latitude = forms.FloatField(min_value=-85.05115, max_value=85) longitude = forms.FloatField(min_value=-180, max_value=180) @@ -337,7 +335,6 @@ class ApiFinnaNearestPhotosForm(forms.Form): class ApiAlbumStateForm(forms.Form): - print("HERE") id = forms.ModelChoiceField(queryset=Album.objects.filter(is_public=True)) state = forms.CharField(max_length=255, required=False) start = forms.IntegerField(required=False) @@ -345,14 +342,12 @@ class ApiAlbumStateForm(forms.Form): class ApiAlbumSourceForm(forms.Form): - print("HERE") query = forms.CharField(max_length=255, required=True) start = forms.IntegerField(required=False) limit = forms.IntegerField(required=False) class ApiPhotoUploadForm(forms.Form): - print("HERE") id = forms.CharField(max_length=255) latitude = forms.FloatField(min_value=-85.05115, max_value=85, required=False) longitude = forms.FloatField(min_value=-180, max_value=180, required=False) @@ -461,8 +456,6 @@ def clean_images(self): if not images: raise forms.ValidationError(_('At least one image file is required.')) - # Additional validation for image files can be added here if needed. - return images def clean(self): @@ -473,6 +466,7 @@ def clean(self): if not self.cleaned_data.get('uploader_is_author') and not self.cleaned_data.get('licence'): self.errors['licence'] = [_('Missing licence')] + class UserPhotoUploadAddAlbumForm(forms.ModelForm): location = forms.CharField(max_length=255, required=False) diff --git a/ajapaik/ajapaik/models.py b/ajapaik/ajapaik/models.py index 7157b6705..ee17fef87 100644 --- a/ajapaik/ajapaik/models.py +++ b/ajapaik/ajapaik/models.py @@ -2075,27 +2075,6 @@ class PhotoViewpointElevationSuggestion(Suggestion): on_delete=CASCADE) -# TODO: to be deleted -class PhotoModelSuggestionConfirmReject(Suggestion): - INTERIOR, EXTERIOR = range(2) - GROUND_LEVEL, RAISED, AERIAL = range(3) - SCENE_CHOICES = ( - (INTERIOR, _('Interior')), - (EXTERIOR, _('Exterior')) - ) - VIEWPOINT_ELEVATION_CHOICES = ( - (GROUND_LEVEL, _('Ground')), - (RAISED, _('Raised')), - (AERIAL, _('Aerial')) - ) - viewpoint_elevation_to_confirm = PositiveSmallIntegerField(_('Viewpoint elevation'), choices=VIEWPOINT_ELEVATION_CHOICES, blank=True, null=True) - scene_to_confirm = PositiveSmallIntegerField(_('Scene'), choices=SCENE_CHOICES, blank=True, null=True) - - viewpoint_elevation_to_reject = PositiveSmallIntegerField(_('Viewpoint elevation'), choices=VIEWPOINT_ELEVATION_CHOICES, blank=True, null=True) - scene_to_reject = PositiveSmallIntegerField(_('Scene'), choices=SCENE_CHOICES, blank=True, null=True) - - proposer = ForeignKey('Profile', blank=True, null=True, related_name='photo_scene_suggestions_confirmation', on_delete=CASCADE) - class PhotoModelSuggestionResult(Suggestion): INTERIOR, EXTERIOR = range(2) GROUND_LEVEL, RAISED, AERIAL = range(3) diff --git a/ajapaik/ajapaik/static/js/ajp-picture-category-retrival.js b/ajapaik/ajapaik/static/js/ajp-picture-category-retrival.js index c9513583e..1d61f7b04 100644 --- a/ajapaik/ajapaik/static/js/ajp-picture-category-retrival.js +++ b/ajapaik/ajapaik/static/js/ajp-picture-category-retrival.js @@ -1,5 +1,5 @@ -function getPictureCategoryCategories(photoId, callback) { - var onSuccess = function (response) { +function getImageCategory(photoId, callback) { + let onSuccess = function (response) { callback(determinePictureCategory(response.data)); }; getRequest( @@ -11,8 +11,32 @@ function getPictureCategoryCategories(photoId, callback) { ); } +function determinePictureCategory(responseData) { + let responseDict = {}; + for (let i = 0; i < responseData.length; i++) { + let data = responseData[i]; + let fields = data["fields"]; + if ("scene" in fields) { + if (fields["scene"] === 0) { + responseDict["scene"] = "interior"; + } else { + responseDict["scene"] = "exterior"; + } + } + if ("viewpoint_elevation" in fields) { + if (fields["viewpoint_elevation"] === 0) { + responseDict["viewpoint_elevation"] = "ground"; + } else if (fields["viewpoint_elevation"] === 1) { + responseDict["viewpoint_elevation"] = "raised"; + } else if (fields["viewpoint_elevation"] === 2) { + responseDict["viewpoint_elevation"] = "areal"; + } + } + } + return responseDict; +} + function sendCategoryFeedback(photoId, category, categoryValue) { - console.log("Persisting category alternation to db") let payload = { "photo_id": photoId }; @@ -23,7 +47,7 @@ function sendCategoryFeedback(photoId, category, categoryValue) { } else if (categoryValue === "exterior") { payload["scene_to_alternate"] = 1 } - } else if (category === "view-point") { + } else if (category === "view-point-elevation") { if (categoryValue === "ground") { payload["viewpoint_elevation_to_alternate"] = 0 } else if (categoryValue === "raised") { @@ -33,54 +57,7 @@ function sendCategoryFeedback(photoId, category, categoryValue) { } } - var onSuccess = function () { - console.log("It was a success!") - }; - - postRequest( - '/object-categorization/confirm-latest-category', - payload, - constants.translations.queries.POST_CATEGORY_CONFIRMATION_SUCCESS, - constants.translations.queries.POST_CATEGORY_CONFIRMATION_FAILED, - onSuccess - ); -} - -//TODO: to remove -function sendCategoryConfirmation(photoId, category, categoryValue, confirm) { - - - console.log("categoryValue") - console.log(categoryValue) - - var payload = { - "photo_id": photoId - // "viewpoint_elevation_to_confirm": 1, - // "scene_to_confirm": 1, - // "viewpoint_elevation_to_reject": 1, - // "scene_to_reject": 1 - } - - if (category === "scene") { - if (categoryValue === "interior") { - confirm === 1 ? payload["scene_to_confirm"] = 0 : payload["scene_to_reject"] = 0 - } else if (categoryValue === "exterior") { - confirm === 1 ? payload["scene_to_confirm"] = 1 : payload["scene_to_reject"] = 1 - } - } else if (category === "view-point") { - if (categoryValue === "ground") { - confirm === 1 ? payload["viewpoint_elevation_to_confirm"] = 0 : payload["viewpoint_elevation_to_reject"] = 0 - } else if (categoryValue === "raised") { - confirm === 1 ? payload["viewpoint_elevation_to_confirm"] = 1 : payload["viewpoint_elevation_to_reject"] = 1 - } else { - confirm === 1 ? payload["viewpoint_elevation_to_confirm"] = 2 : payload["viewpoint_elevation_to_reject"] = 2 - } - } - - console.log("PALYLOAD") - console.log(payload) - - var onSuccess = function () { + const onSuccess = function () { console.log("It was a success!") }; @@ -91,37 +68,4 @@ function sendCategoryConfirmation(photoId, category, categoryValue, confirm) { constants.translations.queries.POST_CATEGORY_CONFIRMATION_FAILED, onSuccess ); - console.log(photoId); - console.log(category); - console.log(confirm); -} - -function determinePictureCategory(responseData) { - var responseDict = {} - var category; - - for (let i = 0; i < responseData.length; i++) { - var data = responseData[i] - var model = data["model"]; - if (model === "ajapaik.photomodelsuggestionresult") { - category = data["fields"]["scene"] - if (category === 0) { - responseDict["scene"] = "interior"; - } else { - responseDict["scene"] = "exterior"; - } - } - if (model === "ajapaik.photoviewpointelevationsuggestion") { - category = data["fields"]["viewpoint_elevation"] - if (category === 0) { - responseDict["viewpoint_elevation"] = "ground"; - } else if (category === 1) { - responseDict["viewpoint_elevation"] = "raised"; - } else { - responseDict["viewpoint_elevation"] = "areal"; - } - } - - } - return responseDict; } \ No newline at end of file diff --git a/ajapaik/ajapaik/templates/photo/_photo_comments_and_labels.html b/ajapaik/ajapaik/templates/photo/_photo_comments_and_labels.html index 9ad380614..bc96ffaf9 100644 --- a/ajapaik/ajapaik/templates/photo/_photo_comments_and_labels.html +++ b/ajapaik/ajapaik/templates/photo/_photo_comments_and_labels.html @@ -4,32 +4,50 @@
-