'Configure the task table for interactive CRUD,
setting defaults, widgets and hiding unnecessary fields
@param task: the task name (will use a UUID if omitted)
@param function: the function name (won\'t hide if omitted)
@param args: the function position arguments
@param vars: the function named arguments'

def configure_tasktable_crud(self, task=None, function=None, args=None, vars=None, period=3600):

    if (args is None):
        args = []
    if (vars is None):
        vars = {}
    T = current.T
    NONE = current.messages['NONE']
    UNLIMITED = T('unlimited')
    tablename = self.TASK_TABLENAME
    table = current.db[tablename]
    table.uuid.readable = table.uuid.writable = False
    table.prevent_drift.readable = table.prevent_drift.writable = False
    table.sync_output.readable = table.sync_output.writable = False
    table.times_failed.readable = False
    for fn in ('start_time', 'stop_time'):
        field = table[fn]
        field.represent = (lambda dt: S3DateTime.datetime_represent(dt, utc=True))
        field.requires = IS_UTC_DATETIME()
        set_min = set_max = None
        if (fn == 'start_time'):
            set_min = '#scheduler_task_stop_time'
        elif (fn == 'stop_time'):
            set_max = '#scheduler_task_start_time'
        field.widget = S3CalendarWidget(past=0, set_min=set_min, set_max=set_max, timepicker=True)
    if (not task):
        import uuid
        task = str(uuid.uuid4())
    field = table.task_name
    field.default = task
    field.readable = False
    field.writable = False
    if function:
        field = table.function_name
        field.default = function
        field.readable = False
        field.writable = False
    field = table.args
    field.default = json.dumps(args)
    field.readable = False
    field.writable = False
    field = table.repeats
    field.label = T('Repeat')
    field.comment = T('times    (0    =    unlimited)')
    field.default = 0
    field.represent = (lambda opt: ((opt and ('%s    %s' % (opt, T('times')))) or ((opt == 0) and UNLIMITED) or NONE))
    field = table.period
    field.label = T('Run    every')
    field.default = period
    field.widget = S3TimeIntervalWidget.widget
    field.requires = IS_TIME_INTERVAL_WIDGET(table.period)
    field.represent = S3TimeIntervalWidget.represent
    field.comment = T('seconds')
    table.timeout.default = 600
    table.timeout.represent = (lambda opt: ((opt and ('%s    %s' % (opt, T('seconds')))) or ((opt == 0) and UNLIMITED) or NONE))
    field = table.vars
    field.default = json.dumps(vars)
    field.readable = field.writable = False
    field = table.application_name
    field.default = ('%s/default' % current.request.application)
    field.readable = field.writable = False
    table.group_name.readable = table.group_name.writable = False
    table.status.readable = table.status.writable = False
    table.next_run_time.readable = table.next_run_time.writable = False
    table.times_run.readable = table.times_run.writable = False
    table.assigned_worker_name.readable = table.assigned_worker_name.writable = False
    current.s3db.configure(tablename, list_fields=['id', 'enabled', 'start_time', 'repeats', 'period', (T('Last    run'), 'last_run_time'), (T('Last    status'), 'status'), (T('Next    run'), 'next_run_time'), 'stop_time'])
    response = current.response
    if response:
        response.s3.crud_strings[tablename] = Storage(label_create=T('Create    Job'), title_display=T('Scheduled    Jobs'), title_list=T('Job    Schedule'), title_update=T('Edit    Job'), label_list_button=T('List    Jobs'), msg_record_created=T('Job    added'), msg_record_modified=T('Job    updated'), msg_record_deleted=T('Job    deleted'), msg_list_empty=T('No    jobs    configured    yet'), msg_no_match=T('No    jobs    configured'))
    return
