coderedcms icon indicating copy to clipboard operation
coderedcms copied to clipboard

'str' object has no attribute 'method'

Open jquiroz90 opened this issue 5 years ago • 17 comments

Describe the bug

Form input within 2nd level subpages

Steps to reproduce

-Home page already has form input

  • If a sub page of the site has a form input, nothing happens
  • When a second level sub page (root-page/1st-level-subpage/2nd-level-subpage) has form input, error triggers.

Expected behavior

The form input should be displayed and works flawlessly, not caring about if it's 1st, 2nd or so on... level of subpages.

Additional context

Exception location: page_models.py line 1356 (if request.method == 'POST':)

def get_form(self, request, *args, **kwargs):
        form_class = self.get_form_class()
        form_params = self.get_form_parameters()
        form_params.update(kwargs)
        if request.method == 'POST':
            return form_class(request.POST, request.FILES, *args, **form_params)
        return form_class(*args, **form_params)

jquiroz90 avatar Oct 02 '19 18:10 jquiroz90

I have a page preview block using the form inputs template on the home page that is targeting home/subpage-1/subpage-2. subpage-2 is a Form Page with a text input and a dropdown input. This error is not triggering on coderedcms v.0.16.3. Is there additional context I am missing to replicate the error?

corysutyak avatar Oct 02 '19 19:10 corysutyak

Thanks for the steps to reproduce. Just so I understand clearly...

Home page (Web Page) - contains page preview block of subpage
|- subpage (Form Page) - contains page preview of sub-subpage?
  |- sub-subpage (Form Page)

vsalvino avatar Oct 02 '19 19:10 vsalvino

Home page (Web Page) - contains page preview block of subpage
|- subpage (Web Page) - contains page preview of subpage
|- subpage* (Form Page) - It's hidden
  |- sub-subpage (Article Landing Page) - contains page preview of subpage*

Then home-page and subpage are broken.

jquiroz90 avatar Oct 02 '19 19:10 jquiroz90

So subpage contains a preview of itself? If that is the case then it would definitely break. If subpage contains a preview of subpage* then it should work in theory, although it would likely break if subpage* is unpublished.

vsalvino avatar Oct 02 '19 19:10 vsalvino

No, it doesn't contain a preview of itself, form page is another one. But, yes, it's unpublished.

jquiroz90 avatar Oct 02 '19 19:10 jquiroz90

Try publishing the page. I believe that is the problem.

vsalvino avatar Oct 02 '19 20:10 vsalvino

I published it but the problem still persists

jquiroz90 avatar Oct 02 '19 20:10 jquiroz90

Closing due to inactivity / needs more info to reproduce the problem.

vsalvino avatar Apr 11 '20 19:04 vsalvino

I get the same problem when using form page preview on an article page : 'str' object has no attribute 'method'.

Home page (Web Page) |- subpage (Article Index Page) |- sub-subpage (Article Page) - page preview of form page |- subpage (Form Page)

pascalthivierge avatar Dec 10 '20 20:12 pascalthivierge

I'm using Wagtailtrans, but I doubt it would be the problem.

pascalthivierge avatar Dec 10 '20 20:12 pascalthivierge

I should add that the page preview of a form input on a standard web page works... but not on an article page under article page index.

pascalthivierge avatar Dec 10 '20 21:12 pascalthivierge

Can you confirm that the site name and port under Settings > Site is correctly set? i.e. it should match your domain (www.example.com) and port (80 for http, 443 for https).

vsalvino avatar Dec 10 '20 21:12 vsalvino

yes, the hostname match my domain name and using https with port 443

pascalthivierge avatar Dec 11 '20 13:12 pascalthivierge

I'm having this issues as well.

-Article Index Page --Article with Form Inputs preview (Sign up for our newsletter) The Article shows the inputs and accepts the form properly, I'm thinking it may have something to do with the index page grabbing the body content of the Article for the text preview.

Boomacroom avatar Dec 30 '20 19:12 Boomacroom

yes, the hostname match my domain name and using https with port 443

Using the template tag truncatewords, will give the same error. Commenting out the following fixed the issue for me.

{% if self.show_preview_text %}<p>{{article.specific.body_preview}}</p>{% endif %}

Boomacroom avatar Dec 30 '20 19:12 Boomacroom

Interesting, this must be related to trying to fetch child pages of the page while it is in "preview" state (it is technically not a page object during preview, it is some kind of special ephemeral preview object). This has long been a cryptic issue, thanks for investigating!

A fix might be to add a try/except to body_preview() method, or to add special logic during render() of previews.

vsalvino avatar Jan 05 '21 21:01 vsalvino

Run into a similar error message when running a search:

Start condition: there's a page ("Contact") with page preview block, pointing at a form ("Contact Form") ("Contact" and "Contact Form" are both children of "Home"), everything is published, no draft versions.

  • Case A) Running a search across the site, with a term that does not gives a match for "Home", Page Preview Template: "Form inputs" -> success, no error, other pages are found
  • Case B) Running a search across the site, search term should give a match for "Home", Page Preview Template: "Default" -> no error, other pages plus "Home" are found
  • Case C) Running a search across the site, search term should give a match for "Home", Page Preview Template: "Card" -> no error, other pages plus "Home" are found
  • Case D) Running a search across the site, search term should give a match for "Home", Page Preview Template: "Form inputs" -> 'str' object has no attribute 'method'

Exception Location: /home/user/.local/share/virtualenvs/app-0IWFc-Ol/lib/python3.9/site-packages/coderedcms/models/page_models.py, line 1504, in get_form

Error during template rendering In template /home/user/.local/share/virtualenvs/app-0IWFc-Ol/lib/python3.9/site-packages/coderedcms/templates/coderedcms/blocks/pagepreview_form.html, error at line 6

'str' object has no attribute 'method' 1 {% extends "coderedcms/blocks/base_block.html" %} 2 {% load django_bootstrap5 coderedcms_tags wagtailcore_tags %} 3 {% block block_render %} 4 {% with page=self.page.specific %} 5 {% if page.form_live %} 6 {% get_pageform page request as form %}


Django Version: 4.0.7 Python Version: 3.9.2 Coderedcms : 1.0.1


The "Contact Form" works otherwise for submission as intended from all Page Previews (with "Form inputs") and in itself as well.


Nonetheless, Coderedcms is some awesome work! Truly appreciated!

pbspm01 avatar Sep 30 '22 22:09 pbspm01