Download mColorPicker archive from http://www.bertera.it/software/web2py/mColorPicker-w2p.tgz ad decompress in static/ folder of your application
Add the widget in db.py
import uuid
colorpicker_js = URL(r=request,c='static/mColorPicker', f='mColorPicker.min.js')
class ColorPickerWidget(object):
"""
Colorpicker widget based on http://code.google.com/p/mcolorpicker/
"""
def __init__ (self, js = colorpicker_js, button=True, style="", transparency=False):
uid = str(uuid.uuid4())[:8]
self._class = "_%s" % uid
self.style = style
if transparency == False:
self.transparency = 'false'
else:
self.transparency = 'true'
if button == True:
self.data = 'hidden'
if self.style == "":
self.style = "height:20px;width:20px;"
else:
self.data = 'display'
if not js in response.files:
response.files.append(js)
def widget(self, f, v):
wrapper = DIV()
inp = SQLFORM.widgets.string.widget(f,v, _value=v, _type='color',\
_data_text='hidden', _style=self.style, _hex='true', _class=self._class)
scr = SCRIPT("$.fn.mColorPicker.init.replace = false; \
$.fn.mColorPicker.init.allowTransparency=%s; \
$('input.%s').mColorPicker({'imageFolder': '/%s/static/mColorPicker/'});"\
% (self.transparency, self._class, request.application))
wrapper.components.append(inp)
wrapper.components.append(scr)
return wrapper
color_widget = ColorPickerWidget()
create a test table and set the widget to our new colorpicker widget
db.define_table('house', Field('color', widget = color_widget.widget))
create the form in your controller:
def index():
form = SQLFORM(db.house)
if form.accepts(request.vars, session):
response.flash = T('New house inserted')
return dict(form=form)
.playincard....
ross.peoples...
frank
abhishekgupt...