From 6dec025dfabf3654c8b76cd2aa1e639aa496c676 Mon Sep 17 00:00:00 2001 From: Virginia Dooley Date: Thu, 13 Jun 2024 15:35:54 +0100 Subject: [PATCH] Record new version with photo upload --- ynr/apps/moderation_queue/helpers.py | 15 ++++++++++++--- ynr/apps/people/models.py | 4 ++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ynr/apps/moderation_queue/helpers.py b/ynr/apps/moderation_queue/helpers.py index 1aa25efb5c..fd20d4abf9 100644 --- a/ynr/apps/moderation_queue/helpers.py +++ b/ynr/apps/moderation_queue/helpers.py @@ -3,7 +3,7 @@ import requests from candidates.models.db import ActionType, LoggedAction -from candidates.views.version_data import get_client_ip +from candidates.views.version_data import get_change_metadata, get_client_ip from django.http import HttpResponseRedirect from django.shortcuts import render from django.urls import reverse @@ -32,14 +32,23 @@ def image_form_valid_response(request, person, image_form): queued_image = image_form.save(commit=False) queued_image.user = request.user queued_image.save() - # Record that action: + # TODO: Record this action and update the person versions. + # this needs a separate path than the usual record_version + change_metadata = get_change_metadata( + request, information_source=image_form.cleaned_data["why_allowed"] + ) + change_metadata.update({"photo-upload": True}) + + person.record_version(change_metadata) + person.save() + LoggedAction.objects.create( user=request.user, action_type=ActionType.PHOTO_UPLOAD, ip_address=get_client_ip(request), popit_person_new_version="", person=person, - source=image_form.cleaned_data["justification_for_use"], + source=image_form.cleaned_data["why_allowed"], ) return HttpResponseRedirect( reverse("photo-upload-success", kwargs={"person_id": person.id}) diff --git a/ynr/apps/people/models.py b/ynr/apps/people/models.py index 9eb3eadb3e..885a82eb50 100644 --- a/ynr/apps/people/models.py +++ b/ynr/apps/people/models.py @@ -409,6 +409,10 @@ def record_version(self, change_metadata, new_person=False): # Always create a version if this is a merge should_insert = True + if new_version["information_source"] == "profile-photo": + # Always create a version if this is a photo upload + should_insert = True + if should_insert: versions.insert(0, new_version)