Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media Chooser not Appearing #54

Closed
jpbeltrami opened this issue May 9, 2019 · 12 comments · Fixed by #57
Closed

Media Chooser not Appearing #54

jpbeltrami opened this issue May 9, 2019 · 12 comments · Fixed by #57

Comments

@jpbeltrami
Copy link

When Using the BaseMediaChooserPanel as mentioned in #53 the chooser doesn't open when clicking on the "choose a media item" button in the edit page.

The browser console shows this error:
image

@thibaudcolas
Copy link
Member

Hey @Aesirry, thanks for the report. I imagine you'd have encountered that when trying to upgrade to the latest version, but it might be useful to get this confirmed. Could you provide the following info:

  • Python version: Run python --version.
  • Django version: Look in your requirements.txt, or run pip show django | grep Version.
  • Wagtail version: Hover over the Wagtail bird in the admin, or run pip show wagtail | grep Version:.
  • wagtailmedia version: Look in your requirements.txt, or run pip show wagtailmedia | grep Version.

Additionally, could you provide us with a sample of the code where you use BaseMediaChooserPanel?

@jpbeltrami
Copy link
Author

Hi @thibaudcolas,

  • Python 3.7.2
  • Django 2.2.1
  • Wagtail 2.5.1
  • WagtailMedia 0.3.0

Here is where I use the Base MediaChooserPanel:

class VideoPage(Page):
    author = models.CharField(max_length=255)
    date = models.DateField("Post date")
    body = models.TextField(blank=False)
    media = models.ForeignKey(
        get_media_model_string(),
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )

    content_panels = Page.content_panels + [
        FieldPanel('author'),
        FieldPanel('date'),
        FieldPanel('body'),
        BaseMediaChooserPanel('media')
    ]

I'm using a custom media model by the way. That's where that get_media_model_string() comes from.

@thibaudcolas
Copy link
Member

thibaudcolas commented May 9, 2019

👌 thanks, that will make troubleshooting much easier.

In the meantime you might be able to do what my project does, although I'm not sure of the implications:

from wagtailmedia.widgets import AdminMediaChooser

[...]

content_panels = Page.content_panels + [
    [...]
    FieldPanel('media', widget=AdminMediaChooser),
]

If that's an issue with 0.3.0 I'm sorry it fell through the cracks. Tried my best to review each and every bit of API of wagtailmedia, but I must've missed that one.

@jpbeltrami
Copy link
Author

Hey @thibaudcolas, using AdminMediaChooser still gives the same error.

I guess for now just using FieldPanel should be enough.

Thank you!

@thibaudcolas
Copy link
Member

Ah that's really strange 😕 are you sure this isn't just a caching issue with a CDN / the browser?

I'll try both options and report back.

@jpbeltrami
Copy link
Author

hmm not sure it's a CDN issue since it's on localhost, I'll check the browser

@zerolab
Copy link
Member

zerolab commented May 10, 2019

The fix for #34 (i.e #40) is on the right path

MediaChooserPanel needs to be:

class MediaChooserPanel(BaseChooserPanel):
    object_type_name = 'media'

    def widget_overrides(self):
        return {self.field_name: AdminMediaChooser}

The one thing missing from that PR is a shim or deprecation for BaseMediaChooserPanel for projects that currently use it. Unless we cut a new release with the appropriate upgrade considerations @thibaudcolas

Context: Slack #support reply. Diff for mentioned repo:

master...solarissmoke:wagtail25#diff-7bea8da4a64ce9c5452abd60428fa2c9R8

@thibaudcolas
Copy link
Member

@Aesirry also try to run collectstatic on your local environment to make sure this isn't the issue. We did move lots of JS code around as part of the 0.3.0 compatibility changes.

@jpbeltrami
Copy link
Author

@thibaudcolas I tried creating a brand new site (the previous one had many modifications, including templates). There is another error when I try to use a RichTextField and a media field with the AdminMediaChooser.

image

Again for this site the versions are the same:

  • python 3.7.2
  • django 2.2.1
  • wagtail 2.5.1
  • wagtailmedia 0.3.0

here's the model:

class HomePage(Page):
    author = models.CharField(max_length=255, blank=True, null=True)
    date = models.DateField("Post date", blank=True, null=True)
    body = RichTextField(blank=True, null=True)
    media = models.ForeignKey(
        'wagtailmedia.Media',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )

    content_panels = Page.content_panels + [
        FieldPanel('author'),
        FieldPanel('date'),
        FieldPanel('body'),
        FieldPanel('media', widget=AdminMediaChooser),
    ]

I made another model without a media field and the RichTextField works normally.
here's the code for that:

class RandomPage(Page):
    author = models.CharField(max_length=255, blank=True, null=True)
    date = models.DateField("Post date", blank=True, null=True)
    body = RichTextField(blank=True, null=True)

    content_panels = Page.content_panels + [
        FieldPanel('author'),
        FieldPanel('date'),
        FieldPanel('body')
    ]

I hope this can give you a hint in the right direction 👍

@jpbeltrami
Copy link
Author

jpbeltrami commented May 13, 2019

@thibaudcolas I spoke over slack with the Wagtail support and it turns out that this is actually an issue with wagtail.
image

Also using FieldPanel('media', widget=AdminMediaChooser) works fine now. You might want to change the example in the ReadMe

@thibaudcolas
Copy link
Member

Ah 🙂that's an annoying name clash, but I'm glad we know the solution.

👍 I'll leave this open until we do the docs change similarly to #34 / #40, and also have a note about the potential name clash to avoid.

thibaudcolas added a commit to thibaudcolas/wagtailmedia that referenced this issue May 22, 2019
thibaudcolas added a commit that referenced this issue May 22, 2019
* Clean up README
* Switch StreamField / model field docs sections around
* Document `media` field name clash. Fix #54
@thibaudcolas
Copy link
Member

thibaudcolas commented May 22, 2019

I've updated the docs as part of #57, sorry you ran into this @Aesirry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants