56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
# combo - content management system
|
|
# Copyright (C) 2017 Entr'ouvert
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
# under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from django import forms
|
|
from django.utils.encoding import force_text
|
|
from django.utils.text import slugify
|
|
|
|
from .models import MapLayer
|
|
|
|
|
|
class IconRadioSelect(forms.RadioSelect):
|
|
option_template_name = 'maps/icon_radio_option.html'
|
|
|
|
|
|
class MapNewLayerForm(forms.ModelForm):
|
|
class Meta:
|
|
model = MapLayer
|
|
exclude = ('slug', 'cache_duration', 'include_user_identifier')
|
|
widgets = {'marker_colour': forms.TextInput(attrs={'type': 'color'}),
|
|
'icon_colour': forms.TextInput(attrs={'type': 'color'}),
|
|
}
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(MapNewLayerForm, self).__init__(*args, **kwargs)
|
|
self.fields['icon'].choices = list(
|
|
sorted(self.fields['icon'].choices, key=lambda x: slugify(force_text(x[1]))))
|
|
|
|
|
|
class MapLayerForm(forms.ModelForm):
|
|
class Meta:
|
|
model = MapLayer
|
|
fields = '__all__'
|
|
widgets = {'marker_colour': forms.TextInput(attrs={'type': 'color'}),
|
|
'icon_colour': forms.TextInput(attrs={'type': 'color'}),
|
|
'icon': IconRadioSelect(),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super(MapLayerForm, self).__init__(*args, **kwargs)
|
|
self.fields['icon'].choices = list(
|
|
sorted(self.fields['icon'].choices, key=lambda x: slugify(force_text(x[1]))))
|