yourcelf / olwidget

Javascript library to replace textareas that contain WKT data with editable OpenLayers maps, and a django app using it for django forms and admin.
Other
91 stars 43 forks source link

list_map admin attr could take a callable -- feature request #33

Closed skyl closed 14 years ago

skyl commented 14 years ago

I did this in my branch; I don't like the solution but it works. I can make a branch and commit the change if you are interested. The reason this is important is you can use the http://geodjango.org/docs/geos.html#simplify-tolerance-0-0-preserve-topology-false so when you have 600 very complicated polygons you can render them without crippling the browser.

def get_changelist_map(self, cl):
    """
    Display a map in the admin changelist, with info popups
    """
    if self.list_map:
        info = []
        for obj in cl.get_query_set():
            # Transform the fields into one projection.
            try:
                geoms = [getattr(obj, field) for field in self.list_map]
                for geom in geoms:
                    geom.transform(int(DEFAULT_PROJ))
            except AttributeError:
                geoms = [getattr(obj, field)() for field in self.list_map]
                for geom in geoms:
                    geom.transform(int(DEFAULT_PROJ))
yourcelf commented 14 years ago

Hmmm, I see your point, this could be useful. Of course, you could just subclass GeoModelAdmin with this implementation... but I can see it being useful, in general, to support fields and callables.

I agree that the solution seems a little inelegant. I'll think on it and see if I can come up with another way. Let me know if you think of one.

yourcelf commented 14 years ago

Hey,

I've implemented this in the latest master in the following way:

def get_changelist_map(self, cl):
    """ 
    Display a map in the admin changelist, with info popups
    """
    if self.list_map:
        info = []
        for obj in cl.get_query_set():
            # Transform the fields into one projection.
            geoms = []
            for field in self.list_map:
                geom = getattr(obj, field)
                if callable(geom):
                    geom = geom()
                geoms.append(geom)
            for geom in geoms:
                geom.transform(int(DEFAULT_PROJ))

Let me know if you encounter any trouble with this implementation.