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

`allow_outgoing_webmentions` field does not display on custom forms #47

Closed campegg closed 1 year ago

campegg commented 1 year ago

I am using custom forms on my site, but after upgrading from v3.1.0 to v4.0.0, the allow_outgoing_webmentions checkbox does not display. The form views look like this:

class AdminNoteCreate(LoginRequiredMixin, CreateView):
    model = Note
    template_name = "note.html"
    fields = [
        "text",
        "in_reply_to",
        "create_date",
        "rss_only",
        "allow_outgoing_webmentions",
    ]

And the template looks like this:

<h4>Note Meta</h4>
<div>
    {{ form.allow_outgoing_webmentions }}
    <label for="{{ form.allow_outgoing_webmentions.id_for_label }}">Send webmentions</label>
</div>
<div>
    {{ form.rss_only }}
    <label for="{{ form.rss_only.id_for_label }}">RSS only</label>
</div>

This is what I see:

allow_outgoing_webmentions
beatonma commented 1 year ago

I'm afraid I haven't been able to reproduce this yet - this renders fine for me.

4.0.0 changed the default value of allow_outgoing_webmentions to make it configurable - can you confirm that you ran makemigrations and migrate after upgrading? I've just tried doing this and it rendered fine with or without running migrations but it's the only relevant thing I can think of that changed.

Can you view source in your browser and confirm that the checkbox isn't somehow hidden by css?

I'm all out of ideas after that but I'd at least like to cross those off the list.

Thanks!

campegg commented 1 year ago

Thanks for taking a look! I have run makemigrations and migrate. This is what I see when I view source; the checkbox is definitely not there:

wm_view_source

Since it was the only other change I made, I also tried setting the value of WEBMENTIONS_ALLOW_OUTGOING_DEFAULT in my settings file to both True and False, as well as removing it completely, but that didn't have any effect (not that I really expected it to).

beatonma commented 1 year ago

Good to rule those out, thanks. I'll dig around some more...

beatonma commented 1 year ago

The only way I've found for the checkbox not to render is if the field is misspelled in the template (e.g. {{ form.misspelled__allow_outgoing_webmentions }}).

That doesn't appear to be the case for you, and I don't see why it would have been affected by the update, but can you please try adding {{ form }} to your template to see what that renders?

campegg commented 1 year ago

That works! (At least, the checkbox renders.)

django-wm-test-form

Edit: there seems to be an additional hidden field in there (initial-allow_outgoing_webmentions) that I've not seen before; guessing that's from setting WEBMENTIONS_ALLOW_OUTGOING_DEFAULT?

campegg commented 1 year ago

OK, so I deleted the local dev version of my site, set up a new virtual environment, re-cloned my site repo and tried again. And guess what? It worked. So I did the same on my live site and it worked there, too. I'm guessing it was a problem on my part, not an issue with the package. Sorry for the runaround!

beatonma commented 1 year ago

Weird! No problem, glad you got it sorted out.

Aside/TIL: The hidden initial- field is used to check whether a field has changed when submitting a form - it's a core Django thing.