ellmetha / django-machina

A Django forum engine for building powerful community driven websites.
https://django-machina.readthedocs.org
BSD 3-Clause "New" or "Revised" License
593 stars 126 forks source link

Soft delete for disapproved posts. #246

Open snehlata08 opened 3 years ago

snehlata08 commented 3 years ago

Currently the posts/topics which are disapproved gets deleted straight away from the database. I request a feature where the posts are not deleted for certain days(for eg. 15 days) so that they can be reviewed and re-posted. @ellmetha

rg2609 commented 3 years ago
rg2609 commented 3 years ago

@ellmetha, Most required feature, we also want this feature to be added

BoPeng commented 2 years ago

I have implemented this, but for a private project. Essentially, what we did was

  1. Overriding the field approved to a tri-status field

    approved = models.BooleanField(
        null=True, default=None, db_index=True, verbose_name='Approved')

    by extending Topic and Post.

  2. Change the model and view querysets by adding the logics such as exclude(approved=False)and

        if self.request.user.is_authenticated and not self.request.user.is_staff:
            cond = Q(approved=False) & ~Q(poster=self.request.user)
        else:
            cond = Q(approved=False)
        return Post.objects.exclude(cond)

    so that the deleted posts will still be seen by their own authors.

  3. Then we changed the delete logic to something like

    def delete(self, *args, **kwargs):
    if self.approved is False:
        super().delete(*args, **kwargs)
    else:
        self.approved = False
        self.save(update_fields=['approved'])
  4. In the templates, the approved=None, approved=True, and approved=False posts are displayed differently. Right now we make all None and True posts public, and False only visible to their posters.

I am sure that I am allowed to make the relevant changes public but I am not sure if @ellmetha welcome such a PR. I can image a flag is needed (TRI_STATE_APPROVAL_STATUS?) to keep backward compatibility.