Frojd / wagtail-geo-widget

Wagtail-Geo-Widget is the complete map solution for your Wagtail site.
MIT License
138 stars 37 forks source link

address field not rendered #11

Closed kakulukia closed 7 years ago

kakulukia commented 7 years ago

Hi! I was following the readme, but the GeoPanel stops working when i add the address field to its definition. In the admin the address field will not be displayed and changes to the location will not be saved. There is no obvious error i could report - everything look fine apart from the missing input field. Django 1.10.7 and wagtail 1.9.1

marteinn commented 7 years ago

Hi @kakulukia! How does your implementation look like? My first guess is that you do not have a defined address field in your model? Perhaps our geopage example might help?

kakulukia commented 7 years ago

I did use exactly this reference. :/

kakulukia commented 7 years ago

I will try again with a tatally new wagtail project and report back.

marteinn commented 7 years ago

Hi @kakulukia! Ok, awesome. It would of course also help to get your model definition, or at least pieces of it so I can debug :)

kakulukia commented 7 years ago

Hi here is the full model definition (without the address part inside the geo panel to make it kinda work)

class HomePage(AbstractEmailForm):
    template = 'home/home_page.jade'
    body1 = RichTextField(blank=True)

    thank_you_text = RichTextField(blank=True)

    body2 = RichTextField(blank=True)
    address = models.CharField(max_length=250, blank=True, null=True)
    location = models.CharField(max_length=250, blank=True, null=True)

    body3 = RichTextField(blank=True)

    content_panels = AbstractEmailForm.content_panels + [
        # FormSubmissionsPanel(),
        FieldPanel('body1', classname="full"),
        InlinePanel('form_fields', label="Form fields"),
        FieldPanel('thank_you_text', classname="full"),
        MultiFieldPanel([
            FieldRowPanel([
                FieldPanel('from_address', classname="col6"),
                FieldPanel('to_address', classname="col6"),
            ]),
            FieldPanel('subject'),
        ], "Email"),
        FieldPanel('body2', classname="full"),
        GeoPanel('location'),
        FieldPanel('body3', classname="full"),
    ]

    @cached_property
    def point(self):
        return geosgeometry_str_to_struct(self.location)

    @property
    def lat(self):
        return self.point['y']

    @property
    def lng(self):
        return self.point['x']

    def get_context(self, request, *args, **kwargs):
        context = super().get_context(request, *args, **kwargs)
        context['GOOGLE_MAPS_V3_APIKEY'] = settings.GOOGLE_MAPS_V3_APIKEY
        return context
marteinn commented 7 years ago

@kakulukia Thanks! I think that AbstractEmailForm might be the thing causing issues, but it extends Page and should work. I will look into building a test case using the code you have provided, but need two-three days to get back to you.

kakulukia commented 7 years ago

Take your time! Here ist my test with a totally blank version of wagtail and your widget: https://www.dropbox.com/s/uofy58vm4t1ldf4/geotest.zip?dl=0

Same result as in my other project. :(

marteinn commented 7 years ago

@kakulukia I took a quick look at the sample you provided and noticed that GOOGLE_MAPS_V3_APIKEY was not defined anywhere?

kakulukia commented 7 years ago

i removed that because of sensitive data .. but the existence of the key doesnt make a difference to the rendering of the address field inside the wagtail admin

marteinn commented 7 years ago

@kakulukia Gotcha, it is usually a easy fix :) In that case I will proceed with testing using your app.

marteinn commented 7 years ago

@kakulukia I looked through your code sample and the reason why the address field was not showing is because it was not defined as a field panel (next to the GeoPanel).

This should work for you:

from __future__ import absolute_import, unicode_literals

from django.db import models

from wagtail.wagtailcore.models import Page
from wagtail.wagtailadmin.edit_handlers import (
    FieldPanel,
)
from wagtailgeowidget.edit_handlers import GeoPanel

class HomePage(Page):
    address = models.CharField(max_length=250, blank=True, null=True)
    location = models.CharField(max_length=250, blank=True, null=True)

    content_panels = Page.content_panels + [
        FieldPanel('address'),
        GeoPanel('location', address_field='address'),
    ]

I took a quick look at the readme and noticed that the samples not not include this, so I will fix this at once. I will also look into raising a js alert/console.log error for those cases when a address field cannot be find.

kakulukia commented 7 years ago

haha .. like i said i did follow the docs exactly :D But this way the widget looks kinda separated and not like in this screenshot: https://raw.githubusercontent.com/frojd/wagtail-geo-widget/develop/img/screen1.png

But it works, thx

marteinn commented 7 years ago

@kakulukia To get the same appearance as the screenshot you can wrap your fields inside a MultiFieldPanel, like this:

from wagtail.wagtailadmin.edit_handlers import (
    FieldPanel,
    StreamFieldPanel,
    InlinePanel,
    MultiFieldPanel,
)
from wagtailgeowidget.edit_handlers import GeoPanel

content_panels = Page.content_panels + [
    MultiFieldPanel([
            FieldPanel('address'),
            GeoPanel('location', address_field='address'),
        ], _('Geo details')),
]
kakulukia commented 7 years ago

Nince! Please also put that into the docs! I know its actually wagtail stuff, but it makes your plugin much nicer to use :)

marteinn commented 7 years ago

@kakulukia Good feedback - will do :)