Closed dragon-fire-fly closed 1 year ago
This was caused by the incorrect receiver
variable being passed from the EditMessage
view to the edit_message
template.
This was the original code:
class EditMessage(LoginRequiredMixin, TemplateView):
model = Message
template_name = "app_user/edit_message.html"
def get(self, request, *args, **kwargs):
message = get_object_or_404(Message, pk=kwargs["pk"])
if message.user_sender == request.user:
context = {
"msg": message,
"receiver": get_object_or_404(User, pk=message.pk),
"form": MessageForm(instance=message),
}
return render(request, "app_user/edit_message.html", context)
return redirect("app_user:messages")
The "receiver" variable was retrieving the User based on the message pk rather than the user pk
This bug was fixed by determining the correct parameter to access the correct user pk from the message
object.
The correct receiver was then accessed by calling the get_object_or_404()
method below:
receiver = get_object_or_404(User, pk=message.user_receiver_id)
and returning as part of the context variable to the template.
Describe the bug The wrong user is being shown when the "edit message" button is pressed on a selected message. In the example below, the message is to "Admin" but the "edit message" page shows "Casper" and their associated picture.
To Reproduce Steps to reproduce the behavior:
Expected behavior In this case, "Admin's" username and profile picture should have been shown with the message
Screenshots
Desktop (please complete the following information):