class PushinhoForm(forms.Form): channel_name = forms.CharField(max_length=40) main_icon = forms.ImageField(required=True) main_icon_color = forms.CharField(max_length=7, help_text=_("Hexa Decimal Color"), widget=ColorFieldWidget()) chat_icon = forms.ImageField(required=True) chat_icon_color = forms.CharField(max_length=7, help_text=_("Hexa Decimal Color"), widget=ColorFieldWidget()) chat_push_message_color = forms.CharField( max_length=7, help_text=_("Hexa Decimal Color"), widget=ColorFieldWidget()) chat_push_text_color = forms.CharField(max_length=7, help_text=_("Hexa Decimal Color"), widget=ColorFieldWidget()) chat_user_text_color = forms.CharField(max_length=7, help_text=_("Hexa Decimal Color"), widget=ColorFieldWidget()) auto_open = forms.BooleanField(required=False) welcome_button = forms.CharField(required=False) welcome_message = forms.CharField(required=False) def clean(self): if self.data.get( WELCOME_MESSAGE) and not self.data.get(WELCOME_BUTTON): raise forms.ValidationError( _("You cannot add a Welcome Message without a Keyword"))
def test_render_with_colors(self): widget = ColorFieldWidget(colors=['#ffffff', '#223344', '#557799']) self.assertIn('<input id="id_test" list="datalist_for_id_test" name="test" type="color" value="#123456" />', widget.render('test', '#123456')) self.assertIn('''<script type="text/javascript"> (function($){ $(document).ready(function(){ $('#id_test').each(function(i, elm){ // Make sure html5 color element is not replaced if (elm.type != 'color') $(elm).colorPicker({"colors": ["ffffff", "223344", "557799"]}); }); }); })('django' in window && django.jQuery ? django.jQuery: jQuery); </script> ''', widget.render('test', '#123456')) # NOQA
def test_render_no_id(self): widget = ColorFieldWidget() self.assertIn('<input id="id_test" name="test" type="color" value="#123456" />', widget.render('test', '#123456')) self.assertIn('''<script type="text/javascript"> (function($){ $(document).ready(function(){ $('#id_test').each(function(i, elm){ // Make sure html5 color element is not replaced if (elm.type != 'color') $(elm).colorPicker({}); }); }); })('django' in window && django.jQuery ? django.jQuery: jQuery); </script> ''', widget.render('test', '#123456'))
def test_render_with_colors(self): widget = ColorFieldWidget(colors=['#ffffff', '#223344', '#557799']) self.assertInHTML( '<input id="id_test" list="datalist_for_id_test" name="test" type="color" value="#123456" />', widget.render('test', '#123456')) self.assertIn('''<script type="text/javascript"> (function($){ $(document).ready(function(){ $('#id_test').each(function(i, elm){ // Make sure html5 color element is not replaced if (elm.type != 'color') $(elm).colorPicker({"colors": ["ffffff", "223344", "557799"]}); }); }); })('django' in window && django.jQuery ? django.jQuery: jQuery); </script> ''', widget.render('test', '#123456')) # NOQA
def test_render_no_id(self): widget = ColorFieldWidget() self.assertInHTML( '<input id="id_test" name="test" type="color" value="#123456" />', widget.render('test', '#123456')) self.assertIn( '''<script type="text/javascript"> (function($){ $(document).ready(function(){ $('#id_test').each(function(i, elm){ // Make sure html5 color element is not replaced if (elm.type != 'color') $(elm).colorPicker({}); }); }); })('django' in window && django.jQuery ? django.jQuery: jQuery); </script> ''', widget.render('test', '#123456'))
class TagForm(forms.Form): name = forms.CharField( max_length=10, widget=forms.TextInput(attrs={'placeholder': 'Tag title'}), required=True) color = RGBColorField(widget=ColorFieldWidget(colors=[ '#61BD4F', '#F2D900', '#FFA111', '#EB5942', '#C470DF', '#0576BF', '#00C1E1', '#4FEB9A', '#FF72CA', '#355163', '#B3BEC4' ]))
class Meta: model = Habit fields = [ 'name', 'color', 'schedule', 'description', ] widgets = {'color': ColorFieldWidget()}
def __init__(self, *args, **kwargs): super(ThemedColorForm, self).__init__(*args, **kwargs) if self._color_fields: blog_settings = BlogSettings.load() if blog_settings and blog_settings.color_theme: theme_colors = blog_settings.color_theme.colors for color_field in self._color_fields: self.fields[color_field].widget = \ ColorFieldWidget(colors=theme_colors)