def get_dummy_dexterity_value(obj, widget, data):
    value = None
    field = widget.field
    catalog = getToolByName(obj, 'portal_catalog')
    if interfaces.IChoice.providedBy(field):
        if shasattr(field, 'vocabulary') and field.vocabulary:
            vocabulary = field.vocabulary
        elif shasattr(field, 'vocabularyName') and field.vocabularyName:
            factory = component.getUtility(
                interfaces.IVocabularyFactory,
                field.vocabularyName)
            vocabulary = factory(obj)
        else:
            return

        if interfaces.IContextSourceBinder.providedBy(vocabulary):
            criteria = vocabulary.selectable_filter.criteria
            results = catalog(**criteria)
            if not len(results):
                return
            value = results[random.randint(0, len(results)-1)].getObject()
        else:
            if interfaces.ITreeVocabulary.providedBy(vocabulary) or \
                    not len(vocabulary):
                # Can't yet deal with tree vocabs
                return
            index = random.randint(0, len(vocabulary)-1)
            value = vocabulary._terms[index].value

    elif interfaces.IBool.providedBy(field):
        value = random.randint(0, 1) and True or False

    elif interfaces.ITextLine.providedBy(field):
        if HAS_USERANDGROUPSELECTIONWIDGET and \
                IUserAndGroupSelectionWidget.providedBy(widget):
            mtool = getToolByName(obj, 'portal_membership')
            mids = mtool.listMemberIds()
            value = mids[random.randint(0, len(mids)-1 or 1)]
        else:
            length = getattr(field, 'max_length', None)
            value = unicode(get_text_line()[:length])

    elif interfaces.IText.providedBy(field):
        if IWysiwygWidget.providedBy(widget):
            value = unicode(get_rich_text(data))
        else:
            value = unicode(get_text_paragraph())

    elif interfaces.IDatetime.providedBy(field):
        days = random.random()*10 * (random.randint(-1, 1) or 1)
        value = datetime.datetime.now() + datetime.timedelta(days, 0)

    elif interfaces.IDate.providedBy(field):
        days = random.random()*10 * (random.randint(-1, 1) or 1)
        value = datetime.datetime.now() + datetime.timedelta(days, 0)

    return value
def get_dummy_dexterity_value(obj, widget, data):
    value = None
    field = widget.field
    if interfaces.IChoice.providedBy(field):
        value = get_value_for_choice(obj, field)

    elif interfaces.ISet.providedBy(field) and \
            interfaces.IChoice.providedBy(field.value_type):
        value = get_value_for_choice(obj, field.value_type)

    elif interfaces.IBool.providedBy(field):
        value = random.randint(0, 1) and True or False

    elif interfaces.ITextLine.providedBy(field):
        if HAS_USERANDGROUPSELECTIONWIDGET and \
                IUserAndGroupSelectionWidget.providedBy(widget):
            mtool = api.portal.get_tool('portal_membership')
            mids = mtool.listMemberIds()
            value = mids[random.randint(0, len(mids) - 1 or 1)]
        else:
            length = getattr(field, 'max_length', None)
            value = unicode(get_text_line()[:length])

    elif interfaces.IText.providedBy(field):
        if IWysiwygWidget.providedBy(widget):
            value = unicode(get_rich_text(data))
        else:
            value = unicode(get_text_paragraph())

    elif HAS_PLONE_APP_TEXTFIELD and IRichText.providedBy(field):
        value = unicode(get_rich_text(data))

    elif interfaces.IDatetime.providedBy(field):
        days = random.random() * 10 * (random.randint(-1, 1) or 1)
        value = datetime.datetime.now() + datetime.timedelta(days, 0)

    elif interfaces.IDate.providedBy(field):
        days = random.random() * 10 * (random.randint(-1, 1) or 1)
        value = datetime.datetime.now() + datetime.timedelta(days, 0)

    return value
def get_dummy_dexterity_value(obj, widget, data):
    value = None
    field = widget.field
    if interfaces.IChoice.providedBy(field):
        value = get_value_for_choice(obj, field)

    elif interfaces.ISet.providedBy(field) and \
            interfaces.IChoice.providedBy(field.value_type):
        value = get_value_for_choice(obj, field.value_type)

    elif interfaces.IBool.providedBy(field):
        value = random.randint(0, 1) and True or False

    elif interfaces.ITextLine.providedBy(field):
        if HAS_USERANDGROUPSELECTIONWIDGET and \
                IUserAndGroupSelectionWidget.providedBy(widget):
            mtool = api.portal.get_tool('portal_membership')
            mids = mtool.listMemberIds()
            value = mids[random.randint(0, len(mids)-1 or 1)]
        else:
            length = getattr(field, 'max_length', None)
            value = unicode(get_text_line()[:length])

    elif interfaces.IText.providedBy(field):
        if IWysiwygWidget.providedBy(widget):
            value = unicode(get_rich_text(data))
        else:
            value = unicode(get_text_paragraph())

    elif HAS_PLONE_APP_TEXTFIELD and IRichText.providedBy(field):
        value = unicode(get_rich_text(data))

    elif interfaces.IDatetime.providedBy(field):
        days = random.random()*10 * (random.randint(-1, 1) or 1)
        value = datetime.datetime.now() + datetime.timedelta(days, 0)

    elif interfaces.IDate.providedBy(field):
        days = random.random()*10 * (random.randint(-1, 1) or 1)
        value = datetime.datetime.now() + datetime.timedelta(days, 0)

    return value