Closed dragon-fire-fly closed 1 year ago
There is only one form for messages regardless of whether they are new or edited (the edited form is creating by passing the instance=message
argument when the MessageForm
class is instantiated).
The original form save method did not distinguish between new and edited messages when adding the edited
property.
def save(self, commit=True):
message = super(MessageForm, self).save(commit=False)
message.edited = True
if commit:
message.save()
return message
To resolve this, a msgtype
argument was added to the save
method, then either "new" or "edit" were passed as arguments for new and edited messages respectively.
The new code has this argument added and an if statement check as so:
def save(self, msgtype, commit=True):
message = super(MessageForm, self).save(commit=False)
if msgtype == "edit":
message.edited = True
if commit:
message.save()
return message
And the add message view and edit message view pass this argument as so: add message:
if new_msg.is_valid():
new_msg = new_msg.save("new", commit=False)
new_msg.user_sender_id = request.POST["sender"]
new_msg.user_receiver_id = request.POST["receiver"]
new_msg.save("new")
messages.success(request, "Message sent!")
edit message:
if form.is_valid():
form.save("edit")
messages.success(request, "Message successfully updated.")
Describe the bug The
edited
property is being added to new messages as well as edited ones. The "edited" checkbox in the message model is being checked whenever a new message is created, but it should only get checked when the message is edited for the first time.To Reproduce Steps to reproduce the behavior:
Expected behavior New messages should not have the "edited" checkbox ticked. This should only be ticked once the message has passed through the "edit" view.
Screenshots
Desktop (please complete the following information):