-
Notifications
You must be signed in to change notification settings - Fork 283
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
Question: overriding attrs (settings_overrides) #120
Comments
Hi,
But, in your example, to fix original center and zoom level you just set settings file. You can also write your own widget, with its own javascript, which takes your parameters to do leaflet actions (set custom center, custom zoom, custom rendering) |
+1 You could try: class ClientLocationWidget(LeafletWidget):
def __init__(self, attrs=None):
if attrs is None:
attrs = {}
attrs.update({
'settings_overrides':
{
'DEFAULT_CENTER': (55.92934, 23.311752),
'DEFAULT_ZOOM': 12
}
})
super(ClientLocationWidget, self).__init__(attrs=attrs) /cc @PetrDlouhy :) |
@leplatrem Thanks, but settings_overrides still has no effect. @submarcos In documentation, there is example where you can change from leaflet.forms.widgets import LeafletWidget
class WeatherStationForm(forms.ModelForm):
class Meta:
model = WeatherStation
fields = ('name', 'geom')
widgets = {'geom': LeafletWidget(attrs={
'settings_overrides': {
'DEFAULT_CENTER': (6.0, 45.0),
}
})} I just thought maybe I could override I know I can set global settings in settings.py, but Idea was to have different widgets for different purposes with different default settings, ignoring default ones. |
I tried example with custom Form class I mentioned in last post, it simply does not work. I think it's simply a bug. After searching for "settings_overrides" in repository, it's note quite appearent how it could be actually passed as tag argument from widget class, unless you pass it manually to tag inside template. But I can be wrong of course. Could someone please try that |
@Talkless I am sorry that you encounter those problems. Unfortunately I just can't spend time on it. I cannot say if this feature works the way it is described. Maybe @PetrDlouhy could help us finding out :) Please don't hesitate to hack around, open a pull-request with some fixs, it is always going to be easier to discuss with some code :) You could even write a small test to reproduce what you are trying to achieve, that would be the most efficient :) |
My working usage is this: class UserLeafletWidget(LeafletWidget):
def __init__(self, *args, **kwargs):
user_attendance = kwargs['user_attendance']
settings_overrides = {}
if user_attendance.team and user_attendance.team.subsidiary.city.location:
settings_overrides['DEFAULT_CENTER'] = (user_attendance.team.subsidiary.city.location.y, user_attendance.team.subsidiary.city.location.x)
settings_overrides['DEFAULT_ZOOM'] = 13
super(UserLeafletWidget, self).__init__(
attrs={
"geom_type":'LINESTRING',
"map_height":"500px",
"map_width":"100%",
'settings_overrides':settings_overrides,
}
) The working unit test in code is this: class SettingsOverridesTest(SimpleTestCase):
def test_settings_overrides(self):
widget = LeafletWidget(attrs={
'settings_overrides': {
'DEFAULT_CENTER': (8.0, 3.14),
}
})
output = widget.render('geom', '', {'id': 'geom'})
self.assertIn('"center": [8.0, 3.14]', output) @Talkless: Are you sure, that the |
@PetrDlouhy I'm pretty sure in Python 3 you can skip arguments, check first example: https://docs.python.org/3/library/functions.html#super Thanks for the input, I'll try again later. |
@Talkless OK, I don't work in Python 3, so I was confused. Maybe it would be helpful to set up TOX testing for Django-leaflet |
I overlooked, that the tests are here and running. So it is tested in Python 3. Though it still doesn't prove, that the issue is not connected with Python 3. Try running your application on Python 2 (if possible). |
How could I run tests? quicktest.py asks for some kind app..? |
You can run it with |
It would be worth documenting this indeed. As @dyve said, without tests it's no fun :) |
@Talkless could you eventually sort this out ? Thanks for letting others know :) |
No. Sorry, I've been sick for a while, and just can't find time to produce simple test app :( . |
I've created minimal app for reproducing my issue: Please check |
The problem is, that if you set the widget with I have added the possibility to set |
I want to override LEAFLET_CONFIG for specific custom widget, which would be used in specific LeafletGeoAdmin.
Is it possible to do that without reimplementing ModelForm? Here how it's looks currently:
my
widgets.py
:my
admin.py
:But it has no effect.
The text was updated successfully, but these errors were encountered: