beatonma / django-wm

Automatic Webmention functionality for Django models
https://beatonma.org/webmentions_tester/
GNU General Public License v3.0
12 stars 2 forks source link

How to only send webmentions from "live" objects? #30

Closed philgyford closed 1 year ago

philgyford commented 2 years ago

I've added MentionableMixin to a Post model, that has statuses of "Draft" and "Published", and I'm trying to work out how I can ensure that webmentions are only sent when a Post object's saved and it's in "Published" state. At the moment, overriding the save() method, I can't figure out a way to do it.

My initial thought is to give MentionableMixin a get_allow_outgoing_webmentions() method that, by default, just returns the value of allow_outgoing_webmentions. Child classes could override this with something like:

    def get_allow_outgoing_webmentions(self):
        if self.allow_outgoing_webmentions and self.status == LIVE:
            return True
        else:
            return False

Then the existing MentionableMixin.save() method could check that instead of allow_outgoing_webmentions before handling them.

I guess add a matching get_allow_incoming_webmentions() method for completeness too.