'Widget builder
@param field: the Field
@param value: the current value
@param attributes: the HTML attributes for the widget'

def __call__(self, field, value, **attributes):

    _class = self._class
    defaults = {'_type': 'text', '_class': _class, 'value': value, 'requires': field.requires}
    attr = self._attributes(field, defaults, **attributes)
    input_id = attr.get('_id')
    if (not input_id):
        if isinstance(field, Field):
            input_id = str(field).replace('.', '_')
        else:
            input_id = field.name.replace('.', '_')
        attr['_id'] = input_id
    input_name = attr.get('_name')
    if (not input_name):
        input_name = field.name.replace('.', '_')
        attr['_name'] = input_name
    container_id = ('%s-calendar-widget' % input_id)
    settings = current.deployment_settings
    calendar = (self.calendar or current.calendar.name)
    calendar = (calendar if (calendar and (calendar != 'Gregorian')) else 'gregorian')
    date_format = (self.date_format or settings.get_L10n_date_format())
    time_format = (self.time_format or settings.get_L10n_time_format())
    separator = (self.separator or settings.get_L10n_datetime_separator())
    c = (current.calendar if (not self.calendar) else S3Calendar(self.calendar))
    firstDOW = c.first_dow
    dtformat = separator.join([date_format, time_format])
    extremes = self.extremes(dtformat=dtformat)
    T = current.T
    clear_text = self.clear_text
    if (clear_text is None):
        clear_text = s3_str(T('Clear'))
    else:
        clear_text = s3_str(T(clear_text))
    options = {'calendar': calendar, 'dateFormat': str(date_format), 'timeFormat': str(time_format), 'separator': separator, 'firstDOW': firstDOW, 'monthSelector': self.month_selector, 'yearSelector': self.year_selector, 'showButtons': self.buttons, 'weekNumber': self.week_number, 'timepicker': self.timepicker, 'minuteStep': self.minute_step, 'todayText': s3_str(T('Today')), 'nowText': s3_str(T('Now')), 'closeText': s3_str(T('Done')), 'clearText': clear_text, 'setMin': self.set_min, 'setMax': self.set_max}
    options.update(extremes)
    if settings.get_ui_calendar_clear_icon():
        options['clearButton'] = 'icon'
    self.inject_script(input_id, options)
    real_input = INPUT(**attr)
    return TAG[''](DIV(real_input, _id=container_id, _class='calendar-widget-container'))
